From d56da2bc4b3fc69c037d67629c7f830eb357656f Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 4 Sep 2024 16:04:55 +0200 Subject: [PATCH] dnf, yum: set global options before command The `-y` and `-q` options are global options, and can be set before the command that's run. There's some ambiguity in the USAGE output of different versions (`yum`, `dnf`, `dnf5`) yum always outputs the same usage, but shows that options go _before_ the command; yum --help Usage: yum [options] COMMAND yum install --help Usage: yum [options] COMMAND dnf (dnf4) is ambiguous; when showing usage for `install` it shows the options to be set _after_ the command; dnf install --help usage: dnf install [-c [config file]] [-q] [-v] [--version] .... but the global `--help` shows them to be before the command; dnf --help usage: dnf [options] COMMAND General DNF options: ... -q, --quiet quiet operation -v, --verbose verbose operation ,,, --setopt SETOPTS set arbitrary config and repo options dnf5 is more explicit about global vs per-command options; dnf --help Usage: dnf5 [GLOBAL OPTIONS] ... dnf install --help Usage: dnf5 [GLOBAL OPTIONS] install [OPTIONS] [ARGUMENTS] Testing shows that older versions (`dnf4` and `yum`) handle both fine, and because `dnf5` (per the above) prefers global options to go before the command, we can use that convention in this script. Signed-off-by: Sebastiaan van Stijn --- install.sh | 8 ++++---- rootless-install.sh | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/install.sh b/install.sh index 3a0a94d..2fd98f7 100755 --- a/install.sh +++ b/install.sh @@ -554,14 +554,14 @@ do_install() { centos|fedora|rhel) if command_exists dnf; then pkg_manager="dnf" - pkg_manager_flags="--best" + pkg_manager_flags="-y -q --best" config_manager="dnf config-manager" enable_channel_flag="--set-enabled" disable_channel_flag="--set-disabled" pre_reqs="dnf-plugins-core" else pkg_manager="yum" - pkg_manager_flags="" + pkg_manager_flags="-y -q" config_manager="yum-config-manager" enable_channel_flag="--enable" disable_channel_flag="--disable" @@ -578,7 +578,7 @@ do_install() { if ! is_dry_run; then set -x fi - $sh_c "$pkg_manager $pkg_manager_flags install -y -q $pre_reqs" + $sh_c "$pkg_manager $pkg_manager_flags install $pre_reqs" $sh_c "$config_manager --add-repo $repo_file_url" if [ "$CHANNEL" != "stable" ]; then @@ -631,7 +631,7 @@ do_install() { if ! is_dry_run; then set -x fi - $sh_c "$pkg_manager $pkg_manager_flags install -y -q $pkgs" + $sh_c "$pkg_manager $pkg_manager_flags install $pkgs" ) echo_docker_as_nonroot exit 0 diff --git a/rootless-install.sh b/rootless-install.sh index cd080e2..797df61 100755 --- a/rootless-install.sh +++ b/rootless-install.sh @@ -130,10 +130,10 @@ checks() { if command -v apt-get >/dev/null 2>&1; then INSTRUCTIONS="apt-get install -y uidmap" elif command -v dnf >/dev/null 2>&1; then - INSTRUCTIONS="dnf install -y shadow-utils" + INSTRUCTIONS="dnf -y install shadow-utils" elif command -v yum >/dev/null 2>&1; then INSTRUCTIONS="curl -o /etc/yum.repos.d/vbatts-shadow-utils-newxidmap-epel-7.repo https://copr.fedorainfracloud.org/coprs/vbatts/shadow-utils-newxidmap/repo/epel-7/vbatts-shadow-utils-newxidmap-epel-7.repo -yum install -y shadow-utils46-newxidmap" +yum -y install shadow-utils46-newxidmap" else echo "newuidmap binary not found. Please install with a package manager." exit 1 @@ -147,7 +147,7 @@ yum install -y shadow-utils46-newxidmap" apt-get install -y iptables" elif command -v dnf >/dev/null 2>&1; then INSTRUCTIONS="${INSTRUCTIONS} -dnf install -y iptables" +dnf -y install iptables" else echo "iptables binary not found. Please install with a package manager." exit 1