From 7c884cfe2fc1eb4bd056ad8d9ef44003c2599f2e Mon Sep 17 00:00:00 2001 From: Daniel Hilst <392820+dhilst@users.noreply.github.com> Date: Mon, 14 Sep 2026 15:43:40 -0300 Subject: [PATCH] refactor(xcatdsklspost): put the /xcatpost cleanup in one routine The decision to remove the postscripts from /xcatpost sits inline in the tail of xcatdsklspost, where nothing can drive it without a management node and a real download. A test of that decision has to grep the source of the script instead. Move the decision into append_xcatpost_cleanup, above the XCATDSKLSPOST_SOURCE_ONLY guard, so a test can source the script and call the routine against a scratch directory. The routine takes the mypostscript path and the xcatpost directory, and emits the same text as before for every value of site.cleanupxcatpost. Signed-off-by: Daniel Hilst <392820+dhilst@users.noreply.github.com> --- xCAT/postscripts/xcatdsklspost | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/xCAT/postscripts/xcatdsklspost b/xCAT/postscripts/xcatdsklspost index 6f7dcc63a..5b8774f79 100755 --- a/xCAT/postscripts/xcatdsklspost +++ b/xCAT/postscripts/xcatdsklspost @@ -224,6 +224,29 @@ parsehttpserver () fi } +##################################################### +# Append to the generated mypostscript the /xcatpost cleanup the site table asks for. +# +# The append happens on every path this script serves: node deployment, and each +# updatenode, moncfg or reboot run. +# +# $1 - path of the generated mypostscript +# $2 - the xcatpost directory to remove the postscripts from +##################################################### +append_xcatpost_cleanup() +{ + local mypostscript=$1 + local postdir=$2 + local cleanupxcatpost + + cleanupxcatpost=`grep CLEANUPXCATPOST= "$mypostscript" |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` + if [[ "$cleanupxcatpost" =~ ^(1|yes|y)$ ]]; then + echo "cd /" >> "$mypostscript" + # /xcatpost might be read-only for statelite nodes + echo "rm -rf $postdir/*" >> "$mypostscript" + fi +} + if [ "$XCATDSKLSPOST_SOURCE_ONLY" = "1" ]; then return 0 2>/dev/null || exit 0 fi @@ -1086,12 +1109,7 @@ fi DHCP_TMP=`sed 's/\(DHCPINTERFACES=\)\(.*\)$/\1"\2"/' /$xcatpost/mypostscript` echo "$DHCP_TMP" > /$xcatpost/mypostscript -CLEANUPXCATPOST=`grep CLEANUPXCATPOST= /$xcatpost/mypostscript |awk -F = '{print $2}' | tr -d \'\" | tr A-Z a-z` -if [[ "$CLEANUPXCATPOST" =~ ^(1|yes|y)$ ]]; then - echo "cd /" >> /$xcatpost/mypostscript - # /xcatpost might be read-only for statelite nodes - echo "rm -rf /$xcatpost/*" >> /$xcatpost/mypostscript -fi +append_xcatpost_cleanup /$xcatpost/mypostscript /$xcatpost