This commit is contained in:
Thomas Forgione 2025-05-06 17:38:23 +02:00
parent 78625c52d7
commit 53c5859678

View File

@ -56,12 +56,16 @@ has_apt=0
has_pacman=0
should_install_git=0
should_install_zsh=0
should_clone_dotfiles=0
should_install_dotfiles=0
should_install_update_remainder=0
should_install_neovim=0
should_configure_neovim=0
should_install_rust=0
should_install_nodejs=0
should_configure_nodejs=0
should_install_python=0
should_configure_python=0
should_install_hyprland=0
find_os() {
@ -84,48 +88,77 @@ find_os() {
}
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
if [ $? -eq 0 ]; then
has_zsh=1
else
has_zsh=0
fi
test_command git
if [ $? -ne 0 ]; then
should_install_git=1
if [ $? -eq 0 ]; then
has_git=1
else
has_git=0
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
if [ $has_sudo -eq 0 ]; then
if [ $has_zsh -eq 0 ] || [ $has_git -eq 0 ]; then
warn "can't install dotfiles without sudo, or zsh and git"
return
fi
fi
should_install_update_remainder=1
yes_no_ask "do you wish to install and configure dotfiles?"
if [ $? -eq 0 ]; then
if [ $has_zsh -eq 0 ]; then
should_install_zsh=1
fi
if [ $has_git -eq 0 ]; then
should_install_git=1
fi
should_clone_dotfiles=1
should_install_dotfiles=1
yes_no_ask "do you want a weekly remainder to do your system's update?"
if [ $? -eq 0 ]; then
should_install_update_remainder=1
fi
fi
}
ask_for_neovim() {
if [ $has_sudo -eq 0 ]; then
test_command nvim
if [ $? -eq 0 ]; then
has_neovim=1
else
has_neovim=0
fi
if [ $has_neovim -eq 0 ] && [ $has_sudo -eq 0 ]; then
warn "can't install neovim without sudo"
return
fi
yes_no_ask "do you wish to install and configure neovim?"
if [ $? -ne 0 ]; then
return
if [ $has_neovim -eq 1 ]; then
yes_no_ask "do you wish to configure neovim?"
if [ $? -eq 0 ]; then
should_clone_dotfiles=1
should_configure_neovim=1
fi
else
yes_no_ask "do you wish to install and configure neovim?"
if [ $? -eq 0 ]; then
should_clone_dotfiles=1
should_install_neovim=1
should_configure_neovim=1
fi
fi
should_install_dotfiles=1
test_command neovim
if [ $? -ne 0 ]; then
should_install_neovim=1
fi
}
ask_for_rust() {
@ -141,34 +174,58 @@ ask_for_rust() {
}
ask_for_python() {
if [ $has_sudo -eq 0 ]; then
test_command python
if [ $? -eq 0 ]; then
has_python=1
else
has_python=0
fi
if [ $has_python -eq 0 ] && [ $has_sudo -eq 0 ]; then
warn "can't install python without sudo"
return
fi
yes_no_ask "do you wish to install and configure python?"
if [ $? -ne 0 ]; then
return
if [ $has_python -eq 1 ]; then
yes_no_ask "do you wish to configure python?"
if [ $? -eq 0 ]; then
should_configure_python=1
fi
else
yes_no_ask "do you wish to install and configure python?"
if [ $? -eq 0 ]; then
should_install_python=1
should_configure_python=1
fi
fi
should_install_python=1
}
ask_for_nodejs() {
if [ $has_sudo -eq 0 ]; then
test_command node
if [ $? -eq 0 ]; then
has_node=1
else
has_node=0
fi
if [ $has_node -eq 0 ] && [ $has_sudo -eq 0 ]; then
warn "can't install node without sudo"
return
fi
yes_no_ask "do you wish to install and configure nodejs?"
if [ $? -ne 0 ]; then
return
if [ $has_node -eq 1 ]; then
yes_no_ask "do you wish to configure nodejs?"
if [ $? -eq 0 ]; then
should_configure_node=1
fi
else
yes_no_ask "do you wish to install and configure nodejs?"
if [ $? -eq 0 ]; then
should_install_node=1
should_configure_node=1
fi
fi
test_command node
if [ $? -ne 0 ]; then
should_install_nodejs=1
fi
}
ask_for_hyprland() {
@ -187,6 +244,7 @@ ask_for_hyprland() {
return
fi
should_clone_dotfiles=1
should_install_hyprland=1
}
@ -262,7 +320,7 @@ run() {
fi
# Install some python plugins that work well with neovim if necessary
if [ $should_install_neovim -eq 1 ]; then
if [ $should_configure_neovim -eq 1 ]; then
python_packages+=(neovim)
python_packages+=(pycodestyle)
python_packages+=("python-lsp-server[all]")
@ -288,37 +346,43 @@ run() {
curl -fsSL https://deb.nodesource.com/setup_current.x | sudo bash
fi
if [ $has_apt -eq 1 ]; then
sudo apt install -y ${packages[@]}
if [ $has_sudo -eq 1 ]; then
if [ $has_apt -eq 1 ]; then
sudo apt install -y ${packages[@]}
if [ $should_install_neovim ]; then
# Install neovim from github to get latest version
curl -L https://github.com/neovim/neovim/releases/download/stable/nvim-linux-x86_64.tar.gz -o tmp.tar.gz
sudo tar xf tmp.tar.gz -C / --strip-components=1
rm tmp.tar.gz
if [ $should_install_neovim ]; then
# Install neovim from github to get latest version
curl -L https://github.com/neovim/neovim/releases/download/stable/nvim-linux-x86_64.tar.gz -o tmp.tar.gz
sudo tar xf tmp.tar.gz -C / --strip-components=1
rm tmp.tar.gz
fi
elif [ $has_pacman -eq 1 ]; then
sudo pacman -Sy ${packages[@]} --noconfirm --needed
fi
elif [ $has_pacman -eq 1 ]; then
sudo pacman -Sy ${packages[@]} --noconfirm --needed
fi
if [ $should_install_dotfiles ]; then
sudo chsh $USER -s /usr/bin/zsh
if [ $should_configure_dotfiles ]; then
sudo chsh $USER -s /usr/bin/zsh
fi
fi
# Prepare venv for python
if [ $should_install_python -eq 1 ]; then
if [ $should_configure_python -eq 1 ]; then
python -m venv $HOME/.venv
VIRTUAL_ENV=$HOME/.venv $HOME/.venv/bin/pip install ${python_packages[@]}
fi
# Configure dotfiles
if [ $should_clone_dotfiles -eq 1 ]; then
if [ ! -d $HOME/.config/dotfiles ]; then
git clone https://gitea.tforgione.fr/tforgione/dotfiles $HOME/.config/dotfiles
fi
fi
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
ln -s $HOME/.config/dotfiles/zshrc $HOME/.zshrc
@ -348,12 +412,11 @@ run() {
fi
# Configure neovim
if [ $should_install_neovim -eq 1 ]; then
if [ $should_configure_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
mkdir -p $HOME/.config/nvim
ln -s $HOME/.config/dotfiles/nvim.lua $HOME/.config/nvim/init.lua
ln -s $HOME/.config/dotfiles/nvim/init.lua $HOME/.config/nvim/init.lua
# Install vim plug
curl -fLo $HOME/.local/share/nvim/site/autoload/plug.vim --create-dirs \
@ -364,7 +427,7 @@ run() {
fi
# Configure nodejs
if [ $should_install_nodejs -eq 1 ]; then
if [ $should_configure_nodejs -eq 1 ]; then
mkdir -p $HOME/.npmbin
npm config set prefix $HOME/.npmbin
npm install -g npm