sh.tforgione.fr/tforgione.sh

145 lines
3.2 KiB
Bash
Raw Normal View History

2019-01-09 10:25:29 +00:00
#!/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
}
2019-01-09 10:43:34 +00:00
yes_no_ask_required() {
yes_no_ask $@
if [ $? -ne 0 ]; then
echo_green "Can't continue"
exit 1
fi
}
2019-01-09 10:25:29 +00:00
yes_no_ask() {
echo_green_n $1 "[Y/n]"
read -n 1 answer
2019-01-09 10:43:34 +00:00
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!"
2019-01-09 10:25:29 +00:00
fi
}
configure_zsh() {
2019-01-09 10:43:34 +00:00
yes_no_ask "Do you wish to install and configure zsh ?"
if [ $? -ne 0 ]; then
echo_green "Stopping"
return
2019-01-09 10:25:29 +00:00
fi
2019-01-09 10:43:34 +00:00
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
2019-01-09 10:25:29 +00:00
fi
2019-01-09 10:43:34 +00:00
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
2019-01-09 10:25:29 +00:00
fi
2019-01-09 10:47:01 +00:00
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
2019-01-09 10:25:29 +00:00
fi
2019-01-09 10:47:01 +00:00
if [ ! -d $HOME/.config/dotfiles ]; then
git_clone https://gitea.tforgione.fr/tforgione/dotfiles/ $HOME/.config/dotfiles
2019-01-09 10:25:29 +00:00
fi
2019-01-09 10:47:01 +00:00
if [ -f $HOME/.zshrc ]; then
path1=`realpath $HOME/.zshrc`
path2=`realpath $HOME/.config/dotfiles/zshrc`
2019-01-09 10:43:34 +00:00
if [ "$path1" == "$path2" ]; then
echo_green "It seems that your zshrc is already a good link."
else
2019-01-09 10:47:01 +00:00
if `realpath $HOME/.zshrc`; then
2019-01-09 10:43:34 +00:00
echo_green Warning: you already have a zshrc, it will be moved to ~/.zshrc.bak
2019-01-09 10:47:01 +00:00
mv $HOME/.zshrc $HOME/.zshrc.bak
2019-01-09 10:43:34 +00:00
fi
echo_green Linking zshrc
2019-01-09 10:47:01 +00:00
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
2019-01-09 10:43:34 +00:00
fi
else
echo_green Linking zshrc
2019-01-09 10:47:01 +00:00
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
2019-01-09 10:25:29 +00:00
fi
2019-01-09 10:43:34 +00:00
if [ "$user_shell" == "/bin/zsh" ]; then
echo_green "It seems that you already use zsh."
2019-01-09 10:25:29 +00:00
else
2019-01-09 10:43:34 +00:00
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
2019-01-09 10:25:29 +00:00
fi
}
2019-01-09 10:43:34 +00:00
main() {
echo_green "=== WELCOME TO TFORGIONE'S CONFIG INSTALLER ==="
configure_zsh
}
main < /dev/tty
2019-01-09 10:25:29 +00:00