From 587e5e5ed7e5842b6bef3de0c0a2d4d186794d93 Mon Sep 17 00:00:00 2001 From: Roger Yao Date: Mon, 23 Sep 2024 10:52:59 +0800 Subject: [PATCH] Generate longhorn.yaml with version replacement longhorn/longhorn#9512 Signed-off-by: Roger Yao --- test_tools/update_LH_ver_with_download.sh | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 test_tools/update_LH_ver_with_download.sh diff --git a/test_tools/update_LH_ver_with_download.sh b/test_tools/update_LH_ver_with_download.sh new file mode 100755 index 0000000000..e435975c28 --- /dev/null +++ b/test_tools/update_LH_ver_with_download.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +# Check if the correct number of arguments are provided +if [ "$#" -ne 3 ]; then + echo "" + echo "Usage: $0 " + echo "" + echo "Arguments:" + echo " The version of Longhorn images to be replaced (e.g., v1.6.3, v1.7.1)." + echo " The new version of Longhorn images to use (e.g., v1.6.3-dev-20240922, v1.7.x-head)." + echo " The branch or tag from which to download the Longhorn YAML file." + echo "" + echo " Examples:" + echo "" + echo " # For downloading longhorn.yaml from the v1.6.x branch" + echo " $0 v1.6.3 v1.6.3-dev-20240922 v1.6.x" + echo "" + echo " # For downloading longhorn.yaml from the v1.7.x branch" + echo " $0 v1.7.1 v1.7.x-head v1.7.x" + echo "" + echo " # For downloading longhorn.yaml from the master branch" + echo " $0 master-head v1.8.0-dev-20240922 master" + echo "" + exit 1 +fi + +# Capture the input arguments +OLD_VERSION=$1 +NEW_VERSION=$2 +LONGHORN_VERSION=$3 + +# Define the file path for the downloaded longhorn.yaml +FILE_PATH="longhorn.yaml" + +# Download the specified version of the longhorn.yaml file +wget -O "$FILE_PATH" "https://raw.githubusercontent.com/longhorn/longhorn/${LONGHORN_VERSION}/deploy/longhorn.yaml" + +# Check if the file was downloaded successfully +if [ $? -ne 0 ]; then + echo "Error downloading longhorn.yaml. Please check the Longhorn version." + exit 1 +fi + +# Define the list of Longhorn image names +IMAGES=( + "longhornio/longhorn-ui" + "longhornio/longhorn-manager" + "longhornio/longhorn-engine" + "longhornio/longhorn-instance-manager" + "longhornio/longhorn-share-manager" + "longhornio/backing-image-manager" +) + +# Loop through each image and perform the find/replace +for IMAGE in "${IMAGES[@]}"; do + # Use sed to replace old version with new version + sed -i "s|${IMAGE}:${OLD_VERSION}|${IMAGE}:${NEW_VERSION}|g" "$FILE_PATH" +done + +# Define the new filename based on the new version +NEW_FILE_PATH="longhorn-${NEW_VERSION}.yaml" + +# Move the modified file to the new file name +mv "$FILE_PATH" "$NEW_FILE_PATH" + +echo "Replacement complete. Updated file saved as $NEW_FILE_PATH."