Skip to content

Commit d56da2b

Browse files
committed
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] <COMMAND> ... 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 <github@gone.nl>
1 parent 0d6f72e commit d56da2b

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

install.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,14 @@ do_install() {
554554
centos|fedora|rhel)
555555
if command_exists dnf; then
556556
pkg_manager="dnf"
557-
pkg_manager_flags="--best"
557+
pkg_manager_flags="-y -q --best"
558558
config_manager="dnf config-manager"
559559
enable_channel_flag="--set-enabled"
560560
disable_channel_flag="--set-disabled"
561561
pre_reqs="dnf-plugins-core"
562562
else
563563
pkg_manager="yum"
564-
pkg_manager_flags=""
564+
pkg_manager_flags="-y -q"
565565
config_manager="yum-config-manager"
566566
enable_channel_flag="--enable"
567567
disable_channel_flag="--disable"
@@ -578,7 +578,7 @@ do_install() {
578578
if ! is_dry_run; then
579579
set -x
580580
fi
581-
$sh_c "$pkg_manager $pkg_manager_flags install -y -q $pre_reqs"
581+
$sh_c "$pkg_manager $pkg_manager_flags install $pre_reqs"
582582
$sh_c "$config_manager --add-repo $repo_file_url"
583583

584584
if [ "$CHANNEL" != "stable" ]; then
@@ -631,7 +631,7 @@ do_install() {
631631
if ! is_dry_run; then
632632
set -x
633633
fi
634-
$sh_c "$pkg_manager $pkg_manager_flags install -y -q $pkgs"
634+
$sh_c "$pkg_manager $pkg_manager_flags install $pkgs"
635635
)
636636
echo_docker_as_nonroot
637637
exit 0

rootless-install.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ checks() {
130130
if command -v apt-get >/dev/null 2>&1; then
131131
INSTRUCTIONS="apt-get install -y uidmap"
132132
elif command -v dnf >/dev/null 2>&1; then
133-
INSTRUCTIONS="dnf install -y shadow-utils"
133+
INSTRUCTIONS="dnf -y install shadow-utils"
134134
elif command -v yum >/dev/null 2>&1; then
135135
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
136-
yum install -y shadow-utils46-newxidmap"
136+
yum -y install shadow-utils46-newxidmap"
137137
else
138138
echo "newuidmap binary not found. Please install with a package manager."
139139
exit 1
@@ -147,7 +147,7 @@ yum install -y shadow-utils46-newxidmap"
147147
apt-get install -y iptables"
148148
elif command -v dnf >/dev/null 2>&1; then
149149
INSTRUCTIONS="${INSTRUCTIONS}
150-
dnf install -y iptables"
150+
dnf -y install iptables"
151151
else
152152
echo "iptables binary not found. Please install with a package manager."
153153
exit 1

0 commit comments

Comments
 (0)