Skip to content

Commit d857138

Browse files
committed
feat(scripts): update check_and_install_packages to always update packages
The check_and_install_packages function has been updated to always run `pacman -Syu` on the passed packages. This ensures that the packages are not only installed, but also updated to their latest versions. The check with `pacman -Q` has been removed.
1 parent 77dd5be commit d857138

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

scripts/archlinux_util.sh

+10-18
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ check_pacman() {
5858
echo_msg "OK. Pacman is installed."
5959
}
6060

61+
# Initialize pacman keyring
6162
init_pacman_keyring() {
6263
if [ "$KEYRING_CHECKED" = false ]; then
6364
echo_msg "Initializing pacman keyring (current count: $(pacman-key --list-keys | wc -l))..."
@@ -92,27 +93,18 @@ adjust_dir_permissions() {
9293
fi
9394
}
9495

95-
# Checks if packages are installed and if not, adds them to a list
96+
# Check and install packages
9697
check_and_install_packages() {
97-
echo_msg "Checking if packages (${*}) are installed..."
98-
pkgs_to_install=""
99-
for pkg in "$@"; do
100-
if ! pacman -Q "$pkg" > /dev/null 2>&1; then
101-
pkgs_to_install="$pkgs_to_install $pkg"
102-
fi
103-
done
98+
echo_msg "Checking and updating packages (${*})..."
10499

105-
if [ -n "$pkgs_to_install" ]; then
106-
adjust_dir_permissions
107-
init_pacman_keyring
100+
adjust_dir_permissions
101+
init_pacman_keyring
108102

109-
echo_msg "Installing packages ($pkgs_to_install)..."
110-
# shellcheck disable=SC2086
111-
if ! pacman -Syu --needed --noconfirm $pkgs_to_install; then
112-
echo "Failed to install packages. If you're getting an error about a missing secret key, you might need to manually import the key. Refer to the Arch Linux wiki for more information: https://wiki.archlinux.org/title/Pacman/Package_signing#Adding_unofficial_keys"
113-
exit 1
114-
fi
103+
echo_msg "Installing and updating packages ($*)..."
104+
if ! pacman -Syu --needed --noconfirm "$@"; then
105+
echo "Failed to install or update packages. If you're getting an error about a missing secret key, you might need to manually import the key. Refer to the Arch Linux wiki for more information: https://wiki.archlinux.org/title/Pacman/Package_signing#Adding_unofficial_keys"
106+
exit 1
115107
fi
116108

117-
echo_msg "OK. All packages (${*}) installed or already present."
109+
echo_msg "OK. All packages (${*}) installed or updated."
118110
}

0 commit comments

Comments
 (0)