sh.tforgione.fr/tforgione.sh

258 lines
7.0 KiB
Bash
Raw Normal View History

2024-10-19 02:38:04 +01:00
#!/usr/bin/env bash
2019-01-09 10:25:29 +00:00
2020-01-07 10:41:12 +00:00
user=$USER
2019-01-09 10:25:29 +00:00
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() {
2020-11-14 18:05:33 +00: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 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
}
2024-10-19 02:38:04 +01:00
should_install_git=0
should_install_zsh=0
should_install_dotfiles=0
should_install_update_remainder=0
should_install_neovim=0
should_install_rust=0
should_install_nodejs=0
2019-01-09 10:43:34 +00:00
2024-10-19 02:38:04 +01:00
ask_for_dotfiles() {
yes_no_ask "do you wish to install and configure dotfiles?"
if [ $? -ne 0 ]; then
2019-01-09 10:43:34 +00:00
return
fi
2024-10-19 02:38:04 +01:00
test_command zsh
if [ $? -ne 0 ]; then
should_install_zsh=1
2020-02-13 15:26:53 +00:00
fi
2024-10-19 02:38:04 +01:00
test_command git
if [ $? -ne 0 ]; then
should_install_git=1
2020-02-13 15:26:53 +00:00
fi
2024-10-19 02:38:04 +01:00
should_install_dotfiles=1
2020-02-13 15:26:53 +00:00
2024-10-19 02:38:04 +01:00
yes_no_ask "do you want a weekly remainder to do your system's update?"
if [ $? -ne 0 ]; then
2019-04-26 14:52:31 +01:00
return
fi
2024-10-19 02:38:04 +01:00
should_install_update_remainder=1
2019-04-26 14:52:31 +01:00
}
2024-10-19 02:38:04 +01:00
ask_for_neovim() {
yes_no_ask "do you wish to install and configure neovim?"
if [ $? -ne 0 ]; then
2019-04-26 14:52:31 +01:00
return
fi
2024-10-19 02:38:04 +01:00
should_install_dotfiles=1
2019-04-26 14:52:31 +01:00
2024-10-19 02:38:04 +01:00
test_command neovim
if [ $? -ne 0 ]; then
should_install_neovim=1
fi
2019-04-26 14:52:31 +01:00
}
2024-10-19 02:38:04 +01:00
ask_for_rust() {
yes_no_ask "do you wish to install and configure rust?"
if [ $? -ne 0 ]; then
2019-04-26 14:10:30 +01:00
return
fi
2024-10-19 02:38:04 +01:00
test_command rustc
if [ $? -ne 0 ]; then
should_install_rust=1
2019-04-26 14:10:30 +01:00
fi
}
2024-10-19 02:38:04 +01:00
ask_for_nodejs() {
yes_no_ask "do you wish to install and configure nodejs?"
if [ $? -ne 0 ]; then
return
2019-01-09 10:25:29 +00:00
fi
2019-05-03 09:27:49 +01:00
2024-10-19 02:38:04 +01:00
test_command node
if [ $? -ne 0 ]; then
should_install_nodejs=1
2019-04-26 14:32:43 +01:00
fi
}
2024-10-19 02:38:04 +01:00
debug() {
if [ $should_install_git -eq 1 ]; then
info "should install git"
fi
2019-05-03 09:46:18 +01:00
2024-10-19 02:38:04 +01:00
if [ $should_install_zsh -eq 1 ]; then
info "should install zsh"
2019-01-09 10:25:29 +00:00
fi
2024-10-19 02:38:04 +01:00
if [ $should_install_dotfiles -eq 1 ]; then
info "should install dotfiles"
2019-01-09 10:25:29 +00:00
fi
2024-10-19 02:38:04 +01:00
if [ $should_install_neovim -eq 1 ]; then
info "should install neovim"
2019-01-09 10:25:29 +00:00
fi
2024-10-19 02:38:04 +01:00
if [ $should_install_rust -eq 1 ]; then
info "should install rust"
2019-01-09 10:25:29 +00:00
fi
2024-10-19 02:38:04 +01:00
if [ $should_install_nodejs -eq 1 ]; then
info "should install nodejs"
2019-01-09 10:25:29 +00:00
fi
}
2024-10-19 02:38:04 +01:00
run() {
packages=()
2019-04-26 14:07:03 +01:00
2024-10-19 02:38:04 +01:00
if [ $should_install_git -eq 1 ]; then
packages+=(git)
2019-04-26 14:07:03 +01:00
fi
2024-10-19 02:38:04 +01:00
if [ $should_install_zsh -eq 1 ]; then
packages+=(zsh)
fi
2019-04-26 14:32:43 +01:00
2024-10-19 02:38:04 +01:00
if [ $should_install_dotfiles -eq 1 ]; then
packages+=(neovim)
2019-04-26 14:07:03 +01:00
fi
2024-10-19 02:38:04 +01:00
if [ $should_install_nodejs -eq 1 ]; then
packages+=(nodejs)
packages+=(npm)
2019-04-26 14:52:31 +01:00
fi
2024-10-19 02:38:04 +01:00
sudo apt install -y ${packages[@]}
2019-04-26 14:52:31 +01:00
2024-10-19 02:38:04 +01:00
if [ $should_install_dotfiles -eq 1 ]; then
if [ ! -d $HOME/.config/ohmyzsh ]; then
git clone https://github.com/ohmyzsh/ohmyzsh $HOME/.config/ohmyzsh
fi
if [ ! -d $HOME/.config/dotfiles ]; then
git clone https://gitea.tforgione.fr/tforgione/dotfiles $HOME/.config/dotfiles
fi
sudo chsh $USER -s /bin/zsh
2019-04-26 14:07:03 +01:00
2024-10-19 02:38:04 +01:00
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
2019-04-26 14:38:56 +01:00
2019-04-26 14:07:03 +01:00
2024-10-19 02:38:04 +01:00
if [ $should_install_update_remainder -eq 1 ]; then
2020-02-13 15:07:48 +00:00
2024-10-19 02:38:04 +01: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
echo "export UPDATE_CHECK_TYPE=sliding" >> $HOME/.config/dotfiles/zsh/extraconfig.zsh
export UPDATE_CHECK=weekly
export UPDATE_CHECK_TYPE=sliding
$HOME/.config/dotfiles/bin/update postpone
fi
2020-02-13 15:07:48 +00:00
fi
2024-10-19 02:38:04 +01:00
if [ $should_install_nodejs -eq 1 ]; then
mkdir -p $HOME/.npmbin
npm config set prefix $HOME/.npmbin
npm install -g npm
sudo apt purge npm -y
2020-01-31 13:35:07 +00:00
fi
2024-10-19 02:38:04 +01:00
if [ $should_install_neovim -eq 1 ]; then
# Create config files an directories
mkdir -p $HOME/.nvim/backups $HOME/.nvim/swp $HOME/.nvim/undo
rm -f $HOME/.config/nvim
ln -s $HOME/.config/dotfiles/nvim $HOME/.config/nvim
2024-10-19 02:38:04 +01:00
# Install vim plug
curl -fLo $HOME/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
2024-10-19 02:38:04 +01:00
# Install plugins
nvim +PlugInstall +qa
fi
2020-01-31 13:35:07 +00:00
2024-10-19 02:38:04 +01:00
if [ $should_install_rust -eq 1 ]; then
curl https://sh.rustup.rs -sSf | sh -s -- --no-modify-path -y
export PATH=$HOME/.cargo/bin:$PATH
rustup component add rust-analyzer
cargo install cargo-update
2020-02-13 15:26:53 +00:00
fi
}
2024-10-19 02:38:04 +01:00
banner() {
echo -e "\x1b[32;1m┌───────────────────────────────────────────────────────────────────────────────────────────┐"
echo "│ _ __ _ _ _ _ _ _ │"
echo "│ | | / _| (_) ( ) (_) | | | | | │"
echo "│ | |_| |_ ___ _ __ __ _ _ ___ _ __ ___|/ ___ _ _ __ ___| |_ __ _| | | ___ _ __ │"
echo "│ | __| _/ _ \| '__/ _\` | |/ _ \| '_ \ / _ \ / __| | | '_ \/ __| __/ _\` | | |/ _ \ '__| │"
echo "│ | |_| || (_) | | | (_| | | (_) | | | | __/ \__ \ | | | | \__ \ || (_| | | | __/ | │"
echo "│ \__|_| \___/|_| \__, |_|\___/|_| |_|\___| |___/ |_|_| |_|___/\__\__,_|_|_|\___|_| │"
echo "│ __/ | │"
echo "│ |___/ │"
echo "├───────────────────────────────────────────────────────────────────────────────────────────┤"
echo "│ WELCOME TO TFORGIONE'S INSTALLER │"
echo -e "└───────────────────────────────────────────────────────────────────────────────────────────┘\x1b[0m"
2020-02-13 15:26:53 +00:00
}
2019-01-09 10:43:34 +00:00
main() {
2024-10-19 02:38:04 +01:00
banner
2019-04-18 08:53:22 +01:00
info "before anything, i need to know if your user can use sudo"
2020-01-31 13:44:36 +00:00
yes_no_ask "can your user use sudo?"
2019-04-18 08:53:22 +01:00
sudo_available=$?
2024-10-19 02:38:04 +01:00
ask_for_dotfiles
ask_for_neovim
ask_for_rust
ask_for_nodejs
debug
run
2019-01-09 10:43:34 +00:00
}
main < /dev/tty