2019-04-15 16:19:59 +01:00
|
|
|
#!/usr/bin/env sh
|
2019-01-09 10:25:29 +00:00
|
|
|
|
|
|
|
# This script installs the default things for having a stylish zsh
|
|
|
|
user_shell=`getent passwd $USER | cut -f7 -d:`
|
|
|
|
|
2019-04-15 16:19:59 +01:00
|
|
|
info() {
|
|
|
|
echo -e '\033[1m'info:'\033[0m' $@
|
2019-01-09 10:25:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 16:19:59 +01:00
|
|
|
info_n() {
|
|
|
|
echo -en '\033[1m'info:'\033[0m' $@
|
2019-01-09 10:25:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 16:19:59 +01:00
|
|
|
warn() {
|
|
|
|
echo -e '\033[33;1m'warning:'\033[0m' $@
|
2019-01-09 10:25:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 16:19:59 +01:00
|
|
|
warn_n() {
|
|
|
|
echo -en '\033[33;1m'warning:'\033[0m' $@
|
2019-01-09 10:25:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 16:19:59 +01:00
|
|
|
error() {
|
|
|
|
echo -e '\033[31;1m'error:'\033[0m' $@
|
2019-01-09 10:25:29 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 16:19:59 +01:00
|
|
|
error_n() {
|
|
|
|
echo -en '\033[31;1m'error:'\033[0m' $@
|
|
|
|
}
|
|
|
|
|
|
|
|
echo_green() {
|
|
|
|
echo -e '\033[32;1m'$@'\033[0m'
|
2019-01-09 10:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_command() {
|
|
|
|
command -v $1 > /dev/null 2>&1
|
|
|
|
}
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
yes_no_ask_required() {
|
2019-04-15 16:19:59 +01:00
|
|
|
yes_no_ask $@ "(required)"
|
2019-01-09 10:43:34 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2019-04-15 19:24:41 +01:00
|
|
|
error "refused to perform required task, can't continue"
|
2019-01-09 10:43:34 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-09 10:25:29 +00:00
|
|
|
yes_no_ask() {
|
2019-04-15 16:19:59 +01:00
|
|
|
info_n $@ "[Y/n]"
|
|
|
|
read answer
|
2019-01-09 10:43:34 +00:00
|
|
|
if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
install() {
|
|
|
|
test_command apt
|
|
|
|
if [ $? -eq 0 ]; then
|
2019-04-15 19:24:41 +01:00
|
|
|
sudo apt install -y $1
|
2019-01-09 10:43:34 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
test_command pacman
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
sudo pacman -S $1
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-04-15 16:19:59 +01:00
|
|
|
error "distribution not recognized, can't install $1."
|
2019-01-09 10:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
git_clone() {
|
2019-04-15 19:25:55 +01:00
|
|
|
info_n "cloning $1..."
|
2019-01-09 10:43:34 +00:00
|
|
|
git clone $1 $2 > /dev/null 2>&1
|
|
|
|
if [ $? -eq 0 ]; then
|
2019-04-15 16:19:59 +01:00
|
|
|
echo " OK!"
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
error "clone failed!"
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
configure_zsh() {
|
|
|
|
|
2019-04-15 16:19:59 +01:00
|
|
|
yes_no_ask "do you wish to install and configure zsh ?"
|
2019-01-09 10:43:34 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2019-04-15 16:19:59 +01:00
|
|
|
info "exiting"
|
2019-01-09 10:43:34 +00:00
|
|
|
return
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-15 16:43:28 +01:00
|
|
|
test_command git
|
2019-01-09 10:43:34 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2019-04-15 16:19:59 +01:00
|
|
|
yes_no_ask_required "you'll need git for this, do you wish to install git ?"
|
2019-01-09 10:43:34 +00:00
|
|
|
install git
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-15 16:43:28 +01:00
|
|
|
test_command zsh
|
2019-01-09 10:43:34 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2019-04-15 16:19:59 +01:00
|
|
|
yes_no_ask_required "this magnificent prompt is based on zsh, do you wish to install zsh ?"
|
2019-01-09 10:43:34 +00:00
|
|
|
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
|
2019-04-15 16:19:59 +01:00
|
|
|
info "it seems that your zshrc is already a good link."
|
2019-01-09 10:43:34 +00:00
|
|
|
else
|
2019-01-09 10:47:01 +00:00
|
|
|
if `realpath $HOME/.zshrc`; then
|
2019-04-15 16:19:59 +01:00
|
|
|
warn "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
|
2019-04-15 16:19:59 +01:00
|
|
|
info "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
|
2019-04-15 16:19:59 +01:00
|
|
|
info "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
|
2019-04-15 16:19:59 +01:00
|
|
|
info "it seems that you already use zsh."
|
2019-01-09 10:25:29 +00:00
|
|
|
else
|
2019-04-15 16:19:59 +01:00
|
|
|
info "it seems your shell is not zsh..."
|
|
|
|
yes_no_ask "do you want to change your shell ? (you'll need root) ?"
|
2019-04-15 17:04:47 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
2019-04-15 16:19:59 +01:00
|
|
|
info "changing your shell"
|
2019-01-09 10:43:34 +00:00
|
|
|
sudo chsh $user -s /bin/zsh
|
|
|
|
else
|
2019-04-15 16:19:59 +01:00
|
|
|
info "not doing anything"
|
2019-01-09 10:43:34 +00:00
|
|
|
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
|
|
|
|