diff --git a/scripts/update.sh b/scripts/update.sh index 53128d4..a9a748d 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -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) @@ -81,7 +97,7 @@ esac carbon_home=${packs_dir}/${pack} # Create updates directory if it doesn't exist -updates_dir=$(pwd)/update_logs/${pack} +updates_dir=${packs_dir}/updates/${pack} if [[ ! -d ${updates_dir} ]] then mkdir -p ${updates_dir} @@ -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 ]] @@ -106,26 +122,27 @@ then unzip_pack ${pack} fi -if [[ ! -f ${carbon_home}/bin/update_linux ]] +if [[ ! -f ${carbon_home}/bin/wso2update_linux ]] then echo "Update executable not found." rm -rf ${packs_dir}/${pack} exit 1 -else - break fi # Move into binaries directory cd ${carbon_home}/bin -# Run in-place update +# Run update tool +echo "Running WSO2 Update tool" if [[ ${status} -eq 0 ]] || [[ ${status} -eq 1 ]] || [[ ${status} -eq 2 ]] then - ./update_linux --verbose 2>&1 | tee ${updates_dir}/output.txt + echo "Validating credentials" + ./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 @@ -141,11 +158,11 @@ else exit 1 fi -# Handle the In-place tool being updated +# Handle the update 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 @@ -158,7 +175,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} @@ -166,33 +185,31 @@ else fi # Get list of merged files -if [[ ${update_status} -eq 0 ]] # If update is successful +if [[ ${update_status} -ne 1 ]] # 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 -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 module in "${updated_modules[@]}" do - template_file=${packs_dir}/../../../${module}/templates/carbon-home/${filepath}.erb - if [[ -f ${template_file} ]] - then - updated_templates+=("modules/"${template_file##*${packs_dir}/../../../}) - fi + template_file=${packs_dir}/../../../${module}/templates/carbon-home/${filepath}.erb + if [[ -f ${template_file} ]] + then + updated_templates+=("modules/"${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`