partial rewrite of script and new update location
This commit is contained in:
parent
edf6a13e38
commit
3bc3683b11
@ -1,11 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
### update script for ab-openldap container and utility scripts
|
||||
#
|
||||
# update script for ab-openldap container and utility scripts
|
||||
# version 1.0.0
|
||||
# script by Asif Bacchus
|
||||
# usage of this script is subject to the license terms found at:
|
||||
# https://git.asifbacchus.app/ab-docker/scripts/LICENSE
|
||||
|
||||
#
|
||||
|
||||
### pre-requisites
|
||||
|
||||
@ -32,55 +33,53 @@ updateSuccess=0
|
||||
# reference constants
|
||||
containerName='ab-openldap'
|
||||
containerUpdatePath='docker.asifbacchus.app/ldap/ab-openldap:latest'
|
||||
server="https://git.asifbacchus.app/ab-docker/scripts/raw/branch/master/$containerName/"
|
||||
serverPath="https://asifbacchus.app/public/$containerName/"
|
||||
checksumFilename='checksums.sha256'
|
||||
|
||||
# files to update
|
||||
localScriptName='update.sh'
|
||||
repoScriptName='update.sh'
|
||||
updateFiles="ab-openldap.sh ab-openldap.params.template backup.sh backup.params.template"
|
||||
scriptName='ab-openldap-update.sh'
|
||||
updateFiles="ab-openldap-backup.params.template ab-openldap-backup.sh ab-openldap.params.template ab-openldap.sh"
|
||||
|
||||
printf "\nUpdating %s:\n" "$containerName"
|
||||
|
||||
|
||||
### update container
|
||||
printf "\n*** Updating %s container and service scripts ***\n\n" "$containerName"
|
||||
|
||||
printf "Updating container:\n"
|
||||
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"
|
||||
exit 1
|
||||
else
|
||||
printf "Container updated!\n\n"
|
||||
fi
|
||||
|
||||
|
||||
### update scripts
|
||||
printf "Updating %s service scripts\n" "$containerName"
|
||||
|
||||
## download latest checksums
|
||||
printf "Getting latest checksums from ab-git server... "
|
||||
if ! wget --quiet --tries=3 --timeout=10 -N "${server}${checksumFilename}"; then
|
||||
printf "[ERROR]\n"
|
||||
printf "Unable to download checksums from ab-git server. Try again later.\n\n"
|
||||
exit 1
|
||||
else
|
||||
printf "[OK]\n"
|
||||
fi
|
||||
|
||||
## check for updates to this script
|
||||
printf "Checking for updates to this script... "
|
||||
repoScriptChecksum=$( grep "$repoScriptName" "$checksumFilename" | grep -o '^\S*' )
|
||||
localScriptChecksum=$( sha256sum "$localScriptName" | grep -o '^\S*' )
|
||||
### 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"
|
||||
exit 1
|
||||
else
|
||||
printf "[OK]\n"
|
||||
fi
|
||||
|
||||
|
||||
### script self-update
|
||||
printf "checking for updates to this script... "
|
||||
localScriptChecksum=$( sha256 "./$scriptName" | grep -o '^\S*' )
|
||||
repoScriptChecksum=$( grep "$scriptName" "$checksumFilename" | grep -o '^\S*' )
|
||||
if [ "$localScriptChecksum" = "$repoScriptChecksum" ]; then
|
||||
printf "[NONE]\n"
|
||||
else
|
||||
# download updated script
|
||||
if ! wget --quiet --tries=3 --timeout=10 -O $localScriptName "${server}${repoScriptName}"; then
|
||||
printf "[ERROR]\n"
|
||||
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"
|
||||
exit 1
|
||||
else
|
||||
# verify download
|
||||
localScriptChecksum=$( sha256sum "$localScriptName" | grep -o '^\S*' )
|
||||
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"
|
||||
@ -96,36 +95,31 @@ fi
|
||||
set -- dummy $updateFiles
|
||||
shift
|
||||
for file; do
|
||||
updateTarget="$file"
|
||||
printf "\nChecking '%s' for updates... " "$updateTarget"
|
||||
repoFile=$( grep "$updateTarget" "$checksumFilename" | grep -o '^\S*' )
|
||||
printf "\nchecking '%s' for updates... " "$file"
|
||||
repoFileChecksum=$( grep "$file" "$checksumFilename" | grep -o '^\S*' )
|
||||
if [ -f "$file" ]; then
|
||||
localFile=$( sha256sum "$updateTarget" | grep -o '^\S*' )
|
||||
localFileChecksum=$( sha256sum "$file" | grep -o '^\S*' )
|
||||
else
|
||||
localFile=0
|
||||
localFileChecksum=0
|
||||
fi
|
||||
|
||||
if ! [ "$localFile" = "$repoFile" ]; then
|
||||
if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then
|
||||
printf "[AVAILABLE]\n"
|
||||
updatesAvailable=$((updatesAvailable+1))
|
||||
# download update
|
||||
printf "Downloading updated '%s'... " "$updateTarget"
|
||||
# specify a name here instead of using the server name so that wget
|
||||
# overwrites the file
|
||||
if ! wget --quiet --tries=3 --timeout=10 -O "$updateTarget" "${server}${updateTarget}"; then
|
||||
printf "Downloading updated '%s'... " "$file"
|
||||
if ! wget --quiet --tries=3 --timeout=10 -O "$file" "$serverPath$file"; then
|
||||
printf "[ERROR]\n"
|
||||
downloadFailed=$((downloadFailed+1))
|
||||
else
|
||||
printf "[OK]\n"
|
||||
printf "[OK] "
|
||||
downloadSuccess=$((downloadSuccess+1))
|
||||
# verify download
|
||||
printf "Verifying '%s'... " "$updateTarget"
|
||||
localFile=$( sha256sum "$updateTarget" | grep -o '^\S*' )
|
||||
if ! [ "$localFile" = "$repoFile" ]; then
|
||||
localFileChecksum=$( sha256sum "$file" | grep -o '^\S*' )
|
||||
if ! [ "$localFileChecksum" = "$repoFileChecksum" ]; then
|
||||
printf "[INVALID]\n"
|
||||
updateFailed=$((updateFailed+1))
|
||||
else
|
||||
printf "[OK]\n"
|
||||
printf "[VERIFIED]\n"
|
||||
updateSuccess=$((updateSuccess+1))
|
||||
fi
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user