From 7aaf4d57d8e028f83271f5c547845ede95d48be3 Mon Sep 17 00:00:00 2001 From: Luke Short Date: Wed, 28 Jun 2023 11:38:24 -0600 Subject: [PATCH 1/2] init: Avoid re-installing Pacman packages * Add the "--needed" argument to Pacman to only install new packages. * Pacman cache is also only updated once instead of during every command. These changes makes entering an Arch Linux container much faster. Resolves #826 Signed-off-by: Luke Short --- distrobox-init | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/distrobox-init b/distrobox-init index 2941cd7a7d..59bcea9946 100755 --- a/distrobox-init +++ b/distrobox-init @@ -617,9 +617,12 @@ if [ "${upgrade}" -ne 0 ] || ! command -v find || ! command -v mount || ! comman fi elif command -v pacman; then + # Update the package repository cache exactly once before installing packages. + pacman -S -y -y + # If we need to upgrade, do it and exit, no further action required. if [ "${upgrade}" -ne 0 ]; then - pacman -Syyu --noconfirm + pacman -S -u --noconfirm exit fi # In archlinux official images, pacman is configured to ignore locale and docs @@ -631,8 +634,8 @@ if [ "${upgrade}" -ne 0 ] || ! command -v find || ! command -v mount || ! comman # Check if shell_pkg is available in distro's repo. If not we # fall back to bash, and we set the SHELL variable to bash so # that it is set up correctly for the user. - pacman --noconfirm -Syyu - if ! pacman -Sy --noconfirm "${shell_pkg}"; then + pacman -S -u --noconfirm + if ! pacman -S --needed --noconfirm "${shell_pkg}"; then shell_pkg="bash" fi deps=" @@ -665,12 +668,12 @@ if [ "${upgrade}" -ne 0 ] || ! command -v find || ! command -v mount || ! comman fi done # shellcheck disable=SC2086 - pacman -Sy --noconfirm ${install_pkg} + pacman -S --needed --noconfirm ${install_pkg} # Install additional packages passed at distrbox-create time if [ -n "${container_additional_packages}" ]; then # shellcheck disable=SC2086 - pacman -Sy --noconfirm ${container_additional_packages} + pacman -S --needed --noconfirm ${container_additional_packages} fi elif command -v slackpkg; then From 6607d330de9d73a47dfd87bfa6384a411f93a0aa Mon Sep 17 00:00:00 2001 From: Luke Short Date: Wed, 28 Jun 2023 11:42:25 -0600 Subject: [PATCH 2/2] init: do not force Pacman upgrades Upgrades should only run when the "--upgrade" argument is passsed. Related #826 Signed-off-by: Luke Short --- distrobox-init | 1 - 1 file changed, 1 deletion(-) diff --git a/distrobox-init b/distrobox-init index 59bcea9946..d6d90368b0 100755 --- a/distrobox-init +++ b/distrobox-init @@ -634,7 +634,6 @@ if [ "${upgrade}" -ne 0 ] || ! command -v find || ! command -v mount || ! comman # Check if shell_pkg is available in distro's repo. If not we # fall back to bash, and we set the SHELL variable to bash so # that it is set up correctly for the user. - pacman -S -u --noconfirm if ! pacman -S --needed --noconfirm "${shell_pkg}"; then shell_pkg="bash" fi