|
|
|
@ -8,12 +8,35 @@
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
|
|
# check if wget is installed
|
|
|
|
|
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"
|
|
|
|
|
exit 1
|
|
|
|
|
consoleError '1' "Sorry, this script requires that 'wget' is installed in order to automatically update files."
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# is user root or in the docker group?
|
|
|
|
@ -32,36 +55,36 @@ updateSuccess=0
|
|
|
|
|
|
|
|
|
|
# reference constants
|
|
|
|
|
containerName='ab-openldap'
|
|
|
|
|
containerUpdatePath='docker.asifbacchus.app/ldap/ab-openldap:latest'
|
|
|
|
|
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"; then
|
|
|
|
|
printf "[ERROR]\n\n"
|
|
|
|
|
printf "There was an error updating the container. Try again later.\n\n"
|
|
|
|
|
if ! docker pull "$containerUpdatePath" > /dev/null 2>&1; then
|
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -74,25 +97,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"
|
|
|
|
@ -103,23 +126,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
|
|
|
|
@ -130,9 +153,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
|