fix setup script

This commit is contained in:
max_richter 2023-10-11 16:39:01 +02:00
parent 752fe71647
commit a4fc0b8cdc
10 changed files with 62 additions and 112 deletions

View File

@ -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 "${@}"

63
.dotfiles/helpers/installer.sh Normal file → Executable file
View File

@ -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
install $1
}
install() {
# Check if program is already installed
if isInstalled $1; then
echo "$1 is already installed"
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 " - installing $1 ..."
sudo apt-get install $1 -y >/dev/null
echo " ✓ finished"
echo "Unsupported package manager. Exiting."
exit 1
fi
}
[[ "${1}" != "--source-only" ]] && install "${@}"
# 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
}

View File

@ -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 "${@}"

View File

@ -104,5 +104,3 @@ function multiselect() {
eval $retval='("${selected[@]}")'
}
[[ "${1}" != "--source-only" ]] && multiselect "${@}"

View File

@ -7,5 +7,3 @@ prompt() {
*) echo "invalid" ;;
esac
}
[[ "${1}" != "--source-only" ]] && prompt "${@}"

View File

@ -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"

View File

@ -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

View File

@ -1,17 +1,15 @@
#!/bin/bash
cd "$(dirname "$0")"
INTERACTIVE="false"
if [ $- == *i* ]; then
INTERACTIVE="true"
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