format text output

This commit is contained in:
Asif Bacchus 2020-09-14 23:50:04 -06:00
parent 81e0a6d91a
commit 809c04b4b3

View File

@ -57,36 +57,36 @@ updateSuccess=0
# reference constants # reference constants
containerName='ab-openldap' containerName='ab-openldap'
containerUpdatePath='docker.asifbacchus.app/ldap/ab-openldap:latestx' containerUpdatePath="docker.asifbacchus.app/ldap/$containerName:latest"
serverPath="https://asifbacchus.app/public/$containerName/" serverPath="https://asifbacchus.app/public/$containerName/"
checksumFilename='checksums.sha256' checksumFilename='checksums.sha256'
# files to update # files to update
scriptName='ab-openldap-update.sh' scriptName="$containerName-update.sh"
updateFiles="ab-openldap-backup.params.template ab-openldap-backup.sh ab-openldap.params.template ab-openldap.sh" updateFiles="$containerName-backup.params.template $containerName-backup.sh $containerName.params.template $containerName.sh"
printf "\nUpdating %s:\n" "$containerName" printf "\n%sUpdating %s%s%s:%s\n" "$cyan" "$yellow" "$containerName" "$cyan" "$norm"
### update container ### update container
printf "updating container... " printf "updating container... "
if ! docker pull "$containerUpdatePath" > /dev/null 2>&1; then if ! docker pull "$containerUpdatePath" > /dev/null 2>&1; then
printf "[ERROR]\n\n" printf "%s[ERROR]\n\n" "$err"
printf "There was an error updating the container. Try again later.\n\n" printf "There was a problem updating the container. Please try again later.%s\n\n" "$norm"
exit 1 exit 1
else else
printf "[OK]\n" printf "%s[OK]%s\n" "$ok" "$norm"
fi fi
### checksums ### checksums
printf "downloading latest checksums... " printf "downloading latest checksums... "
if ! wget --quiet --tries=3 --timeout=10 -O "$checksumFilename" "$serverPath$checksumFilename"; then if ! wget --quiet --tries=3 --timeout=10 -O "$checksumFilename" "$serverPath$checksumFilename"; then
printf "[ERROR]\n\n" printf "%s[ERROR]\n\n" "$err"
printf "Unable to download updated checksums. Try again later.\n\n" printf "Unable to download updated checksums. Please try again later.%s\n\n" "$norm"
exit 1 exit 1
else else
printf "[OK]\n" printf "%s[OK]%s\n" "$ok" "$norm"
fi fi
@ -99,25 +99,25 @@ if [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then
else else
# download updated script # download updated script
if ! wget --quiet --tries=3 --timeout=10 -O "$scriptName" "$serverPath$scriptName"; then if ! wget --quiet --tries=3 --timeout=10 -O "$scriptName" "$serverPath$scriptName"; then
printf "[ERROR]\n\n" printf "%s[ERROR]\n\n" "$err"
printf "Unable to download script update. Try again later.\n\n" printf "Unable to download script update. Please try again later.%s\n\n" "$norm"
exit 1 exit 1
else else
# verify download # verify download
localScriptChecksum=$( sha256sum "$scriptName" | grep -o '^\S*' ) localScriptChecksum=$( sha256sum "$scriptName" | grep -o '^\S*' )
if ! [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then if ! [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then
printf "[ERROR]\n" printf "%s[ERROR]\n\n" "$err"
printf "Unable to verify checksum of updated script. Try again later.\n\n" printf "Unable to verify checksum of updated script. Please try again later.%s\n\n" "$norm"
else else
printf "[UPDATED]\n\n" printf "%s[UPDATED]%s\n\n" "$ok" "$norm"
printf "*** This script has been updated. Please re-run it to load the updated version of this file. ***\n\n" printf "%s*** This script has been updated. Please re-run it to load the updated version of this file. ***%s\n\n" "$yellow" "$norm"
exit 0 exit 0
fi fi
fi fi
fi fi
## update files ## update files
set -- dummy $updateFiles set -- dummy "$updateFiles"
shift shift
for file; do for file; do
printf "\nchecking '%s' for updates... " "$file" printf "\nchecking '%s' for updates... " "$file"
@ -128,23 +128,23 @@ for file; do
localFileChecksum=0 localFileChecksum=0
fi fi
if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then
printf "[AVAILABLE]\n" printf "%s[AVAILABLE]%s\n" "$yellow" "$norm"
updatesAvailable=$((updatesAvailable+1)) updatesAvailable=$((updatesAvailable+1))
# download update # download update
printf "Downloading updated '%s'... " "$file" printf "Downloading updated '%s'... " "$file"
if ! wget --quiet --tries=3 --timeout=10 -O "$file" "$serverPath$file"; then if ! wget --quiet --tries=3 --timeout=10 -O "$file" "$serverPath$file"; then
printf "[ERROR]\n" printf "%s[ERROR]%s\n\n" "$err" "$norm"
downloadFailed=$((downloadFailed+1)) downloadFailed=$((downloadFailed+1))
else else
printf "[OK] " printf "%s[OK] %s" "$ok" "$norm"
downloadSuccess=$((downloadSuccess+1)) downloadSuccess=$((downloadSuccess+1))
# verify download # verify download
localFileChecksum=$( sha256sum "$file" | grep -o '^\S*' ) localFileChecksum=$( sha256sum "$file" | grep -o '^\S*' )
if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then
printf "[INVALID]\n" printf "%s[INVALID]%s\n" "$err" "$norm"
updateFailed=$((updateFailed+1)) updateFailed=$((updateFailed+1))
else else
printf "[VERIFIED]\n" printf "%s[VERIFIED]%s\n" "$ok" "$norm"
updateSuccess=$((updateSuccess+1)) updateSuccess=$((updateSuccess+1))
fi fi
fi fi
@ -155,9 +155,9 @@ done
### display results ### display results
printf "\nResults:\n" printf "\n%sResults:%s\n" "$cyan" "$norm"
printf "\tUpdates: %s available\n" "$updatesAvailable" printf "\tUpdates: %s available\n" "$updatesAvailable"
printf "\tDownloads: %s successful, %s failed\n" "$downloadSuccess" "$downloadFailed" printf "\tDownloads: %s successful, %s%s failed%s\n" "$downloadSuccess" "$err" "$downloadFailed" "$norm"
printf "\tUpdates: %s applied, %s failed\n" "$updateSuccess" "$updateFailed" printf "\tUpdates: %s applied, %s%s failed%s\n" "$updateSuccess" "$err" "$updateFailed" "$norm"
exit 0 exit 0