New commit

This commit is contained in:
Thomas Forgione 2019-01-09 11:43:34 +01:00
parent 62fdf8689c
commit 78889ae464
No known key found for this signature in database
GPG Key ID: 203DAEA747F48F41
1 changed files with 94 additions and 57 deletions

View File

@ -31,85 +31,122 @@ test_command() {
command -v $1 > /dev/null 2>&1 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() { yes_no_ask() {
echo_green_n $1 "[Y/n]" echo_green_n $1 "[Y/n]"
read -n 1 answer read -n 1 answer
echo_green echo_green '\b '
if ! [[ "$answer" == "Y" ]] && ! [[ "$answer" == "y" ]] && ! [[ "$anwser" == "" ]] if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then
then return 0
echo_green "Can't continue..." else
exit 1 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 fi
} }
configure_zsh() { configure_zsh() {
test_command git yes_no_ask "Do you wish to install and configure zsh ?"
if [ $? -ne 0 ] if [ $? -ne 0 ]; then
then echo_green "Stopping"
yes_no_ask "You'll need git for this, do you wish to install git ?" return
sudo apt install git
fi fi
test_command zsh test_command -v git
if [ $? -ne 0 ] if [ $? -ne 0 ]; then
then yes_no_ask_required "You'll need git for this, do you wish to install git ?"
yes_no_ask "This magnificent prompt is based on zsh, do you wish to install zsh ?" install git
sudo apt install zsh
fi fi
mkdir -p $HOME/.config test_command -v zsh
if [ ! -d $HOME/.config/oh-my-zsh ] if [ $? -ne 0 ]; then
then yes_no_ask_required echo_green "This magnificent prompt is based on zsh, do you wish to install zsh ?"
echo_green "Cloning oh-my-zsh" install zsh
git clone https://github.com/robbyrussell/oh-my-zsh/ $HOME/.config/oh-my-zsh
fi fi
if [ ! -d $HOME/.config/dotfiles ] mkdir -p $home/.config
then if [ ! -d $home/.config/oh-my-zsh ]; then
echo_green "Cloning tforgione's dotfiles..." git_clone https://github.com/robbyrussell/oh-my-zsh/ $home/.config/oh-my-zsh
git clone https://github.com/tforgione/dotfiles/ $HOME/.config/dotfiles
fi fi
should_make_link=0 if [ ! -d $home/.config/dotfiles ]; then
if [ -f "$HOME/.zshrc" ] git_clone https://gitea.tforgione.fr/tforgione/dotfiles/ $home/.config/dotfiles
then fi
path1=`realpath $HOME/.zshrc`
path2=`realpath $HOME/.config/dotfiles/zshrc` if [ ! -d $home/.scripts ]; then
if [ "$path1" == "$path2" ] yes_no_ask "You don't have tforgione's scripts, do you want them ?"
then if [ $? -eq 0 ]; then
should_make_link=1 git_clone https://gitea.tforgione.fr/tforgione/scripts $home/.scripts
fi fi
fi fi
if [ $should_make_link -eq 0 ] if [ -f $home/.zshrc ]; then
then path1=`realpath $home/.zshrc`
if [ -f `realpath $HOME/.zshrc` ] path2=`realpath $home/.config/dotfiles/zshrc`
then if [ "$path1" == "$path2" ]; then
echo_green "Warning: you already have a zshrc, it will be moved to ~/.zshrc.bak" echo_green "It seems that your zshrc is already a good link."
mv $HOME/.zshrc $HOME/.zshrc.bak
fi
echo_green "Linking zshrc"
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
fi
chsh_executed=0
if [ ! "$user_shell" == "/bin/zsh" ]
then
echo_green "Changing user's default shell..."
chsh $user -s /bin/zsh
chsh_executed=1
fi
if [ $chsh_executed -eq 1 ]
then
echo_green "chsh was executed, you might need to log-out and log-in to finalize the changes."
echo_green "Everything else has been configured. Have a good day!"
else else
echo_green "Everything has been configured. Have a good day!" 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 fi
} }
configure_zsh < /dev/tty main() {
echo_green "=== WELCOME TO TFORGIONE'S CONFIG INSTALLER ==="
configure_zsh
}
main < /dev/tty