sh.tforgione.fr/tforgione.sh

151 lines
3.2 KiB
Bash
Executable File

#!/usr/bin/env sh
# This script installs the default things for having a stylish zsh
user_shell=`getent passwd $USER | cut -f7 -d:`
info() {
echo -e '\033[1m'info:'\033[0m' $@
}
info_n() {
echo -en '\033[1m'info:'\033[0m' $@
}
warn() {
echo -e '\033[33;1m'warning:'\033[0m' $@
}
warn_n() {
echo -en '\033[33;1m'warning:'\033[0m' $@
}
error() {
echo -e '\033[31;1m'error:'\033[0m' $@
}
error_n() {
echo -en '\033[31;1m'error:'\033[0m' $@
}
echo_green() {
echo -e '\033[32;1m'$@'\033[0m'
}
test_command() {
command -v $1 > /dev/null 2>&1
}
yes_no_ask_required() {
yes_no_ask $@ "(required)"
if [ $? -ne 0 ]; then
error "can't continue"
exit 1
fi
}
yes_no_ask() {
info_n $@ "[Y/n]"
read answer
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
error "distribution not recognized, can't install $1."
}
git_clone() {
info_n "Cloning $1..."
git clone $1 $2 > /dev/null 2>&1
if [ $? -eq 0 ]; then
echo " OK!"
else
echo
error "clone failed!"
fi
}
configure_zsh() {
yes_no_ask "do you wish to install and configure zsh ?"
if [ $? -ne 0 ]; then
info "exiting"
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 "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
info "it seems that your zshrc is already a good link."
else
if `realpath $HOME/.zshrc`; then
warn "you already have a zshrc, it will be moved to ~/.zshrc.bak"
mv $HOME/.zshrc $HOME/.zshrc.bak
fi
info "linking zshrc"
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
fi
else
info "linking zshrc"
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
fi
if [ "$user_shell" == "/bin/zsh" ]; then
info "it seems that you already use zsh."
else
info "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
info "changing your shell"
sudo chsh $user -s /bin/zsh
else
info "not doing anything"
fi
fi
}
main() {
echo_green "=== WELCOME TO TFORGIONE'S CONFIG INSTALLER ==="
configure_zsh
}
main < /dev/tty