feature(HELPERSCRIPTS): add parameter processing skeleton

This commit is contained in:
Asif Bacchus 2021-01-15 05:07:01 -07:00
parent cbb8595380
commit 19a8f3a082

View File

@ -1,7 +1,7 @@
#!/bin/sh #!/bin/sh
### update script for ab-nginx container and utility scripts ### update script for ab-nginx container and utility scripts
# version 1.0.0 # version 2.0.0
# script by Asif Bacchus # script by Asif Bacchus
### ###
@ -45,17 +45,18 @@ if ! command -v wget >/dev/null 2>&1; then
errMsg "Sorry, this script requires that 'wget' is installed in order to download updates. Exiting." errMsg "Sorry, this script requires that 'wget' is installed in order to download updates. Exiting."
fi fi
# check if docker is installed # include in docker section
if ! command -v docker >/dev/null 2>&1; then ## check if docker is installed
errMsg "Sorry, it appears that docker is not installed on this machine! Exiting." #if ! command -v docker >/dev/null 2>&1; then
fi # errMsg "Sorry, it appears that docker is not installed on this machine! Exiting."
#fi
# is user root or in the docker group? #
if [ ! "$(id -u)" -eq 0 ]; then ## is user root or in the docker group?
if ! id -Gn | grep docker >/dev/null; then #if [ ! "$(id -u)" -eq 0 ]; then
errMsg "You must either be root or in the 'docker' group to pull container updates." # if ! id -Gn | grep docker >/dev/null; then
fi # errMsg "You must either be root or in the 'docker' group to pull container updates."
fi # fi
#fi
# zero counters # zero counters
updatesAvailable=0 updatesAvailable=0
@ -71,10 +72,46 @@ containerUpdatePath="docker.asifbacchus.app/$dockerNamespace/$containerName:late
server="https://asifbacchus.app/updates/docker/$dockerNamespace/$containerName/" server="https://asifbacchus.app/updates/docker/$dockerNamespace/$containerName/"
checksumFilename='checksums.sha256' checksumFilename='checksums.sha256'
# operation triggers
doDockerUpdate=1
doScriptUpdate=1
doContainerRestart=1
# files to update # files to update
localScriptName="$(basename "$0")" localScriptName="$(basename "$0")"
repoScriptName='update.sh' repoScriptName='update.sh'
### process startup parameters
while [ $# -gt 0 ]; do
case "$1" in
-h|-\?|--help)
# display inline help
# TODO: create script help function
scriptHelp
;;
-s|--scripts|--scripts-only)
# update scripts only, skip docker container update
doDockerUpdate=0
;;
-c|--container|--container-only)
# update docker container only, skip script update
doScriptUpdate=0
;;
--no-restart)
# do not restart container automatically
doContainerRestart=0
;;
*)
printf "%s\nUnknown option: %s\n" "$err" "$1"
printf "%sUse '--help' for valid options%s\n\n" "$info" "$norm"
exit 1
;;
esac
shift
done
### update container ### update container
printf "%s\n*** Updating %s container and service scripts ***\n\n%s" "$info" "$containerName" "$norm" printf "%s\n*** Updating %s container and service scripts ***\n\n%s" "$info" "$containerName" "$norm"