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
|
|
|
}
|
|
|
|
|
2019-04-26 14:52:31 +01:00
|
|
|
install_python3() {
|
|
|
|
test_command apt
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
sudo apt install python3 python3-pip
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
test_command pacman
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
sudo pacman -S python python-pip
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
error "distribution not recognized, can't install python3."
|
|
|
|
}
|
|
|
|
|
|
|
|
install_python_neovim() {
|
|
|
|
test_command pip3
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
sudo pip3 install neovim
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
test_command pip
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
sudo pip install neovim
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
error "couldn't find pip, can't install python-neovim."
|
|
|
|
}
|
|
|
|
|
2019-04-26 14:10:30 +01:00
|
|
|
install_neovim() {
|
|
|
|
test_command apt
|
|
|
|
if [ $? -eq 0 ]; then
|
2019-04-26 14:26:20 +01:00
|
|
|
test_command add-apt-repository
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
sudo apt update && sudo apt install -y software-properties-common
|
|
|
|
fi
|
|
|
|
|
2019-04-26 14:15:32 +01:00
|
|
|
sudo add-apt-repository -y ppa:neovim-ppa/stable
|
|
|
|
sudo apt update -y
|
|
|
|
sudo apt install -y neovim
|
2019-04-26 14:10:30 +01:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
test_command pacman
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
sudo pacman -S neovim
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
error "distribution not recognized, can't install neovim."
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-04-26 14:32:43 +01:00
|
|
|
clone_dotfiles() {
|
|
|
|
if [ ! -d $HOME/.config/dotfiles ]; then
|
|
|
|
|
|
|
|
test_command git
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
if [ $sudo_available -ne 0 ]; then
|
|
|
|
error "git is needed, but you don't have git neither sudo"
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
yes_no_ask_required "you'll need git for this, do you wish to install git ?"
|
|
|
|
install git
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
git_clone https://gitea.tforgione.fr/tforgione/dotfiles/ $HOME/.config/dotfiles
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-01-09 10:25:29 +00:00
|
|
|
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-26 14:07:03 +01:00
|
|
|
info "not installing zsh"
|
2019-01-09 10:43:34 +00:00
|
|
|
return
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
|
2019-04-26 14:32:43 +01:00
|
|
|
clone_dotfiles
|
2019-01-09 10:25:29 +00:00
|
|
|
|
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-16 12:46:58 +01:00
|
|
|
if [ $sudo_available -ne 0 ]; then
|
|
|
|
error "zsh is needed, but you don't have zsh neither sudo"
|
|
|
|
return 1
|
|
|
|
else
|
|
|
|
yes_no_ask_required "this magnificent prompt is based on zsh, do you wish to install zsh ?"
|
|
|
|
install zsh
|
|
|
|
fi
|
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 [ -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..."
|
2019-04-16 12:46:58 +01:00
|
|
|
|
|
|
|
if [ $sudo_available -eq 0 ]; then
|
|
|
|
# Sudo is available, run chsh
|
2019-04-18 08:53:22 +01:00
|
|
|
yes_no_ask "do you want to change your shell ?"
|
2019-04-16 12:46:58 +01:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
info "changing your shell"
|
|
|
|
sudo chsh $user -s /bin/zsh
|
|
|
|
else
|
|
|
|
info "not doing anything"
|
|
|
|
fi
|
2019-01-09 10:43:34 +00:00
|
|
|
else
|
2019-04-16 12:46:58 +01:00
|
|
|
info "you don't have root, but you can run 'exec zsh' at the end of your bashrc"
|
|
|
|
yes_no_ask "do you wish to do that ?"
|
|
|
|
if [ $? -eq 0 ]; then
|
2019-04-16 13:06:49 +01:00
|
|
|
echo >> $HOME/.bashrc
|
|
|
|
echo "exec zsh" >> $HOME/.bashrc
|
|
|
|
echo >> $HOME/.bashrc
|
2019-04-16 12:46:58 +01:00
|
|
|
else
|
|
|
|
info "not doing anything"
|
|
|
|
fi
|
2019-01-09 10:43:34 +00:00
|
|
|
fi
|
2019-01-09 10:25:29 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-04-26 14:07:03 +01:00
|
|
|
configure_neovim() {
|
|
|
|
test_command nvim
|
|
|
|
if [ $? -ne 0 ] && [ $sudo_available -ne 0 ]; then
|
|
|
|
warn "you don't have neither sudo nor neovim, skipping neovim configuration"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
yes_no_ask "do you wish to install and configure neovim ?"
|
|
|
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
info "not installing neovim"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2019-04-26 14:32:43 +01:00
|
|
|
clone_dotfiles
|
|
|
|
|
2019-04-26 14:07:03 +01:00
|
|
|
test_command nvim
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
info "installing neovim"
|
2019-04-26 14:28:02 +01:00
|
|
|
install_neovim
|
2019-04-26 14:07:03 +01:00
|
|
|
fi
|
|
|
|
|
2019-04-26 14:52:31 +01:00
|
|
|
# Try and install python3 and python-neovim
|
|
|
|
test_command python3
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
install_python3
|
|
|
|
fi
|
|
|
|
|
|
|
|
install_python_neovim
|
|
|
|
|
2019-04-26 14:38:56 +01:00
|
|
|
# Create config files an directories
|
2019-04-26 14:07:03 +01:00
|
|
|
mkdir -p $HOME/.config/nvim $HOME/.nvim/backups $HOME/.nvim/swp $HOME/.nvim/undo
|
2019-04-26 14:16:29 +01:00
|
|
|
rm -f $HOME/.config/nvim/init.vim
|
2019-04-26 14:07:03 +01:00
|
|
|
ln -s $HOME/.config/dotfiles/init.vim $HOME/.config/nvim/init.vim
|
|
|
|
|
2019-04-26 14:38:56 +01:00
|
|
|
# Install vim plug
|
2019-04-26 14:52:31 +01:00
|
|
|
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
|
2019-04-26 14:38:56 +01:00
|
|
|
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
|
|
|
|
|
|
|
|
# Install plugins
|
|
|
|
nvim +PlugInstall +qa
|
2019-04-26 14:07:03 +01:00
|
|
|
}
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
main() {
|
|
|
|
echo_green "=== WELCOME TO TFORGIONE'S CONFIG INSTALLER ==="
|
2019-04-18 08:53:22 +01:00
|
|
|
|
|
|
|
info "before anything, i need to know if your user can use sudo"
|
|
|
|
yes_no_ask "can your user use sudo ?"
|
|
|
|
sudo_available=$?
|
|
|
|
|
2019-01-09 10:43:34 +00:00
|
|
|
configure_zsh
|
2019-04-26 14:07:03 +01:00
|
|
|
configure_neovim
|
2019-01-09 10:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main < /dev/tty
|
2019-01-09 10:25:29 +00:00
|
|
|
|