From a4fc0b8cdcdd46675261a3c707cef1b08e5149a8 Mon Sep 17 00:00:00 2001 From: Max Richter Date: Wed, 11 Oct 2023 16:39:01 +0200 Subject: [PATCH] fix setup script --- .dotfiles/helpers/asdf-install.sh | 5 +- .dotfiles/helpers/installer.sh | 63 ++++++++-------- .dotfiles/helpers/linker.sh | 14 ---- .dotfiles/helpers/multiselect.sh | 2 - .dotfiles/helpers/prompt.sh | 2 - .dotfiles/helpers/spinner.sh | 0 .../install/{install-asdf.sh => asdf.sh} | 0 .dotfiles/install/install-nvim.sh | 9 --- .dotfiles/install/zsh-autosuggestions.sh | 8 --- .dotfiles/setup.sh | 71 +++++++------------ 10 files changed, 62 insertions(+), 112 deletions(-) mode change 100644 => 100755 .dotfiles/helpers/installer.sh delete mode 100644 .dotfiles/helpers/linker.sh delete mode 100644 .dotfiles/helpers/spinner.sh rename .dotfiles/install/{install-asdf.sh => asdf.sh} (100%) delete mode 100755 .dotfiles/install/install-nvim.sh delete mode 100755 .dotfiles/install/zsh-autosuggestions.sh diff --git a/.dotfiles/helpers/asdf-install.sh b/.dotfiles/helpers/asdf-install.sh index 39418be..0953928 100644 --- a/.dotfiles/helpers/asdf-install.sh +++ b/.dotfiles/helpers/asdf-install.sh @@ -1,4 +1,4 @@ -asdfInstall(){ +asdf_install(){ . "$HOME/.asdf/asdf.sh" if [ "$(which asdf)" = "" ]; then echo "Asdf not installed" @@ -11,6 +11,3 @@ asdfInstall(){ echo "----------------------------------------------" fi } - - -[[ "${1}" != "--source-only" ]] && asdfInstall "${@}" diff --git a/.dotfiles/helpers/installer.sh b/.dotfiles/helpers/installer.sh old mode 100644 new mode 100755 index 8b71414..cd78521 --- a/.dotfiles/helpers/installer.sh +++ b/.dotfiles/helpers/installer.sh @@ -1,35 +1,40 @@ -isInstalled() { - if [ "$(which $1)" != "" ]; then - return 0 - fi - return 1 +#!/bin/bash + +# Function to check if a command exists +command_exists() { + command -v "$1" >/dev/null 2>&1 } -installOptional() { - echo "install optional '$*'" - # Check if any of the listed programs are installed - # if not install the first one; - for prog in "$@"; do - if isInstalled $prog; then - echo "$prog is installed" - break - fi - done +package_manager=$1 +# Detect the package manager +if command_exists apt-get; then + package_manager="apt" +elif command_exists yum; then + package_manager="yum" +elif command_exists pacman; then + package_manager="pacman" +else + echo "Unsupported package manager. Exiting." + exit 1 +fi - install $1 +# Function to install packages based on the package manager +install_package() { + case $package_manager in + apt) + sudo apt-get install -y $1 + ;; + yum) + sudo yum install -y $1 + ;; + pacman) + sudo pacman -S --noconfirm $1 + ;; + *) + echo "Unsupported package manager: $package_manager" + exit 1 + ;; + esac } - -install() { - # Check if program is already installed - if isInstalled $1; then - echo " ✓ $1 is already installed" - else - echo " - installing $1 ..." - sudo apt-get install $1 -y >/dev/null - echo " ✓ finished" - fi -} - -[[ "${1}" != "--source-only" ]] && install "${@}" diff --git a/.dotfiles/helpers/linker.sh b/.dotfiles/helpers/linker.sh deleted file mode 100644 index 84ab1b3..0000000 --- a/.dotfiles/helpers/linker.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash -linkFile() { - #Move old file - if [ -f "$HOME/$1" ]; then - echo " - moving old file to $1_bak" - mv "$HOME/$1" "$HOME/$1_bak" - fi - - echo " - linking $1 --> $HOME/$1" - - ln -s "$(pwd)/configs/$1" "$HOME/$1" -} - -[[ "${1}" != "--source-only" ]] && linkFile "${@}" diff --git a/.dotfiles/helpers/multiselect.sh b/.dotfiles/helpers/multiselect.sh index 66acd29..d618295 100644 --- a/.dotfiles/helpers/multiselect.sh +++ b/.dotfiles/helpers/multiselect.sh @@ -104,5 +104,3 @@ function multiselect() { eval $retval='("${selected[@]}")' } - -[[ "${1}" != "--source-only" ]] && multiselect "${@}" diff --git a/.dotfiles/helpers/prompt.sh b/.dotfiles/helpers/prompt.sh index 4896a7f..a832024 100644 --- a/.dotfiles/helpers/prompt.sh +++ b/.dotfiles/helpers/prompt.sh @@ -7,5 +7,3 @@ prompt() { *) echo "invalid" ;; esac } - -[[ "${1}" != "--source-only" ]] && prompt "${@}" diff --git a/.dotfiles/helpers/spinner.sh b/.dotfiles/helpers/spinner.sh deleted file mode 100644 index e69de29..0000000 diff --git a/.dotfiles/install/install-asdf.sh b/.dotfiles/install/asdf.sh similarity index 100% rename from .dotfiles/install/install-asdf.sh rename to .dotfiles/install/asdf.sh diff --git a/.dotfiles/install/install-nvim.sh b/.dotfiles/install/install-nvim.sh deleted file mode 100755 index 2ba617c..0000000 --- a/.dotfiles/install/install-nvim.sh +++ /dev/null @@ -1,9 +0,0 @@ -if [ -f "$HOME/.config/nvim/init.lua" ]; then - echo " - moving old file to init.lua.BAK" - mv "$HOME/.config/nvim/init.lua" "$HOME/.config/nvim/init.lua.BAK" -fi - -echo " - linking init.vim --> init.vim" -mkdir -p $HOME/.config/nvim -ln -s "$HOME/.dotfiles/configs/init.lua" "$HOME/.config/nvim/init.lua" -ln -s "$HOME/.dotfiles/configs/lua" "$HOME/.config/nvim/lua" \ No newline at end of file diff --git a/.dotfiles/install/zsh-autosuggestions.sh b/.dotfiles/install/zsh-autosuggestions.sh deleted file mode 100755 index 8413880..0000000 --- a/.dotfiles/install/zsh-autosuggestions.sh +++ /dev/null @@ -1,8 +0,0 @@ -FOLDER=${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions -if [ -s $FOLDER ]; then - echo " ✓ zsh-autosuggestions is already installed" -else - echo " - cloning github.com/zsh-users/zsh-autosuggestions into $FOLDER" - git clone --quiet https://github.com/zsh-users/zsh-autosuggestions $FOLDER > /dev/null - echo " - finished" -fi \ No newline at end of file diff --git a/.dotfiles/setup.sh b/.dotfiles/setup.sh index ba64901..717de7f 100755 --- a/.dotfiles/setup.sh +++ b/.dotfiles/setup.sh @@ -1,17 +1,15 @@ #!/bin/bash -cd "$(dirname "$0")" -INTERACTIVE="false" -if [ $- == *i* ]; then - INTERACTIVE="true" -fi +INTERACTIVE=false + if [ -t 0 ] ; then + INTERACTIVE=true + fi #Loading all the helper scripts -. ./helpers/installer.sh --source-only -. ./helpers/prompt.sh --source-only -. ./helpers/linker.sh --source-only -. ./helpers/multiselect.sh --source-only +source ./helpers/installer.sh +source ./helpers/prompt.sh +source ./helpers/multiselect.sh echo "-- welcome to my setup script --" @@ -19,20 +17,15 @@ if [ "$(which git)" = "" ] && ["$(which curl)" = ""]; then echo "-- installing prerequesits (git, curl) --" - if [ $INTERACTIVE = "true" ]; then + if [ $INTERACTIVE = true ]; then if [ "$(prompt " - do you want to continue")" != "yes" ]; then echo " alllrighty then, byyye" exit fi fi - echo "" - - #Prerequesits - echo "-- installing prerequisites --" - - install git - install curl + install_package git + install_package curl echo "-----------------------------------" @@ -59,7 +52,7 @@ for i in "${!OPTIONS_VALUES[@]}"; do OPTIONS_STRING+="${OPTIONS_VALUES[$i]} (${OPTIONS_LABELS[$i]});" done -if [ $INTERACTIVE = "true" ]; then +if [ $INTERACTIVE = true ]; then multiselect SELECTED "$OPTIONS_STRING": fi @@ -75,50 +68,40 @@ INST_DENO=${SELECTED[7]} INST_HUGO=${SELECTED[8]} INST_RUST=${SELECTED[9]} -if [ $INTERACTIVE = "false" ]; then +if [ $INTERACTIVE = false ]; then INST_ZSH=true INST_ASDF=true INST_NVIM=true fi -echo "-----------------------------------" - echo -e "-- installing programs --" -[[ "$INST_DRNV" = true ]] && install direnv + +[[ "$INST_DRNV" = true ]] && install_package direnv if [ "$INST_ASDF" = true ]; then # Requirements for ASDF - install gnupg2 - install unzip - ./install/install-asdf.sh + install_package gnupg2 + install_package unzip + $HOME/.dotfiles/install/asdf.sh if [ "$INST_NVIM" = true ]; then - asdfInstall neovim - ./install/install-nvim.sh + asdf_install neovim fi - [[ "$INST_NODE" = true ]] && asdfInstall nodejs - [[ "$INST_GO" = true ]] && asdfInstall golang - [[ "$INST_PYTH" = true ]] && asdfInstall python - [[ "$INST_DENO" = true ]] && asdfInstall deno - [[ "$INST_HUGO" = true ]] && asdfInstall hugo - [[ "$INST_RUST" = true ]] && asdfInstall rust + [[ "$INST_NODE" = true ]] && asdf_install nodejs + [[ "$INST_GO" = true ]] && asdf_install golang + [[ "$INST_PYTH" = true ]] && asdf_install python + [[ "$INST_DENO" = true ]] && asdf_install deno + [[ "$INST_HUGO" = true ]] && asdf_install hugo + [[ "$INST_RUST" = true ]] && asdf_install rust fi -echo "-- linking .dotfiles --" - -linkFile .p10k.zsh -linkFile .dircolors -linkFile .tmux.conf - if [ "$INST_ZSH" = true ]; then echo "-- installing oh-my-zsh --" - linkFile .zshrc - install zsh + install_package zsh - zsh $(pwd)/install/oh-my-zsh.sh - zsh $(pwd)/install/zsh-autosuggestions.sh - zsh $(pwd)/install/p10k.sh + zsh $HOME/.dotfiles/install/oh-my-zsh.sh + zsh $HOME/.dotfiles/install/p10k.sh echo "-----------------------------------" fi