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
This commit is contained in:
Ahmad Ansori Palembani 2024-07-20 18:51:50 +07:00
parent 6f569742b5
commit 0349769225
Signed by: null2264
GPG key ID: BA64F8B60AF3EFB6

View file

@ -25,14 +25,14 @@
# === Function and Variable === # === Function and Variable ===
is_package_exists() { 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 case "$OSTYPE" in
"darwin"* ) DISTRO="apple" ;; "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 esac
[ "$SUDO" = "" ] && { [ $(is_package_exists doas) = 1 ] && SUDO="doas" || SUDO="sudo"; } [ "$SUDO" = "" ] && { is_package_exists doas && SUDO="doas" || SUDO="sudo"; }
[ "$PACMAN" = "" ] && { [ "$PACMAN" = "" ] && {
case $DISTRO in case $DISTRO in
"arch" ) PACMAN="pacman" ;; "arch" ) PACMAN="pacman" ;;
@ -71,14 +71,14 @@ install_aur_package() {
# >> Paranoia checks # >> Paranoia checks
[ $DISTRO = "arch" ] || { echo "AUR only available in Arch, skipping..."; return; } [ $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; } [ "$1" = "" ] && { echo "No AUR package candidate is specified, skipping..."; return; }
# << # <<
case "$AUR" in case "$AUR" in
"paru" ) $AUR -S --noconfirm --skipreview "$@" "paru" ) $AUR -S --noconfirm --skipreview "$@" ;;
* ) $AUR -S --noconfirm "$@" * ) $AUR -S --noconfirm "$@" ;;
esac esac
} }
@ -112,13 +112,15 @@ $SUDO $ZI_DOTFILES/zsh-xdg-setup
echo "Installing zsh config..." echo "Installing zsh config..."
ln -si $ZI_DOTFILES/.config/zsh $HOME/.config/zsh ln -si $ZI_DOTFILES/.config/zsh $HOME/.config/zsh
echo "Configuring doas..." is_package_exists doas && {
echo """permit persist :wheel echo "Configuring doas..."
permit nopass root as root""" > /tmp/doas.conf.tmp echo "permit persist :wheel" > /tmp/doas.conf.tmp
echo "=======/etc/doas.conf=======" echo "permit nopass root as root" >> /tmp/doas.conf.tmp
cat /tmp/doas.conf.tmp echo "=======/etc/doas.conf======="
echo "============================" cat /tmp/doas.conf.tmp
$SUDO cp -i /tmp/doas.conf.tmp /etc/doas.conf echo "============================"
$SUDO cp -i /tmp/doas.conf.tmp /etc/doas.conf
}
echo "============================" echo "============================"
echo "Bootstrap completed, please restart your shell!" echo "Bootstrap completed, please restart your shell!"