Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

Commit

Permalink
Modify update script to utilize Updates 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Savidude authored and VimukthiPerera committed May 5, 2021
1 parent 5de3972 commit 53c5124
Showing 1 changed file with 46 additions and 37 deletions.
83 changes: 46 additions & 37 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 <profile_name>" 1>&2; exit 1; }

Expand All @@ -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)
Expand All @@ -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")
;;
*)
Expand All @@ -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 ]]
Expand All @@ -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
Expand All @@ -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

Expand All @@ -156,41 +165,41 @@ 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}
exit ${update_status}
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`
Expand Down

0 comments on commit 53c5124

Please sign in to comment.