From 53c5124adbcd001c14b194079a7db3a64dc2200b Mon Sep 17 00:00:00 2001 From: Savidude Date: Wed, 5 May 2021 14:46:49 +0530 Subject: [PATCH] Modify update script to utilize Updates 2.0 --- scripts/update.sh | 83 ++++++++++++++++++++++++++--------------------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/scripts/update.sh b/scripts/update.sh index 62aa7fe..f569737 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -21,9 +21,9 @@ set -e -# Build artifacts and is_analytics_versions -: ${is_version:="5.10.0"} -: ${packs_dir:=$(pwd)/../files/packs/} +# Build artifacts and versions +: ${version:="5.10.0"} +: ${packs_dir:=$(pwd)/../files/packs} usage() { echo "Usage: $0 -p " 1>&2; exit 1; } @@ -49,6 +49,22 @@ update_pack() { rm -rf ${1} } +print_conflicts() { + conflict_files=$(sed -n '/^Modified/p' ${updates_dir}/output.txt | sed -e 's/.*Conflicts: \[\(.*\)].*/\1/' ) + + if [[ ! -z "$conflict_files" ]] + then + IFS=' ' + read -a strarr <<< "$conflict_files" + for filepath in "${strarr[@]}"; + do + echo ${filepath} + done + + echo "Conflicts are found in the above file(s). Please review the above file(s), resolve conflicts, and save with .final extension. Then re-run the update script." + fi +} + while getopts ":p:" o; do case "${o}" in p) @@ -68,7 +84,7 @@ fi # Set variables relevant to each profile case "${profile}" in is) - pack="wso2is-"${is_version} + pack="wso2is-"${version} updated_roles=("is") ;; *) @@ -90,7 +106,7 @@ fi # Getting update status # 0 - first/last update successful # 1 - Error occurred in last update -# 2 - In-place has been updated +# 2 - Update tool has been updated # 3 - conflicts encountered in last update status=0 if [[ -f ${updates_dir}/status ]] @@ -99,31 +115,24 @@ then fi cd ${packs_dir} - -# The pack should not be unzipped if a conflict is being resolved if [[ ${status} -ne 3 ]] -then + then unzip_pack ${pack} fi -if [[ ! -f ${carbon_home}/bin/update_linux ]] -then - echo "Update executable not found." - rm -rf ${packs_dir}/${pack} - exit 1 -fi - # Move into binaries directory cd ${carbon_home}/bin -# Run in-place update +# Run update +echo "Running update tool. This may take up to 5 minutes" if [[ ${status} -eq 0 ]] || [[ ${status} -eq 1 ]] || [[ ${status} -eq 2 ]] then - ./update_linux --verbose 2>&1 | tee ${updates_dir}/output.txt + ./wso2update_linux --template "Modified: {{.Modified}}, Conflicts: {{.Conflicts}}" 2>&1 | tee ${updates_dir}/output.txt update_status=${PIPESTATUS[0]} elif [[ ${status} -eq 3 ]] then - ./update_linux --verbose --continue 2>&1 | tee ${updates_dir}/output.txt + echo "Resolving conflicts" + ./wso2update_linux --continue --template "Modified: {{.Modified}}, Conflicts: {{.Conflicts}}" 2>&1 | tee ${updates_dir}/output.txt update_status=${PIPESTATUS[0]} # Handle user running update script without resolving conflicts @@ -142,8 +151,8 @@ fi # Handle the In-place tool being updated if [[ ${update_status} -eq 2 ]] then - echo "In-place tool has been updated. Running update again." - ./update_linux --verbose 2>&1 | tee ${updates_dir}/output.txt + echo "Update tool has been updated. Running update again." + ./wso2update_linux --template "Modified: {{.Modified}}, Conflicts: {{.Conflicts}}" 2>&1 | tee ${updates_dir}/output.txt update_status=${PIPESTATUS[0]} fi @@ -156,7 +165,9 @@ then update_pack ${pack} elif [[ ${update_status} -eq 3 ]] then + echo "" echo "Conflicts encountered. Please resolve conflicts in ${packs_dir}/${pack} and run the update script again." + print_conflicts else echo "Update error occurred. Stopped with exit code ${update_status}" rm -rf ${packs_dir}/${pack} @@ -164,33 +175,31 @@ else fi # Get list of merged files -if [[ ${update_status} -eq 0 ]] # If update is successful -then - sed -n '/Merge successful for the following files./,/Successfully completed merging files/p' ${updates_dir}/output.txt > ${updates_dir}/merged_files.txt -elif [[ ${update_status} -eq 3 ]] # If conflicts were encountered during update +if [[ ${update_status} -ne 1 ]] # If update is successful then - sed -n '/Merge successful for the following files./,/Merging/p' ${updates_dir}/output.txt > ${updates_dir}/merged_files.txt + modified_files=$(sed -n '/^Modified/p' ${updates_dir}/output.txt | sed -e 's/.*Modified: \[\(.*\)], Conflicts.*/\1/') fi -if [[ -s ${updates_dir}/merged_files.txt ]] +if [[ ! -z "$modified_files" ]] then - sed -i '1d' ${updates_dir}/merged_files.txt # Remove first line from file - sed -i '$ d' ${updates_dir}/merged_files.txt # Remove last line from file - - while read -r line; do +# Get the list of modified files + IFS=' ' + read -a strarr <<< "$modified_files" + for line in "${strarr[@]}"; + do filepath=${line##*${pack}/} for role in "${updated_roles[@]}" do - template_file=${packs_dir}/../../roles/${role}/templates/carbon-home/${filepath}.j2 - if [[ -f ${template_file} ]] - then - updated_templates+=(${template_file##*${packs_dir}/../../}) - fi + template_file=${packs_dir}/../../roles/${role}/templates/carbon-home/${filepath}.j2 + if [[ -f ${template_file} ]] + then + updated_templates+=(${template_file##*${packs_dir}/../../}) + fi done - done < ${updates_dir}/merged_files.txt + done - # Display template files to be changed +# Display template files to be changed if [[ -n ${updated_templates} ]] then DATE=`date +%Y-%m-%d`