From 809c04b4b327f42d671edb1cadf47de43e11e2d2 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Mon, 14 Sep 2020 23:50:04 -0600 Subject: [PATCH] format text output --- ab-openldap/ab-openldap-update.sh | 50 +++++++++++++++---------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/ab-openldap/ab-openldap-update.sh b/ab-openldap/ab-openldap-update.sh index ff3625e..836cc59 100755 --- a/ab-openldap/ab-openldap-update.sh +++ b/ab-openldap/ab-openldap-update.sh @@ -57,36 +57,36 @@ updateSuccess=0 # reference constants containerName='ab-openldap' -containerUpdatePath='docker.asifbacchus.app/ldap/ab-openldap:latestx' +containerUpdatePath="docker.asifbacchus.app/ldap/$containerName:latest" serverPath="https://asifbacchus.app/public/$containerName/" checksumFilename='checksums.sha256' # files to update -scriptName='ab-openldap-update.sh' -updateFiles="ab-openldap-backup.params.template ab-openldap-backup.sh ab-openldap.params.template ab-openldap.sh" +scriptName="$containerName-update.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 printf "updating container... " if ! docker pull "$containerUpdatePath" > /dev/null 2>&1; then - printf "[ERROR]\n\n" - printf "There was an error updating the container. Try again later.\n\n" + printf "%s[ERROR]\n\n" "$err" + printf "There was a problem updating the container. Please try again later.%s\n\n" "$norm" exit 1 else - printf "[OK]\n" + printf "%s[OK]%s\n" "$ok" "$norm" fi ### checksums printf "downloading latest checksums... " if ! wget --quiet --tries=3 --timeout=10 -O "$checksumFilename" "$serverPath$checksumFilename"; then - printf "[ERROR]\n\n" - printf "Unable to download updated checksums. Try again later.\n\n" + printf "%s[ERROR]\n\n" "$err" + printf "Unable to download updated checksums. Please try again later.%s\n\n" "$norm" exit 1 else - printf "[OK]\n" + printf "%s[OK]%s\n" "$ok" "$norm" fi @@ -99,25 +99,25 @@ if [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then else # download updated script if ! wget --quiet --tries=3 --timeout=10 -O "$scriptName" "$serverPath$scriptName"; then - printf "[ERROR]\n\n" - printf "Unable to download script update. Try again later.\n\n" + printf "%s[ERROR]\n\n" "$err" + printf "Unable to download script update. Please try again later.%s\n\n" "$norm" exit 1 else # verify download localScriptChecksum=$( sha256sum "$scriptName" | grep -o '^\S*' ) if ! [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then - printf "[ERROR]\n" - printf "Unable to verify checksum of updated script. Try again later.\n\n" + printf "%s[ERROR]\n\n" "$err" + printf "Unable to verify checksum of updated script. Please try again later.%s\n\n" "$norm" else - printf "[UPDATED]\n\n" - printf "*** This script has been updated. Please re-run it to load the updated version of this file. ***\n\n" + printf "%s[UPDATED]%s\n\n" "$ok" "$norm" + 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 fi fi fi ## update files -set -- dummy $updateFiles +set -- dummy "$updateFiles" shift for file; do printf "\nchecking '%s' for updates... " "$file" @@ -128,23 +128,23 @@ for file; do localFileChecksum=0 fi if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then - printf "[AVAILABLE]\n" + printf "%s[AVAILABLE]%s\n" "$yellow" "$norm" updatesAvailable=$((updatesAvailable+1)) # download update printf "Downloading updated '%s'... " "$file" 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)) else - printf "[OK] " + printf "%s[OK] %s" "$ok" "$norm" downloadSuccess=$((downloadSuccess+1)) # verify download localFileChecksum=$( sha256sum "$file" | grep -o '^\S*' ) if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then - printf "[INVALID]\n" + printf "%s[INVALID]%s\n" "$err" "$norm" updateFailed=$((updateFailed+1)) else - printf "[VERIFIED]\n" + printf "%s[VERIFIED]%s\n" "$ok" "$norm" updateSuccess=$((updateSuccess+1)) fi fi @@ -155,9 +155,9 @@ done ### display results -printf "\nResults:\n" +printf "\n%sResults:%s\n" "$cyan" "$norm" printf "\tUpdates: %s available\n" "$updatesAvailable" -printf "\tDownloads: %s successful, %s failed\n" "$downloadSuccess" "$downloadFailed" -printf "\tUpdates: %s applied, %s failed\n" "$updateSuccess" "$updateFailed" +printf "\tDownloads: %s successful, %s%s failed%s\n" "$downloadSuccess" "$err" "$downloadFailed" "$norm" +printf "\tUpdates: %s applied, %s%s failed%s\n" "$updateSuccess" "$err" "$updateFailed" "$norm" exit 0 \ No newline at end of file