style(helpers): reformat update script and bump version

This commit is contained in:
Asif Bacchus 2021-07-27 16:09:27 -06:00
parent 4d5f3fa809
commit 03e0631964

View File

@ -1,11 +1,13 @@
#!/bin/sh #!/bin/sh
### update script for ab-nginx container and utility scripts #
# version 2.0.0 # update script for ab-nginx container and utility scripts
# version 2.1.0
# script by Asif Bacchus # script by Asif Bacchus
### #
### functions #
# functions
errMsg() { errMsg() {
printf "\n%s%s%s\n\n" "$err" "$1" "$norm" printf "\n%s%s%s\n\n" "$err" "$1" "$norm"
exit 1 exit 1
@ -25,27 +27,27 @@ okNotify() {
scriptHelp() { scriptHelp() {
textNewline textNewline
textblock "Update ${containerName} container and helper script files" textBlock "Update ${containerName} container and helper script files"
textblock "${bold}Usage: ${localScriptName} [parameters]${norm}" textBlock "${bold}Usage: ${localScriptName} [parameters]${norm}"
textNewline textNewline
textblock "If run with no parameters, the script will update both the container and the helper script files, including this update script." textBlock "If run with no parameters, the script will update both the container and the helper script files, including this update script."
textblockHeader " parameters " textBlockHeader " parameters "
textblockParam "-h|-?|--help" "Display this help screen." textBlockParam "-h|-?|--help" "Display this help screen."
textblockParam "-c|--container|--container-only" "Update the docker container only." textBlockParam "-c|--container|--container-only" "Update the docker container only."
textblockParam "-s|--scripts|--scripts-only" "Update the helper scripts (including this update script) only." textBlockParam "-s|--scripts|--scripts-only" "Update the helper scripts (including this update script) only."
textNewline textNewline
exit 0 exit 0
} }
textblock() { textBlock() {
printf "%s\n" "$1" | fold -w "$width" -s printf "%s\n" "$1" | fold -w "$width" -s
} }
textblockHeader() { textBlockHeader() {
printf "\n%s***%s***%s\n" "$header" "$1" "$norm" printf "\n%s***%s***%s\n" "$header" "$1" "$norm"
} }
textblockParam() { textBlockParam() {
printf "%s%-35s%s%s\n" "$info" "$1" "$2" "$norm" printf "%s%-35s%s%s\n" "$info" "$1" "$2" "$norm"
} }
@ -53,7 +55,8 @@ textNewline() {
printf "\n" printf "\n"
} }
### text formatting presets #
# text formatting presets
if command -v tput >/dev/null 2>&1; then if command -v tput >/dev/null 2>&1; then
bold=$(tput bold) bold=$(tput bold)
err=$(tput bold)$(tput setaf 1) err=$(tput bold)$(tput setaf 1)
@ -74,7 +77,8 @@ else
width=80 width=80
fi 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
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."
@ -102,7 +106,8 @@ doScriptUpdate=1
localScriptName="$(basename "$0")" localScriptName="$(basename "$0")"
repoScriptName='update.sh' repoScriptName='update.sh'
### process startup parameters #
# process startup parameters
while [ $# -gt 0 ]; do while [ $# -gt 0 ]; do
case "$1" in case "$1" in
-h | -\? | --help) -h | -\? | --help)
@ -126,7 +131,8 @@ while [ $# -gt 0 ]; do
shift shift
done done
### update container #
# update container
if [ "$doDockerUpdate" -eq 1 ]; then if [ "$doDockerUpdate" -eq 1 ]; then
# check if docker is installed # check if docker is installed
if ! command -v docker >/dev/null 2>&1; then if ! command -v docker >/dev/null 2>&1; then
@ -148,7 +154,8 @@ if [ "$doDockerUpdate" -eq 1 ]; then
fi fi
fi fi
### update scripts #
# update scripts
if [ "$doScriptUpdate" -eq 1 ]; then if [ "$doScriptUpdate" -eq 1 ]; then
printf "%s*** Updating %s service scripts ***%s\n" "$info" "$containerName" "$norm" printf "%s*** Updating %s service scripts ***%s\n" "$info" "$containerName" "$norm"
@ -239,7 +246,8 @@ if [ "$doScriptUpdate" -eq 1 ]; then
done <"$checksumFilename" done <"$checksumFilename"
fi fi
### display results #
# display results
if [ "$doScriptUpdate" -eq 1 ]; then if [ "$doScriptUpdate" -eq 1 ]; then
printf "\n%s*** Results ***%s\n" "$info" "$norm" printf "\n%s*** Results ***%s\n" "$info" "$norm"
printf "\tUpdates: %s available\n" "$updatesAvailable" printf "\tUpdates: %s available\n" "$updatesAvailable"