From c475c8394a033e77134ce40dfa8428d17ea7f3d6 Mon Sep 17 00:00:00 2001 From: Julie Pichon Date: Wed, 8 May 2019 17:17:14 +0100 Subject: [PATCH] yum_update.sh improvements * Use repoquery instead of repoquery directly "repoquery" is part of -utils which may not be installed, in which case no packages would end up updated. * Use the --quiet flag with repoquery This prevents notices such as subscription-related stderr warnings from being added to the output and messing with the sorted order. * Remove the : after else It seems using else without a colon is the bash standard. This gets rid of the following error on RHEL8: "/tmp/yum_update.sh: line 34: else:: command not found" Depends-On: https://review.opendev.org/662317 Change-Id: Id03405d49dc213d018941c44129521cca845e7d6 --- files/yum_update.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/files/yum_update.sh b/files/yum_update.sh index 7495264..15ba25e 100755 --- a/files/yum_update.sh +++ b/files/yum_update.sh @@ -2,10 +2,12 @@ set -eou pipefail +PKG="$(command -v dnf || command -v yum)" + packages_for_update= -if [ -n "$1" ] && command -v repoquery >/dev/null 2>&1; then +if [ -n "$1" ] && $PKG repoquery >/dev/null 2>&1; then installed_versions=$(rpm -qa --qf "%{NAME} = %{VERSION}-%{RELEASE}\n" | sort) - available_versions=$(repoquery --provides --disablerepo='*' --enablerepo=$1 -a | sort) + available_versions=$($PKG repoquery --quiet --provides --disablerepo='*' --enablerepo=$1 -a | sort) uptodate_versions=$(comm -12 <(printf "%s\n" "$installed_versions") <(printf "%s\n" "$available_versions")) @@ -22,14 +24,13 @@ if [ -z "$packages_for_update" ]; then exit fi -PKG="$(command -v dnf || command -v yum)" PKG_MGR="$(echo ${PKG:(-3)})" if [ $PKG_MGR == "dnf" ]; then if ! echo $installed | grep -qw dnf-plugins-core; then $PKG install -y dnf-plugins-core fi -else: +else if ! echo $installed | grep -qw yum-plugin-priorities; then $PKG install -y yum-plugin-priorities fi