From 4317b5ec75fab75d0befcde0fead5c38a1376962 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Sun, 30 Aug 2026 19:19:20 -0300 Subject: [PATCH] refactor(postscripts): share RPM package manager discovery MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Vinícius Ferrão <2031761+viniciusferrao@users.noreply.github.com> --- xCAT/postscripts/ospkgs | 6 +----- xCAT/postscripts/otherpkgs | 6 +----- xCAT/postscripts/xcatpkgutils.sh | 12 ++++++++++++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/xCAT/postscripts/ospkgs b/xCAT/postscripts/ospkgs index e50b3c4da..3d164d3f3 100755 --- a/xCAT/postscripts/ospkgs +++ b/xCAT/postscripts/ospkgs @@ -910,11 +910,7 @@ elif ( pmatch "$OSVER" "ubuntu*" ); then fi else #check if yum or dnf is installed - if [ -x /usr/bin/dnf ]; then - yumcmd="dnf" - elif [ -x /usr/bin/yum ]; then - yumcmd="yum" - else + if ! yumcmd=$(xcat_find_rpm_package_manager); then echo "Please install yum or dnf on $NODE." exit 1; fi diff --git a/xCAT/postscripts/otherpkgs b/xCAT/postscripts/otherpkgs index 6dbc9707a..eedbc09f2 100755 --- a/xCAT/postscripts/otherpkgs +++ b/xCAT/postscripts/otherpkgs @@ -509,12 +509,8 @@ else result=`rpm --version 2>/dev/null` if [ $? -eq 0 ]; then hasrpm=1 - if [ -x /usr/bin/dnf ]; then + if yumcmd=$(xcat_find_rpm_package_manager); then hasyum=1 - yumcmd="dnf" - elif [ -x /usr/bin/yum ]; then - hasyum=1 - yumcmd="yum" else result=`rpm -q zypper` if [ "$?" = "0" ]; then diff --git a/xCAT/postscripts/xcatpkgutils.sh b/xCAT/postscripts/xcatpkgutils.sh index 8c91b5239..7b3798b9f 100755 --- a/xCAT/postscripts/xcatpkgutils.sh +++ b/xCAT/postscripts/xcatpkgutils.sh @@ -2,6 +2,18 @@ # EPL license http://www.eclipse.org/legal/epl-v10.html # Shared POSIX shell helpers for the ospkgs and otherpkgs postscripts. + +xcat_find_rpm_package_manager() +{ + if [ -x "${1:-/usr/bin}/dnf" ]; then + printf '%s\n' dnf + elif [ -x "${1:-/usr/bin}/yum" ]; then + printf '%s\n' yum + else + return 1 + fi +} + # Keep the marker assignment last so callers know the whole library loaded. # shellcheck disable=SC2034 XCATPKGUTILS_LOADED=1