1
0
Fork 0

Compare commits

...

8 Commits

Author SHA1 Message Date
Asif Bacchus 2427aa628b update checksums 2020-09-15 00:07:49 -06:00
Asif Bacchus 5478ac1565 remove unused colours 2020-09-14 23:53:46 -06:00
Asif Bacchus 809c04b4b3 format text output 2020-09-14 23:50:04 -06:00
Asif Bacchus 81e0a6d91a add yellow text colour 2020-09-14 23:42:39 -06:00
Asif Bacchus 514e24664c use func: consoleError to display error 2020-09-14 23:36:34 -06:00
Asif Bacchus 34d57d4553 add error display function 2020-09-14 23:36:17 -06:00
Asif Bacchus 394487fadb add text formatting presets 2020-09-14 23:36:03 -06:00
Asif Bacchus 0a032cdae1 supress docker update output 2020-09-14 23:21:37 -06:00
2 changed files with 56 additions and 33 deletions

View File

@ -8,12 +8,35 @@
# https://git.asifbacchus.app/ab-docker/scripts/LICENSE # https://git.asifbacchus.app/ab-docker/scripts/LICENSE
# #
### functions
consoleError() {
printf "\n%s%s%s\n\n" "$err" "$2" "$norm"
exit "$1"
}
### text formatting presets
if command -v tput > /dev/null; then
cyan=$(tput setaf 6)
err=$(tput bold)$(tput setaf 1)
norm=$(tput sgr0)
ok=$(tput setaf 2)
yellow=$(tput setaf 11)
else
cyan=''
err=''
norm=''
ok=''
yellow=''
fi
### pre-requisites ### pre-requisites
# check if wget is installed # check if wget is installed
if ! command -v wget > /dev/null 2>&1; then if ! command -v wget > /dev/null 2>&1; then
printf "\nSorry, this script requires that 'wget' is installed in order to automatically update files.\nExiting.\n\n" consoleError '1' "Sorry, this script requires that 'wget' is installed in order to automatically update files."
exit 1
fi fi
# is user root or in the docker group? # is user root or in the docker group?
@ -32,36 +55,36 @@ updateSuccess=0
# reference constants # reference constants
containerName='ab-openldap' containerName='ab-openldap'
containerUpdatePath='docker.asifbacchus.app/ldap/ab-openldap:latest' 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"; 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
@ -74,25 +97,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"
@ -103,23 +126,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
@ -130,9 +153,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

View File

@ -1,5 +1,5 @@
3a6178a07571c14e3036aeede7bfb5fa7982faf682b7b919d2f05dbf07e080da ab-openldap.sh a4ff46220c20887c85dbd9f4cc3d455bddeb920701966693bc277fb0690e9272 ab-openldap-backup.params.template
7e49710a156a2722b7f2dbf92b4f3e4b51bcfbf97403b4698ad4ef0216eadef6 backup.sh 206d756846839c13574adef3acec9a9475e0212904bd44c336414160dfeb7bb1 ab-openldap-backup.sh
5f228bddbe83bbaa495ad4095a50778c865d3288179148829820b55d00511ca5 update.sh a2ae75864833c517aa686bbef02cd22864f305a42013c02d44df0008e4f2995e ab-openldap.params.template
1be75b2ac18dbc7e7f9eeaedffac688d055435b170b00fadb5d5cb3b55398472 ab-openldap.params.template c0d949a47ece205e8b9f31ec7376491a75a39865a3affba85b349982f5519297 ab-openldap.sh
407e732d110cd0dea8e257e22953931fc51237d7583a69722da3b1d7843f0738 backup.params.template 387c7f5c771f13eb6a0f46ecd0d9e12b74bf721020835bb9f51b6bd9a634d38e ab-openldap-update.sh