refactor(SCRIPT): rewrite file update method
This commit is contained in:
parent
f5e553ac21
commit
73d998178c
40
update.sh
40
update.sh
@ -126,51 +126,55 @@ else
|
|||||||
printf "\n%s*** This script has been updated. Please re-run it to load the updated version of this file. ***%s\n\n" "$warn" "$norm"
|
printf "\n%s*** This script has been updated. Please re-run it to load the updated version of this file. ***%s\n\n" "$warn" "$norm"
|
||||||
# overwrite this script with updated script
|
# overwrite this script with updated script
|
||||||
mv -f ./update.sh.tmp "$localScriptName"
|
mv -f ./update.sh.tmp "$localScriptName"
|
||||||
exit 0
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
## update files
|
## update files
|
||||||
set -- dummy $updateFiles
|
while IFS=' ' read -r field1 field2; do
|
||||||
shift
|
printf "\nChecking '%s' for updates... " "$field2"
|
||||||
for file; do
|
updateFilename="$field2"
|
||||||
updateTarget="$file"
|
repoFileChecksum="$field1"
|
||||||
printf "\nChecking '%s' for updates... " "$updateTarget"
|
if [ -f "$updateFilename" ]; then
|
||||||
repoFile=$(grep "$updateTarget" "$checksumFilename" | grep -o '^\S*')
|
localFileChecksum=$(sha256sum "$updateFilename" | grep -o '^\S*')
|
||||||
if [ -f "$file" ]; then
|
|
||||||
localFile=$(sha256sum "$updateTarget" | grep -o '^\S*')
|
|
||||||
else
|
else
|
||||||
localFile=0
|
localFileChecksum=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ "$localFile" = "$repoFile" ]; then
|
# update file if necessary
|
||||||
|
if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then
|
||||||
printf "[AVAILABLE]\n"
|
printf "[AVAILABLE]\n"
|
||||||
updatesAvailable=$((updatesAvailable + 1))
|
updatesAvailable=$((updatesAvailable + 1))
|
||||||
# download update
|
# download update
|
||||||
printf "Downloading updated '%s'... " "$updateTarget"
|
printf "Downloading updated '%s'... " "$updateFilename"
|
||||||
# specify a name here so that wget overwrites the file instead of just appending a number
|
if ! wget --quiet --tries=3 --timeout=10 -O "$updateFilename.tmp" "${server}${updateFilename}"; then
|
||||||
if ! wget --quiet --tries=3 --timeout=10 -O "$updateTarget" "${server}${updateTarget}"; then
|
|
||||||
errNotify
|
errNotify
|
||||||
downloadFailed=$((downloadFailed + 1))
|
downloadFailed=$((downloadFailed + 1))
|
||||||
|
# delete failed download file as necessary
|
||||||
|
rm -f "$updateFilename.tmp" 2>&1
|
||||||
else
|
else
|
||||||
okNotify
|
okNotify
|
||||||
downloadSuccess=$((downloadSuccess + 1))
|
downloadSuccess=$((downloadSuccess + 1))
|
||||||
# verify download
|
# verify download
|
||||||
printf "Verifying '%s'... " "$updateTarget"
|
printf "Verifying '%s'... " "$updateFilename"
|
||||||
localFile=$(sha256sum "$updateTarget" | grep -o '^\S*')
|
localFileChecksum=$(sha256sum "$updateFilename.tmp" | grep -o '^\S*')
|
||||||
if ! [ "$localFile" = "$repoFile" ]; then
|
if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then
|
||||||
errNotify
|
errNotify
|
||||||
updateFailed=$((updateFailed + 1))
|
updateFailed=$((updateFailed + 1))
|
||||||
|
# delete corrupted download file as necessary
|
||||||
|
rm -f "$updateFilename.tmp" 2>&1
|
||||||
else
|
else
|
||||||
okNotify
|
okNotify
|
||||||
updateSuccess=$((updateSuccess + 1))
|
updateSuccess=$((updateSuccess + 1))
|
||||||
|
# overwrite old version of file
|
||||||
|
mv -f "$updateFilename.tmp" "$updateFilename"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
printf "[NONE]\n"
|
printf "[NONE]\n"
|
||||||
fi
|
fi
|
||||||
done
|
done <"$checksumFilename"
|
||||||
|
|
||||||
|
|
||||||
### display results
|
### display results
|
||||||
printf "\n%sResults:%s\n" "$info" "$norm"
|
printf "\n%sResults:%s\n" "$info" "$norm"
|
||||||
|
Loading…
Reference in New Issue
Block a user