From 0349769225e09059d3963f9916205d36accc71d1 Mon Sep 17 00:00:00 2001 From: Ahmad Ansori Palembani Date: Sat, 20 Jul 2024 18:51:50 +0700 Subject: [PATCH] fix(script/bootstrap): Fix some error * Missing ;; in case statement * Should only configure doas if doas is installed * Refactor is_package_exists function to use return --- bootstrap | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/bootstrap b/bootstrap index 3abd4fc..abd1597 100755 --- a/bootstrap +++ b/bootstrap @@ -25,14 +25,14 @@ # === Function and Variable === is_package_exists() { - [ $(command -v "$1" | wc -l) -gt 0 ] && echo 1 || echo 0 + [ $(command -v "$1" | wc -l) -gt 0 ] && return 0 || return 1 } case "$OSTYPE" in "darwin"* ) DISTRO="apple" ;; - *) DISTRO="$(cat /etc/*-release | grep ^ID | head -n1 | cut -d '=' -f2 | cut -d '"' -f2)" ;; + * ) DISTRO="$(cat /etc/*-release | grep ^ID | head -n1 | cut -d '=' -f2 | cut -d '"' -f2)" ;; esac -[ "$SUDO" = "" ] && { [ $(is_package_exists doas) = 1 ] && SUDO="doas" || SUDO="sudo"; } +[ "$SUDO" = "" ] && { is_package_exists doas && SUDO="doas" || SUDO="sudo"; } [ "$PACMAN" = "" ] && { case $DISTRO in "arch" ) PACMAN="pacman" ;; @@ -71,14 +71,14 @@ install_aur_package() { # >> Paranoia checks [ $DISTRO = "arch" ] || { echo "AUR only available in Arch, skipping..."; return; } - [ $(is_package_exists $AUR) = 1 ] || { echo "AUR helper '$AUR' is not installed, skipping..."; return; } + is_package_exists $AUR || { echo "AUR helper '$AUR' is not installed, skipping..."; return; } [ "$1" = "" ] && { echo "No AUR package candidate is specified, skipping..."; return; } # << case "$AUR" in - "paru" ) $AUR -S --noconfirm --skipreview "$@" - * ) $AUR -S --noconfirm "$@" + "paru" ) $AUR -S --noconfirm --skipreview "$@" ;; + * ) $AUR -S --noconfirm "$@" ;; esac } @@ -112,13 +112,15 @@ $SUDO $ZI_DOTFILES/zsh-xdg-setup echo "Installing zsh config..." ln -si $ZI_DOTFILES/.config/zsh $HOME/.config/zsh -echo "Configuring doas..." -echo """permit persist :wheel -permit nopass root as root""" > /tmp/doas.conf.tmp -echo "=======/etc/doas.conf=======" -cat /tmp/doas.conf.tmp -echo "============================" -$SUDO cp -i /tmp/doas.conf.tmp /etc/doas.conf +is_package_exists doas && { + echo "Configuring doas..." + echo "permit persist :wheel" > /tmp/doas.conf.tmp + echo "permit nopass root as root" >> /tmp/doas.conf.tmp + echo "=======/etc/doas.conf=======" + cat /tmp/doas.conf.tmp + echo "============================" + $SUDO cp -i /tmp/doas.conf.tmp /etc/doas.conf +} echo "============================" echo "Bootstrap completed, please restart your shell!"