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
}
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
if ! [[ "$answer" == "Y" ]] && ! [[ "$answer" == "y" ]] && ! [[ "$anwser" == "" ]]
then
echo_green "Can't continue..."
exit 1
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() {
test_command git
if [ $? -ne 0 ]
then
yes_no_ask "You'll need git for this, do you wish to install git ?"
sudo apt install git
yes_no_ask "Do you wish to install and configure zsh ?"
if [ $? -ne 0 ]; then
echo_green "Stopping"
return
fi
test_command zsh
if [ $? -ne 0 ]
then
yes_no_ask "This magnificent prompt is based on zsh, do you wish to install zsh ?"
sudo apt install zsh
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
mkdir -p $HOME/.config
if [ ! -d $HOME/.config/oh-my-zsh ]
then
echo_green "Cloning oh-my-zsh"
git clone https://github.com/robbyrussell/oh-my-zsh/ $HOME/.config/oh-my-zsh
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
if [ ! -d $HOME/.config/dotfiles ]
then
echo_green "Cloning tforgione's dotfiles..."
git clone https://github.com/tforgione/dotfiles/ $HOME/.config/dotfiles
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
should_make_link=0
if [ -f "$HOME/.zshrc" ]
then
path1=`realpath $HOME/.zshrc`
path2=`realpath $HOME/.config/dotfiles/zshrc`
if [ "$path1" == "$path2" ]
then
should_make_link=1
if [ ! -d $home/.config/dotfiles ]; then
git_clone https://gitea.tforgione.fr/tforgione/dotfiles/ $home/.config/dotfiles
fi
if [ ! -d $home/.scripts ]; then
yes_no_ask "You don't have tforgione's scripts, do you want them ?"
if [ $? -eq 0 ]; then
git_clone https://gitea.tforgione.fr/tforgione/scripts $home/.scripts
fi
fi
if [ $should_make_link -eq 0 ]
then
if [ -f `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
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
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
echo_green "Everything has been configured. Have a good day!"
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
}
configure_zsh < /dev/tty
main() {
echo_green "=== WELCOME TO TFORGIONE'S CONFIG INSTALLER ==="
configure_zsh
}
main < /dev/tty