258 lines
7.0 KiB
Bash
Executable File
258 lines
7.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
user=$USER
|
|
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() {
|
|
for i in $@; do
|
|
command -v $i > /dev/null 2>&1
|
|
res=$?
|
|
if [ $res -ne 0 ]; then
|
|
return $res
|
|
fi
|
|
done
|
|
}
|
|
|
|
yes_no_ask() {
|
|
info_n $@ "[Y/n]"
|
|
read answer
|
|
if ! [[ "$answer" == "N" ]] && ! [[ "$answer" == "n" ]]; then
|
|
return 0
|
|
else
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
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
|
|
|
|
ask_for_dotfiles() {
|
|
yes_no_ask "do you wish to install and configure dotfiles?"
|
|
if [ $? -ne 0 ]; then
|
|
return
|
|
fi
|
|
|
|
test_command zsh
|
|
if [ $? -ne 0 ]; then
|
|
should_install_zsh=1
|
|
fi
|
|
|
|
test_command git
|
|
if [ $? -ne 0 ]; then
|
|
should_install_git=1
|
|
fi
|
|
|
|
should_install_dotfiles=1
|
|
|
|
yes_no_ask "do you want a weekly remainder to do your system's update?"
|
|
if [ $? -ne 0 ]; then
|
|
return
|
|
fi
|
|
|
|
should_install_update_remainder=1
|
|
}
|
|
|
|
ask_for_neovim() {
|
|
yes_no_ask "do you wish to install and configure neovim?"
|
|
if [ $? -ne 0 ]; then
|
|
return
|
|
fi
|
|
|
|
should_install_dotfiles=1
|
|
|
|
test_command neovim
|
|
if [ $? -ne 0 ]; then
|
|
should_install_neovim=1
|
|
fi
|
|
}
|
|
|
|
ask_for_rust() {
|
|
yes_no_ask "do you wish to install and configure rust?"
|
|
if [ $? -ne 0 ]; then
|
|
return
|
|
fi
|
|
|
|
test_command rustc
|
|
if [ $? -ne 0 ]; then
|
|
should_install_rust=1
|
|
fi
|
|
}
|
|
|
|
ask_for_nodejs() {
|
|
yes_no_ask "do you wish to install and configure nodejs?"
|
|
if [ $? -ne 0 ]; then
|
|
return
|
|
fi
|
|
|
|
test_command node
|
|
if [ $? -ne 0 ]; then
|
|
should_install_nodejs=1
|
|
fi
|
|
}
|
|
|
|
debug() {
|
|
if [ $should_install_git -eq 1 ]; then
|
|
info "should install git"
|
|
fi
|
|
|
|
if [ $should_install_zsh -eq 1 ]; then
|
|
info "should install zsh"
|
|
fi
|
|
|
|
if [ $should_install_dotfiles -eq 1 ]; then
|
|
info "should install dotfiles"
|
|
fi
|
|
|
|
if [ $should_install_neovim -eq 1 ]; then
|
|
info "should install neovim"
|
|
fi
|
|
|
|
if [ $should_install_rust -eq 1 ]; then
|
|
info "should install rust"
|
|
fi
|
|
|
|
if [ $should_install_nodejs -eq 1 ]; then
|
|
info "should install nodejs"
|
|
fi
|
|
}
|
|
|
|
run() {
|
|
packages=()
|
|
|
|
if [ $should_install_git -eq 1 ]; then
|
|
packages+=(git)
|
|
fi
|
|
|
|
if [ $should_install_zsh -eq 1 ]; then
|
|
packages+=(zsh)
|
|
fi
|
|
|
|
if [ $should_install_dotfiles -eq 1 ]; then
|
|
packages+=(neovim)
|
|
fi
|
|
|
|
if [ $should_install_nodejs -eq 1 ]; then
|
|
packages+=(nodejs)
|
|
packages+=(npm)
|
|
fi
|
|
|
|
sudo apt install -y ${packages[@]}
|
|
|
|
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
|
|
|
|
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
|
|
|
|
|
|
if [ $should_install_update_remainder -eq 1 ]; then
|
|
|
|
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
|
|
fi
|
|
|
|
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
|
|
fi
|
|
|
|
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
|
|
|
|
# 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
|
|
|
|
# Install plugins
|
|
nvim +PlugInstall +qa
|
|
fi
|
|
|
|
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
|
|
fi
|
|
}
|
|
|
|
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"
|
|
}
|
|
|
|
main() {
|
|
banner
|
|
|
|
info "before anything, i need to know if your user can use sudo"
|
|
yes_no_ask "can your user use sudo?"
|
|
sudo_available=$?
|
|
|
|
ask_for_dotfiles
|
|
ask_for_neovim
|
|
ask_for_rust
|
|
ask_for_nodejs
|
|
|
|
debug
|
|
run
|
|
}
|
|
|
|
main < /dev/tty
|