diff --git a/xCAT/postscripts/ospkgs b/xCAT/postscripts/ospkgs index a9cc38bfa..e50b3c4da 100755 --- a/xCAT/postscripts/ospkgs +++ b/xCAT/postscripts/ospkgs @@ -25,6 +25,22 @@ #set -x +XCATPKGUTILS_LOADER="$(dirname "$0")/xcatpkgutils-loader.sh" +if [ ! -r "$XCATPKGUTILS_LOADER" ]; then + printf 'Error: package utility loader is not readable: %s\n' "$XCATPKGUTILS_LOADER" >&2 + unset XCATPKGUTILS_LOADER + exit 1 +fi +# shellcheck source-path=SCRIPTDIR +# shellcheck source=xcatpkgutils-loader.sh +# shellcheck disable=SC1091 +if ! . "$XCATPKGUTILS_LOADER"; then + printf 'Error: package utilities could not be loaded through: %s\n' "$XCATPKGUTILS_LOADER" >&2 + unset XCATPKGUTILS_LOADER + exit 1 +fi +unset XCATPKGUTILS_LOADER + if [ -n "$LOGLABEL" ]; then log_label=$LOGLABEL else diff --git a/xCAT/postscripts/otherpkgs b/xCAT/postscripts/otherpkgs index 515278b91..6dbc9707a 100755 --- a/xCAT/postscripts/otherpkgs +++ b/xCAT/postscripts/otherpkgs @@ -24,6 +24,23 @@ #enable debug #set -x + +XCATPKGUTILS_LOADER="$(dirname "$0")/xcatpkgutils-loader.sh" +if [ ! -r "$XCATPKGUTILS_LOADER" ]; then + printf 'Error: package utility loader is not readable: %s\n' "$XCATPKGUTILS_LOADER" >&2 + unset XCATPKGUTILS_LOADER + exit 1 +fi +# shellcheck source-path=SCRIPTDIR +# shellcheck source=xcatpkgutils-loader.sh +# shellcheck disable=SC1091 +if ! . "$XCATPKGUTILS_LOADER"; then + printf 'Error: package utilities could not be loaded through: %s\n' "$XCATPKGUTILS_LOADER" >&2 + unset XCATPKGUTILS_LOADER + exit 1 +fi +unset XCATPKGUTILS_LOADER + if [ -n "$LOGLABEL" ]; then log_label=$LOGLABEL else diff --git a/xCAT/postscripts/xcatpkgutils-loader.sh b/xCAT/postscripts/xcatpkgutils-loader.sh new file mode 100755 index 000000000..8e131885d --- /dev/null +++ b/xCAT/postscripts/xcatpkgutils-loader.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# EPL license http://www.eclipse.org/legal/epl-v10.html + +xcatpkgutils="$(dirname "$0")/xcatpkgutils.sh" +if [ ! -r "$xcatpkgutils" ]; then + printf 'Error: package utility library is not readable: %s\n' "$xcatpkgutils" >&2 + unset xcatpkgutils + return 1 +fi + +unset XCATPKGUTILS_LOADED +# shellcheck source-path=SCRIPTDIR +# shellcheck source=xcatpkgutils.sh +if ! . "$xcatpkgutils"; then + printf 'Error: package utility library could not be loaded: %s\n' "$xcatpkgutils" >&2 + unset XCATPKGUTILS_LOADED xcatpkgutils + return 1 +fi +if [ "${XCATPKGUTILS_LOADED:-}" != "1" ]; then + printf 'Error: package utility library did not finish loading: %s\n' "$xcatpkgutils" >&2 + unset XCATPKGUTILS_LOADED xcatpkgutils + return 1 +fi +unset XCATPKGUTILS_LOADED xcatpkgutils diff --git a/xCAT/postscripts/xcatpkgutils.sh b/xCAT/postscripts/xcatpkgutils.sh new file mode 100755 index 000000000..8c91b5239 --- /dev/null +++ b/xCAT/postscripts/xcatpkgutils.sh @@ -0,0 +1,7 @@ +#!/bin/sh +# EPL license http://www.eclipse.org/legal/epl-v10.html + +# Shared POSIX shell helpers for the ospkgs and otherpkgs postscripts. +# Keep the marker assignment last so callers know the whole library loaded. +# shellcheck disable=SC2034 +XCATPKGUTILS_LOADED=1