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 jsdjayanga committed Jun 7, 2021
1 parent ce78018 commit 64ae0a7
Showing 1 changed file with 45 additions and 28 deletions.
73 changes: 45 additions & 28 deletions scripts/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 Down Expand Up @@ -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}
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 @@ -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
Expand All @@ -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

Expand All @@ -158,41 +175,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
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`
Expand Down

0 comments on commit 64ae0a7

Please sign in to comment.