Compare commits

..

No commits in common. "2427aa628b4a4fe229778db081c1dc26eacff071" and "b4f8834d5177689fb13a9ddeefafe2bbcdfbb017" have entirely different histories.

2 changed files with 33 additions and 56 deletions

View File

@ -8,35 +8,12 @@
# 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
consoleError '1' "Sorry, this script requires that 'wget' is installed in order to automatically update files." printf "\nSorry, this script requires that 'wget' is installed in order to automatically update files.\nExiting.\n\n"
exit 1
fi fi
# is user root or in the docker group? # is user root or in the docker group?
@ -55,36 +32,36 @@ updateSuccess=0
# reference constants # reference constants
containerName='ab-openldap' containerName='ab-openldap'
containerUpdatePath="docker.asifbacchus.app/ldap/$containerName:latest" containerUpdatePath='docker.asifbacchus.app/ldap/ab-openldap: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="$containerName-update.sh" scriptName='ab-openldap-update.sh'
updateFiles="$containerName-backup.params.template $containerName-backup.sh $containerName.params.template $containerName.sh" updateFiles="ab-openldap-backup.params.template ab-openldap-backup.sh ab-openldap.params.template ab-openldap.sh"
printf "\n%sUpdating %s%s%s:%s\n" "$cyan" "$yellow" "$containerName" "$cyan" "$norm" printf "\nUpdating %s:\n" "$containerName"
### update container ### update container
printf "updating container... " printf "updating container... "
if ! docker pull "$containerUpdatePath" > /dev/null 2>&1; then if ! docker pull "$containerUpdatePath"; then
printf "%s[ERROR]\n\n" "$err" printf "[ERROR]\n\n"
printf "There was a problem updating the container. Please try again later.%s\n\n" "$norm" printf "There was an error updating the container. Try again later.\n\n"
exit 1 exit 1
else else
printf "%s[OK]%s\n" "$ok" "$norm" printf "[OK]\n"
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 "%s[ERROR]\n\n" "$err" printf "[ERROR]\n\n"
printf "Unable to download updated checksums. Please try again later.%s\n\n" "$norm" printf "Unable to download updated checksums. Try again later.\n\n"
exit 1 exit 1
else else
printf "%s[OK]%s\n" "$ok" "$norm" printf "[OK]\n"
fi fi
@ -97,25 +74,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 "%s[ERROR]\n\n" "$err" printf "[ERROR]\n\n"
printf "Unable to download script update. Please try again later.%s\n\n" "$norm" printf "Unable to download script update. Try again later.\n\n"
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 "%s[ERROR]\n\n" "$err" printf "[ERROR]\n"
printf "Unable to verify checksum of updated script. Please try again later.%s\n\n" "$norm" printf "Unable to verify checksum of updated script. Try again later.\n\n"
else else
printf "%s[UPDATED]%s\n\n" "$ok" "$norm" printf "[UPDATED]\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" printf "*** This script has been updated. Please re-run it to load the updated version of this file. ***\n\n"
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"
@ -126,23 +103,23 @@ for file; do
localFileChecksum=0 localFileChecksum=0
fi fi
if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then
printf "%s[AVAILABLE]%s\n" "$yellow" "$norm" printf "[AVAILABLE]\n"
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 "%s[ERROR]%s\n\n" "$err" "$norm" printf "[ERROR]\n"
downloadFailed=$((downloadFailed+1)) downloadFailed=$((downloadFailed+1))
else else
printf "%s[OK] %s" "$ok" "$norm" printf "[OK] "
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 "%s[INVALID]%s\n" "$err" "$norm" printf "[INVALID]\n"
updateFailed=$((updateFailed+1)) updateFailed=$((updateFailed+1))
else else
printf "%s[VERIFIED]%s\n" "$ok" "$norm" printf "[VERIFIED]\n"
updateSuccess=$((updateSuccess+1)) updateSuccess=$((updateSuccess+1))
fi fi
fi fi
@ -153,9 +130,9 @@ done
### display results ### display results
printf "\n%sResults:%s\n" "$cyan" "$norm" printf "\nResults:\n"
printf "\tUpdates: %s available\n" "$updatesAvailable" printf "\tUpdates: %s available\n" "$updatesAvailable"
printf "\tDownloads: %s successful, %s%s failed%s\n" "$downloadSuccess" "$err" "$downloadFailed" "$norm" printf "\tDownloads: %s successful, %s failed\n" "$downloadSuccess" "$downloadFailed"
printf "\tUpdates: %s applied, %s%s failed%s\n" "$updateSuccess" "$err" "$updateFailed" "$norm" printf "\tUpdates: %s applied, %s failed\n" "$updateSuccess" "$updateFailed"
exit 0 exit 0

View File

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