From 1a698d629fd3a99a63c024bd3db94a3860f360dd Mon Sep 17 00:00:00 2001 From: Tu Dinh Date: Fri, 10 Jan 2025 17:43:52 +0100 Subject: [PATCH 1/5] set_xva_bridge: fix cases where XVA_NAME contains spaces Signed-off-by: Tu Dinh --- scripts/set_xva_bridge.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/set_xva_bridge.sh b/scripts/set_xva_bridge.sh index 4f9eafd23..cf53f46db 100755 --- a/scripts/set_xva_bridge.sh +++ b/scripts/set_xva_bridge.sh @@ -93,7 +93,7 @@ if [ "${OLD_COMPRESSION}" != "Zstandard" ] && [ "${OLD_COMPRESSION}" != "gzip" ] exit 1 fi -PATHFOLDER=$(dirname ${XVA_NAME}) +PATHFOLDER=$(dirname "${XVA_NAME}") TMPFOLDER=$(mktemp -d "${PATHFOLDER}"/xvaXXXX) if [ -f "${XVA_NAME}" ]; then From 9f9c1e25a95c71e50332045417e953e918a5c180 Mon Sep 17 00:00:00 2001 From: Tu Dinh Date: Fri, 10 Jan 2025 17:46:17 +0100 Subject: [PATCH 2/5] set_xva_bridge: get TMP_LIST from original archive ova.xml must come first in the archive order. sort sometimes fails to do this correctly even if LC_ALL is set to "C". Fix this by taking the original file list from tar instead. Signed-off-by: Tu Dinh --- scripts/set_xva_bridge.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/set_xva_bridge.sh b/scripts/set_xva_bridge.sh index cf53f46db..14eb238cc 100755 --- a/scripts/set_xva_bridge.sh +++ b/scripts/set_xva_bridge.sh @@ -96,8 +96,10 @@ fi PATHFOLDER=$(dirname "${XVA_NAME}") TMPFOLDER=$(mktemp -d "${PATHFOLDER}"/xvaXXXX) +# extract and create the file list at the same time +TMP_LIST=$(mktemp "${PATHFOLDER}"/SortedListXXXX.txt) if [ -f "${XVA_NAME}" ]; then - tar -xf $1 -C "${TMPFOLDER}" + tar -xvf "${XVA_NAME}" -C "${TMPFOLDER}" > "${TMP_LIST}" else echo "Error: ${XVA_NAME} not found." exit 1 @@ -120,8 +122,6 @@ mv "${XVA_NAME}" "${XVA_NAME}.save" cd "${TMPFOLDER}" # Create the new XVA -TMP_LIST=$(mktemp /tmp/SortedListXXXX.txt) -find . -print | cut -c3- | sort | grep -v "^Ref:[0-9]\+$" > ${TMP_LIST} sudo tar -cv --${COMPRESS_METHOD} -f ${XVA_NAME} --no-recursion -T ${TMP_LIST} rm -f "${TMP_LIST}" From f2274993fc73d9784478278193536fb39bfc5ef6 Mon Sep 17 00:00:00 2001 From: Tu Dinh Date: Fri, 10 Jan 2025 17:51:28 +0100 Subject: [PATCH 3/5] set_xva_bridge: set owner and permissions in tar command Erase the output archive members' owner and permissions directly through tar command line. Make extracted temp files readable with chmod to avoid using sudo for reading input files. Signed-off-by: Tu Dinh --- scripts/set_xva_bridge.sh | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/scripts/set_xva_bridge.sh b/scripts/set_xva_bridge.sh index 14eb238cc..7f3e97c6f 100755 --- a/scripts/set_xva_bridge.sh +++ b/scripts/set_xva_bridge.sh @@ -105,10 +105,10 @@ else exit 1 fi +chmod -R u+rX "${TMPFOLDER}" + if [ -e "${TMPFOLDER}/ova.xml" ]; then - chmod +rw "${TMPFOLDER}/ova.xml" - sed -i "s/bridge<\/name>[^<]*<\/value><\/member>/bridge<\/name>${BRIDGE_VALUE}<\/value><\/member>/g" ${TMPFOLDER}/ova.xml - chmod -rw "${TMPFOLDER}/ova.xml" + sed -i "s/bridge<\/name>[^<]*<\/value><\/member>/bridge<\/name>${BRIDGE_VALUE}<\/value><\/member>/g" "${TMPFOLDER}/ova.xml" else echo "Error: File ova.xml not found during the sed." exit 1 @@ -118,15 +118,11 @@ fi # save first file mv "${XVA_NAME}" "${XVA_NAME}.save" -# create xva -cd "${TMPFOLDER}" - # Create the new XVA -sudo tar -cv --${COMPRESS_METHOD} -f ${XVA_NAME} --no-recursion -T ${TMP_LIST} +tar -C "${TMPFOLDER}" --${COMPRESS_METHOD} -cf "${XVA_NAME}" --no-recursion -T "${TMP_LIST}" --numeric-owner --owner=:0 --group=:0 --mode=ugo= --mtime=@0 rm -f "${TMP_LIST}" # clean TMPFOLDER -cd .. if [ -d "${TMPFOLDER}" ]; then rm -Rf "${TMPFOLDER}" else From 5b27920e2e11b03b96d3cdbd9b3443b1f11da773 Mon Sep 17 00:00:00 2001 From: Tu Dinh Date: Fri, 10 Jan 2025 17:54:19 +0100 Subject: [PATCH 4/5] set_xva_bridge: use file -b file -b avoids printing filename in file's output, which simplifies filetype parsing a bit. Signed-off-by: Tu Dinh --- scripts/set_xva_bridge.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/set_xva_bridge.sh b/scripts/set_xva_bridge.sh index 7f3e97c6f..9f67161e8 100755 --- a/scripts/set_xva_bridge.sh +++ b/scripts/set_xva_bridge.sh @@ -87,7 +87,7 @@ else fi # we detect the compression method of the xva to uncompress it right -OLD_COMPRESSION=$(file "${XVA_NAME}" | cut -f 2 -d : | cut -f 2 -d " ") +OLD_COMPRESSION=$(file -b "${XVA_NAME}" | cut -f 1 -d " ") if [ "${OLD_COMPRESSION}" != "Zstandard" ] && [ "${OLD_COMPRESSION}" != "gzip" ] && [ "${OLD_COMPRESSION}" != "tar" ]; then echo "Error: unknown compression type detected for ${XVA_NAME}: ${OLD_COMPRESSION}" exit 1 From 7a543e939a34b36f4b8d13848afffcd83189817c Mon Sep 17 00:00:00 2001 From: Tu Dinh Date: Fri, 10 Jan 2025 17:55:54 +0100 Subject: [PATCH 5/5] set_xva_bridge: don't check existing bridge name Bridge name can be checked through get_xva_bridge, no need to spend another pass on the XVA file for this. Signed-off-by: Tu Dinh --- scripts/set_xva_bridge.sh | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/scripts/set_xva_bridge.sh b/scripts/set_xva_bridge.sh index 9f67161e8..6aebe33e2 100755 --- a/scripts/set_xva_bridge.sh +++ b/scripts/set_xva_bridge.sh @@ -12,23 +12,6 @@ usage() echo "----------------------------------------------------------------------------------------" } -# extract and read ova.xml -get_bridge() -{ - TMPFOLD=$(mktemp -d /tmp/xvaXXXX) - tar -xf "${XVA_NAME}" -C "${TMPFOLD}" ova.xml - chmod +r "${TMPFOLD}/ova.xml" - XML_VALUE=$(grep -oE "bridge[^<]*" "${TMPFOLD}/ova.xml") - LENGTH=${#XML_VALUE} - PREFIX_LENGTH=$((${LENGTH}-17)) - NETWORK_VALUE=$(cut -c 1-${PREFIX_LENGTH} <<< ${XML_VALUE}) - echo $(cut -c 35-${#NETWORK_VALUE} <<< ${NETWORK_VALUE}) - - if [ -d "${TMPFOLD}" ]; then - rm -Rf "${TMPFOLD}" - fi -} - # check parameters and prompt the usage if needed if [ -z "${1+set}" ] then @@ -70,22 +53,6 @@ else BRIDGE_VALUE=$3 fi -# we want to know the value of the network bridge. -# then we can decide if we need to change it or not. -BRIDGE_READVALUE=$(get_bridge) - -if [ -z "${BRIDGE_READVALUE}" ] -then - echo "No bridge value detected in the xml file!" - exit 1 -else - if [ "${BRIDGE_READVALUE}" == "${BRIDGE_VALUE}" ] - then - echo "The bridge is already ${BRIDGE_VALUE}. Nothing to do." - exit 0 - fi -fi - # we detect the compression method of the xva to uncompress it right OLD_COMPRESSION=$(file -b "${XVA_NAME}" | cut -f 1 -d " ") if [ "${OLD_COMPRESSION}" != "Zstandard" ] && [ "${OLD_COMPRESSION}" != "gzip" ] && [ "${OLD_COMPRESSION}" != "tar" ]; then