Use dependencies variable to clean up output, also make installing dependencies more reliable by updating the package list if the installation fails the first time

This commit is contained in:
2026-02-22 08:10:34 +01:00
parent 32c44d84d8
commit 59b1b711ac

View File

@@ -6,13 +6,43 @@ BACKUP_LIMIT=3
# ---------------- Check dependencies ----------------
echo -e '\nInstalling dependencies ...' >&2
if ! which yay >/dev/null 2>&1; then
! which git >/dev/null 2>&1 &&
if ! sudo pacman -S --noconfirm git; then
if sudo pacman -Syu; then
sudo pacman -S --noconfirm git
else
echo -e '\nUnable to fetch package list. Aborting ...' >&2
exit 1
fi
fi
cd /tmp
git clone https://aur.archlinux.org/yay.git
cd yay
makepkg -cirs
cd ..
rm -fr yay
cd
fi
yay -S --needed --noconfirm curl git neovim pacman-contrib yaycache
dependencies=
! which curl >/dev/null 2>&1 && dependencies="$dependencies curl"
! which git >/dev/null 2>&1 && dependencies="$dependencies git"
! which neovim >/dev/null 2>&1 && dependencies="$dependencies neovim"
! which pacman-contrib >/dev/null 2>&1 && dependencies="$dependencies pacman-contrib"
which btrfs >/dev/null 2>&1 && ! which snapper >/dev/null 2>&1 && dependencies="$dependencies snapper"
! which yaycache >/dev/null 2>&1 && dependencies="$dependencies yaycache"
[ ! "X$dependencies" = 'X' ] &&
if ! yay -S --needed --noconfirm $dependencies; then
if yay -Syu; then
sudo yay -S --noconfirm git
else
echo -e '\nUnable to fetch package list. Aborting ...' >&2
exit 1
fi
fi
[ ! -e /usr/local/bin/vim ] && sudo ln -s /usr/bin/nvim /usr/local/bin/vim
# ---------------- Display updates beforehand ----------------
@@ -40,7 +70,6 @@ done
# ---------------- Backup system ----------------
if which btrfs >/dev/null 2>&1; then
yay -S --needed --noconfirm snapper
[ ! -f /etc/snapper/configs/root ] && sudo snapper -c root create-config /
[ ! $(sudo awk -F '"' '/NUMBER_LIMIT=/ {print $2}' /etc/snapper/configs/root) -eq $BACKUP_LIMIT ] && sudo sed -i.bak "s/\(NUMBER_LIMIT=\"\).*\"/\1$BACKUP_LIMIT\"/" /etc/snapper/configs/root