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