sh.tforgione.fr/tforgione.sh

443 lines
11 KiB
Bash
Raw Permalink Normal View History

2019-04-15 17:19:59 +02:00
#!/usr/bin/env sh
2019-01-09 11:25:29 +01:00
# This script installs the default things for having a stylish zsh
2020-01-07 11:41:12 +01:00
user=$USER
2019-01-09 11:25:29 +01:00
user_shell=`getent passwd $USER | cut -f7 -d:`
2019-04-15 17:19:59 +02:00
info() {
echo -e '\033[1m'info:'\033[0m' $@
2019-01-09 11:25:29 +01:00
}
2019-04-15 17:19:59 +02:00
info_n() {
echo -en '\033[1m'info:'\033[0m' $@
2019-01-09 11:25:29 +01:00
}
2019-04-15 17:19:59 +02:00
warn() {
echo -e '\033[33;1m'warning:'\033[0m' $@
2019-01-09 11:25:29 +01:00
}
2019-04-15 17:19:59 +02:00
warn_n() {
echo -en '\033[33;1m'warning:'\033[0m' $@
2019-01-09 11:25:29 +01:00
}
2019-04-15 17:19:59 +02:00
error() {
echo -e '\033[31;1m'error:'\033[0m' $@
2019-01-09 11:25:29 +01:00
}
2019-04-15 17:19:59 +02:00
error_n() {
echo -en '\033[31;1m'error:'\033[0m' $@
}
echo_green() {
echo -e '\033[32;1m'$@'\033[0m'
2019-01-09 11:25:29 +01:00
}
test_command() {
2020-11-14 19:05:33 +01:00
for i in $@; do
command -v $i > /dev/null 2>&1
res=$?
if [ $res -ne 0 ]; then
return $res
fi
done
2019-01-09 11:25:29 +01:00
}
2019-01-09 11:43:34 +01:00
yes_no_ask_required() {
2019-04-15 17:19:59 +02:00
yes_no_ask $@ "(required)"
2019-01-09 11:43:34 +01:00
if [ $? -ne 0 ]; then
2019-04-15 20:24:41 +02:00
error "refused to perform required task, can't continue"
2019-01-09 11:43:34 +01:00
exit 1
fi
}
2019-01-09 11:25:29 +01:00
yes_no_ask() {
2019-04-15 17:19:59 +02:00
info_n $@ "[Y/n]"
read answer
2019-01-09 11:43:34 +01:00
if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then
return 0
else
return 1
fi
}
install() {
test_command apt
if [ $? -eq 0 ]; then
2020-11-14 19:05:33 +01:00
sudo apt install -yqq $@
2019-01-09 11:43:34 +01:00
return
fi
test_command pacman
if [ $? -eq 0 ]; then
2020-11-14 19:05:33 +01:00
sudo pacman -S $@
2019-01-09 11:43:34 +01:00
return
fi
2020-11-14 19:05:33 +01:00
error "distribution not recognized, can't install $@."
2019-01-09 11:43:34 +01:00
}
2020-02-13 16:26:53 +01:00
remove() {
test_command apt
if [ $? -eq 0 ]; then
sudo apt purge -yqq $1
2020-11-14 19:05:33 +01:00
sudo apt autoremove -yqq
2020-02-13 16:26:53 +01:00
return
fi
test_command pacman
if [ $? -eq 0 ]; then
sudo pacman -Rsn $1
return
fi
error "distribution not recognized, can't remove $1."
}
2019-04-26 15:52:31 +02:00
install_python3() {
test_command apt
if [ $? -eq 0 ]; then
2019-05-03 10:19:23 +02:00
sudo apt install -yqq python3 python3-pip
2019-04-26 15:52:31 +02:00
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 15:10:30 +02:00
install_neovim() {
test_command apt
if [ $? -eq 0 ]; then
2019-05-03 10:19:23 +02:00
sudo apt install -yqq neovim
2019-04-26 15:10:30 +02: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 11:43:34 +01:00
git_clone() {
2019-04-15 20:25:55 +02:00
info_n "cloning $1..."
2020-11-14 19:05:33 +01:00
git clone $@ > /dev/null 2>&1
2019-01-09 11:43:34 +01:00
if [ $? -eq 0 ]; then
2019-04-15 17:19:59 +02:00
echo " OK!"
else
echo
error "clone failed!"
2019-01-09 11:25:29 +01:00
fi
}
2019-04-26 15:32:43 +02:00
clone_dotfiles() {
if [ ! -d $HOME/.config/dotfiles ]; then
test_command git
if [ $? -ne 0 ]; then
if [ $sudo_available -ne 0 ]; then
2020-01-31 14:39:42 +01:00
error "git is needed, but you don't have git or sudo"
2019-04-26 15:32:43 +02:00
return 1
else
2020-01-31 14:44:36 +01:00
yes_no_ask_required "you'll need git for this, do you wish to install git?"
2019-04-26 15:32:43 +02:00
install git
fi
fi
git_clone https://gitea.tforgione.fr/tforgione/dotfiles/ $HOME/.config/dotfiles
2019-05-03 10:46:18 +02:00
echo "# Checks that the update is done weekly, if its not done, prints a nice message" > $HOME/.config/dotfiles/zsh/extraconfig.zsh
echo "export UPDATE_CHECK=weekly" >> $HOME/.config/dotfiles/zsh/extraconfig.zsh
2020-01-07 11:41:12 +01:00
echo "export UPDATE_CHECK_TYPE=sliding" >> $HOME/.config/dotfiles/zsh/extraconfig.zsh
2019-05-03 10:46:18 +02:00
2019-05-03 10:27:49 +02:00
mkdir -p $HOME/.config/dotfiles/.data
2019-05-03 11:04:17 +02:00
if [ $sudo_available -ne 0 ]; then
2019-05-03 10:27:49 +02:00
touch $HOME/.config/dotfiles/.data/noroot
fi
2019-04-26 15:32:43 +02:00
fi
}
2019-05-03 10:03:14 +02:00
configure_dotfiles() {
if [ ! -d $HOME/.config/dotfiles ]; then
2020-01-31 14:44:36 +01:00
yes_no_ask "do you wish to configure the dotfiles?"
if [ $? -ne 0 ]; then
return
fi
2019-05-03 10:03:14 +02:00
clone_dotfiles
fi
2019-05-03 10:03:14 +02:00
}
2019-05-03 10:13:11 +02:00
configure_shell() {
2020-02-05 09:44:54 +01:00
installed_locally=false
2019-01-09 11:25:29 +01:00
2020-01-31 14:44:36 +01:00
yes_no_ask "do you wish to install and configure zsh?"
2019-01-09 11:43:34 +01:00
if [ $? -ne 0 ]; then
2020-01-31 14:44:36 +01:00
yes_no_ask "you don't want zsh? Ok... but can I at least give you a nice bashrc?"
2019-05-03 10:13:11 +02:00
if [ $? -ne 0 ]; then
info "ok :'( I guess I'm not doing anything then"
return
fi
clone_dotfiles
2019-05-03 10:27:49 +02:00
rm -f $HOME/.bashrc
ln -s `realpath $HOME/.config/dotfiles/bashrc` `realpath $HOME/.bashrc`
2019-05-03 10:13:11 +02:00
2019-05-03 10:46:18 +02:00
mkdir -p $HOME/.config/dotfiles/bash
echo "# Checks that the update is done weekly, if its not done, prints a nice message" > $HOME/.config/dotfiles/bash/extraconfig.bash
echo "export UPDATE_CHECK=weekly" >> $HOME/.config/dotfiles/bash/extraconfig.bash
2019-05-03 10:13:11 +02:00
info "bashrc configured successfully"
2019-01-09 11:43:34 +01:00
return
2019-01-09 11:25:29 +01:00
fi
2019-04-26 15:32:43 +02:00
clone_dotfiles
2019-01-09 11:25:29 +01:00
2019-04-15 17:43:28 +02:00
test_command zsh
2019-01-09 11:43:34 +01:00
if [ $? -ne 0 ]; then
2019-04-16 13:46:58 +02:00
if [ $sudo_available -ne 0 ]; then
2020-02-05 09:44:54 +01:00
warn "zsh is needed, but you don't have zsh or sudo"
yes_no_ask "do you want me to compile and install zsh locally?"
if [ $? -ne 0 ]; then
error "zsh is needed, but you refused to install zsh"
return 1
fi
installed_locally=true
info "downloading zsh..."
mkdir tmp
cd tmp
curl https://codeload.github.com/zsh-users/zsh/tar.gz/zsh-5.7.1 --output zsh.tar.gz > /dev/null 2>&1
tar xvf zsh.tar.gz > /dev/null 2>&1
cd zsh-zsh-5.7.1
info "building zsh (this may take a while)..."
./Util/preconfig > /dev/null 2>&1
./configure --prefix ~/.local/share > /dev/null 2>&1
make > /dev/null 2>&1
info "installing zsh (this may take a while)..."
make install > /dev/null 2>&1
cd ../../
rm -rf tmp
info "zsh installed!"
2019-04-16 13:46:58 +02:00
else
2020-01-31 14:44:36 +01:00
yes_no_ask_required "this magnificent prompt is based on zsh, do you wish to install zsh?"
2019-04-16 13:46:58 +02:00
install zsh
fi
2019-01-09 11:25:29 +01:00
fi
2019-01-09 11:47:01 +01:00
mkdir -p $HOME/.config
2020-01-29 11:20:19 +01:00
if [ ! -d $HOME/.config/ohmyzsh ]; then
git_clone https://github.com/ohmyzsh/ohmyzsh $HOME/.config/ohmyzsh
2019-01-09 11:25:29 +01:00
fi
2019-01-09 11:47:01 +01:00
if [ -f $HOME/.zshrc ]; then
path1=`realpath $HOME/.zshrc`
path2=`realpath $HOME/.config/dotfiles/zshrc`
2019-01-09 11:43:34 +01:00
if [ "$path1" == "$path2" ]; then
2019-04-15 17:19:59 +02:00
info "it seems that your zshrc is already a good link."
2019-01-09 11:43:34 +01:00
else
2019-01-09 11:47:01 +01:00
if `realpath $HOME/.zshrc`; then
2019-04-15 17:19:59 +02:00
warn "you already have a zshrc, it will be moved to ~/.zshrc.bak"
2019-01-09 11:47:01 +01:00
mv $HOME/.zshrc $HOME/.zshrc.bak
2019-01-09 11:43:34 +01:00
fi
2019-04-15 17:19:59 +02:00
info "linking zshrc"
2019-01-09 11:47:01 +01:00
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
2019-01-09 11:43:34 +01:00
fi
else
2019-04-15 17:19:59 +02:00
info "linking zshrc"
2019-01-09 11:47:01 +01:00
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
2019-01-09 11:25:29 +01:00
fi
2019-01-09 11:43:34 +01:00
if [ "$user_shell" == "/bin/zsh" ]; then
2019-04-15 17:19:59 +02:00
info "it seems that you already use zsh."
2019-01-09 11:25:29 +01:00
else
2019-04-15 17:19:59 +02:00
info "it seems your shell is not zsh..."
2019-04-16 13:46:58 +02:00
if [ $sudo_available -eq 0 ]; then
# Sudo is available, run chsh
2020-01-31 14:44:36 +01:00
yes_no_ask "do you want to change your shell?"
2019-04-16 13:46:58 +02:00
if [ $? -eq 0 ]; then
info "changing your shell"
sudo chsh $user -s /bin/zsh
else
info "not doing anything"
fi
2019-01-09 11:43:34 +01:00
else
2019-04-16 13:46:58 +02:00
info "you don't have root, but you can run 'exec zsh' at the end of your bashrc"
2020-01-31 14:44:36 +01:00
yes_no_ask "do you wish to do that?"
2019-04-16 13:46:58 +02:00
if [ $? -eq 0 ]; then
2019-04-16 14:06:49 +02:00
echo >> $HOME/.bashrc
2020-02-05 09:44:54 +01:00
if [ "$installed_locally" == "true" ]; then
echo "exec ~/.local/share/bin/zsh" >> $HOME/.bashrc
else
echo "exec zsh" >> $HOME/.bashrc
fi
2019-04-16 14:06:49 +02:00
echo >> $HOME/.bashrc
2019-04-16 13:46:58 +02:00
else
info "not doing anything"
fi
2019-01-09 11:43:34 +01:00
fi
2019-01-09 11:25:29 +01:00
fi
}
2019-04-26 15:07:03 +02:00
configure_neovim() {
test_command nvim
if [ $? -ne 0 ] && [ $sudo_available -ne 0 ]; then
2020-01-31 14:39:42 +01:00
warn "you don't have sudo or neovim, skipping neovim configuration"
2019-04-26 15:07:03 +02:00
return
fi
2020-01-31 14:44:36 +01:00
yes_no_ask "do you wish to install and configure neovim?"
2019-04-26 15:07:03 +02:00
if [ $? -ne 0 ]; then
info "not installing neovim"
return
fi
2019-04-26 15:32:43 +02:00
clone_dotfiles
2019-04-26 15:07:03 +02:00
test_command nvim
if [ $? -ne 0 ]; then
info "installing neovim"
2019-04-26 15:28:02 +02:00
install_neovim
2019-04-26 15:07:03 +02:00
fi
2019-04-26 15:52:31 +02:00
# Try and install python3 and python-neovim
2020-11-14 19:05:33 +01:00
test_command python3 pip3
2019-04-26 15:52:31 +02:00
if [ $? -ne 0 ]; then
install_python3
fi
install_python_neovim
2019-04-26 15:38:56 +02:00
# Create config files an directories
2019-04-26 15:07:03 +02:00
mkdir -p $HOME/.config/nvim $HOME/.nvim/backups $HOME/.nvim/swp $HOME/.nvim/undo
2019-04-26 15:16:29 +02:00
rm -f $HOME/.config/nvim/init.vim
2019-04-26 15:07:03 +02:00
ln -s $HOME/.config/dotfiles/init.vim $HOME/.config/nvim/init.vim
2019-04-26 15:38:56 +02:00
# Install vim plug
2019-05-03 10:27:49 +02:00
curl -fLo $HOME/.local/share/nvim/site/autoload/plug.vim --create-dirs \
2019-04-26 15:38:56 +02:00
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
# Install plugins
nvim +PlugInstall +qa
2019-04-26 15:07:03 +02:00
}
2020-02-13 16:07:48 +01:00
configure_powerline() {
yes_no_ask "do you wish to install powerline fonts?"
if [ $? -ne 0 ]; then
return
fi
info installing powerline fonts
git_clone https://github.com/powerline/fonts
cd fonts
./install.sh
cd ..
rm -rf fonts
}
2020-01-31 14:35:07 +01:00
configure_rust() {
2020-01-31 14:44:36 +01:00
yes_no_ask "do you wish to install and configure rust?"
2020-01-31 14:35:07 +01:00
if [ $? -ne 0 ]; then
return
fi
curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path -y
2020-02-19 11:47:31 +01:00
export PATH=$HOME/.cargo/bin:$PATH
cargo_update_installed=1
yes_no_ask "do you wish to install cargo-update? it allows to update package automatically"
if [ $? -eq 0 ]; then
cargo_update_installed=0
cargo install cargo-update
fi
yes_no_ask "do you wish to install racer? it enabled rust completion from vim"
if [ $? -eq 0 ]; then
rustup toolchain add nightly
cargo +nightly install racer
if [ $cargo_update_installed -eq 0 ]; then
cargo install-update-config -t nightly racer
fi
fi
2020-01-31 14:35:07 +01:00
}
2020-02-13 16:26:53 +01:00
configure_node() {
yes_no_ask "do you wish to install and configure node and npm?"
if [ $? -ne 0 ]; then
return
fi
2020-02-19 11:47:31 +01:00
install nodejs npm
2020-02-13 16:26:53 +01:00
mkdir ~/.npmbin
npm config set prefix ~/.npmbin
2020-02-19 11:47:31 +01:00
npm install -g npm
2020-02-13 16:26:53 +01:00
remove npm
}
configure_awesome() {
yes_no_ask "do you wish to install and configure awesome?"
if [ $? -ne 0 ]; then
return
fi
2020-02-19 11:47:31 +01:00
install awesome acpi
2020-02-13 16:26:53 +01:00
git_clone https://gitea.tforgione.fr/tforgione/awesome ~/.config/awesome
git_clone https://github.com/horst3180/arc-icon-theme --depth 1 && cd arc-icon-theme
./autogen.sh --prefix=/usr
sudo make install
cd ..
rm -rf arc-icon-theme
}
2019-01-09 11:43:34 +01:00
main() {
echo_green "=== WELCOME TO TFORGIONE'S CONFIG INSTALLER ==="
2019-04-18 09:53:22 +02:00
info "before anything, i need to know if your user can use sudo"
2020-01-31 14:44:36 +01:00
yes_no_ask "can your user use sudo?"
2019-04-18 09:53:22 +02:00
sudo_available=$?
2019-05-03 10:03:14 +02:00
configure_dotfiles
2019-05-03 10:13:11 +02:00
configure_shell
2019-04-26 15:07:03 +02:00
configure_neovim
2020-02-13 16:07:48 +01:00
configure_powerline
2020-01-31 14:35:07 +01:00
configure_rust
2020-02-13 16:26:53 +01:00
configure_node
configure_awesome
2019-01-09 11:43:34 +01:00
}
main < /dev/tty
2019-01-09 11:25:29 +01:00