From c00ed7c181f807a67f5508bac4413505b43aecf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Fri, 28 Aug 2026 15:45:55 -0300 Subject: [PATCH] feat(postscripts): require package utility loading --- xCAT/postscripts/ospkgs | 16 ++++++++++++++++ xCAT/postscripts/otherpkgs | 17 +++++++++++++++++ xCAT/postscripts/xcatpkgutils-loader.sh | 24 ++++++++++++++++++++++++ xCAT/postscripts/xcatpkgutils.sh | 7 +++++++ 4 files changed, 64 insertions(+) create mode 100755 xCAT/postscripts/xcatpkgutils-loader.sh create mode 100755 xCAT/postscripts/xcatpkgutils.sh 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