Add local variables

This commit is contained in:
chonghe
2023-10-03 22:02:23 +08:00
committed by Tan Chee Keong
parent 1651f9871a
commit 404961b74f

View File

@@ -48,62 +48,49 @@ write_to_file "$vc_cli" "$vc" "Validator Client"
write_to_file "$am_cli" "$am" "Account Manager" write_to_file "$am_cli" "$am" "Account Manager"
write_to_file "$vm_cli" "$vm" "Validator Manager" write_to_file "$vm_cli" "$vm" "Validator Manager"
#input 1 = $1 = old files; input 2 = $2 = new files #input 1 = $1 = files; input 2 = $2 = new files
old_files=(./book/src/help_general.md ./book/src/help_bn.md ./book/src/help_vc.md ./book/src/help_am.md ./book/src/help_vm.md) files=(./book/src/help_general.md ./book/src/help_bn.md ./book/src/help_vc.md ./book/src/help_am.md ./book/src/help_vm.md)
new_files=($general $bn $vc $am $vm) new_files=($general $bn $vc $am $vm)
# store for troubleshooting purpose
exist=()
update=()
diff=()
# function to check # function to check
check() { check() {
if [[ -f $1 ]]; then # check for existence of file local file="$1"
diff=$(diff $1 $2) local new_file="$2"
diff+=($diff)
exist+=(false) if [[ -f $file ]]; then # check for existence of file
diff=$(diff $file $new_file)
else else
cp $2 ./book/src cp $new_file $file
changes=true changes=true
exist+=(true) echo "$file is not found, it has just been created"
echo "$1 is not found, it has just been created"
fi fi
if [[ -z $diff ]]; then # check for difference if [[ -z $diff ]]; then # check for difference
update+=(false)
return 1 # exit a function (i.e., do nothing) return 1 # exit a function (i.e., do nothing)
else else
cp $2 $1 cp $new_file $file
changes=true changes=true
update+=(true) echo "$file has been updated"
echo "$1 has been updated"
fi fi
} }
# define changes as false # define changes as false
changes=false changes=false
# call check function to check for each help file # call check function to check for each help file
check ${old_files[0]} ${new_files[0]} check ${files[0]} ${new_files[0]}
check ${old_files[1]} ${new_files[1]} check ${files[1]} ${new_files[1]}
check ${old_files[2]} ${new_files[2]} check ${files[2]} ${new_files[2]}
check ${old_files[3]} ${new_files[3]} check ${files[3]} ${new_files[3]}
check ${old_files[4]} ${new_files[4]} check ${files[4]} ${new_files[4]}
# remove help files # remove help files
rm -f help_general.md help_bn.md help_vc.md help_am.md help_vm.md rm -f help_general.md help_bn.md help_vc.md help_am.md help_vm.md
# used for troubleshooting to show status
echo "exist = ${exist[@]}"
echo "update = ${update[@]}"
echo "difference = ${diff[@]}"
# only exit at the very end # only exit at the very end
if [[ $changes == true ]]; then if [[ $changes == true ]]; then
echo "CLI parameters are not up to date. Run \"make cli\" to update, then commit the changes" echo "CLI parameters were not up to date. Run \"make cli\" to update, then commit the changes"
exit 1 exit 1
else else
echo "CLI parameters are up to date." echo "CLI parameters are up to date."
exit 0 exit 0
fi fi