sh.tforgione.fr/tforgione.sh

145 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# This script installs the default things for having a stylish zsh
user_shell=`getent passwd $USER | cut -f7 -d:`
echo_green() {
echo -e '\033[32;1m'$@'\033[0m'
}
echo_green_n() {
echo -en '\033[32;1m'$@'\033[0m'
}
echo_yellow() {
echo -e '\033[33;1m'$@'\033[0m'
}
echo_yellow_n() {
echo -en '\033[33;1m'$@'\033[0m'
}
echo_red() {
echo -e '\033[31;1m'$@'\033[0m'
}
echo_red_n() {
echo -en '\033[31;1m'$@'\033[0m'
}
test_command() {
command -v $1 > /dev/null 2>&1
}
yes_no_ask_required() {
yes_no_ask $@
if [ $? -ne 0 ]; then
echo_green "Can't continue"
exit 1
fi
}
yes_no_ask() {
echo_green_n $1 "[Y/n]"
read -n 1 answer
echo_green '\b '
if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then
return 0
else
return 1
fi
}
install() {
test_command apt
if [ $? -eq 0 ]; then
sudo apt install $1
return
fi
test_command pacman
if [ $? -eq 0 ]; then
sudo pacman -S $1
return
fi
echo "Distribution not recognized, can't install $1."
}
git_clone() {
echo_green_n "Cloning $1..."
git clone $1 $2 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo_green " OK!"
fi
}
configure_zsh() {
yes_no_ask "Do you wish to install and configure zsh ?"
if [ $? -ne 0 ]; then
echo_green "Stopping"
return
fi
test_command -v git
if [ $? -ne 0 ]; then
yes_no_ask_required "You'll need git for this, do you wish to install git ?"
install git
fi
test_command -v zsh
if [ $? -ne 0 ]; then
yes_no_ask_required echo_green "This magnificent prompt is based on zsh, do you wish to install zsh ?"
install zsh
fi
mkdir -p $HOME/.config
if [ ! -d $HOME/.config/oh-my-zsh ]; then
git_clone https://github.com/robbyrussell/oh-my-zsh/ $HOME/.config/oh-my-zsh
fi
if [ ! -d $HOME/.config/dotfiles ]; then
git_clone https://gitea.tforgione.fr/tforgione/dotfiles/ $HOME/.config/dotfiles
fi
if [ -f $HOME/.zshrc ]; then
path1=`realpath $HOME/.zshrc`
path2=`realpath $HOME/.config/dotfiles/zshrc`
if [ "$path1" == "$path2" ]; then
echo_green "It seems that your zshrc is already a good link."
else
if `realpath $HOME/.zshrc`; then
echo_green Warning: you already have a zshrc, it will be moved to ~/.zshrc.bak
mv $HOME/.zshrc $HOME/.zshrc.bak
fi
echo_green Linking zshrc
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
fi
else
echo_green Linking zshrc
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
fi
if [ "$user_shell" == "/bin/zsh" ]; then
echo_green "It seems that you already use zsh."
else
echo_green "It seems your shell is not zsh..."
yes_no_ask "Do you want to change your shell ? (you'll need root) ?"
if [ $? -ne 0 ]; then
echo_green "Changing your shell"
sudo chsh $user -s /bin/zsh
else
echo_green "Not doing anything"
fi
fi
}
main() {
echo_green "=== WELCOME TO TFORGIONE'S CONFIG INSTALLER ==="
configure_zsh
}
main < /dev/tty