refactor(SCRIPT): new formatting
- check for tput, set formatting to null if not installed - collapse scriptHelp according to screen width
This commit is contained in:
parent
6f4b2509b4
commit
b617b7e633
86
ab-nginx.sh
86
ab-nginx.sh
@ -5,11 +5,21 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
# text formatting presets
|
# text formatting presets
|
||||||
cyan=$(tput setaf 6)
|
if command -v tput > /dev/null; then
|
||||||
err=$(tput bold)$(tput setaf 1)
|
cyan=$(tput bold)$(tput setaf 6)
|
||||||
magenta=$(tput setaf 5)
|
err=$(tput bold)$(tput setaf 1)
|
||||||
norm=$(tput sgr0)
|
magenta=$(tput sgr0)$(tput setaf 5)
|
||||||
yellow=$(tput setaf 3)
|
norm=$(tput sgr0)
|
||||||
|
yellow=$(tput sgr0)$(tput setaf 3)
|
||||||
|
width=$(tput cols)
|
||||||
|
else
|
||||||
|
cyan=''
|
||||||
|
err=''
|
||||||
|
magenta=''
|
||||||
|
norm=''
|
||||||
|
yellow=''
|
||||||
|
width=80
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
### parameter defaults
|
### parameter defaults
|
||||||
@ -43,36 +53,48 @@ checkExist () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scriptHelp () {
|
scriptHelp () {
|
||||||
printf "\n${magenta}%80s\n" | tr " " "-"
|
printf "\n%s%1000s\n" "$magenta" | tr " " "-" | cut -c -$width
|
||||||
printf "${norm}This is a simple helper script so you can avoid lengthy typing when working\n"
|
printf "%s" "$norm"
|
||||||
printf "with the nginx container. The script reads the contents of 'ab-nginx.params'\n"
|
textblock "This is a simple helper script so you can avoid lengthy typing when working with the nginx container. The script reads the contents of 'ab-nginx.params' and constructs various 'docker run' commands based on that file. The biggest time-saver is working with certificates. If they are specified in the params file, the script will automatically bind-mount them so nginx serves content via SSL by default."
|
||||||
printf "and constructs various 'docker run' commands based on that file. The biggest\n"
|
newline
|
||||||
printf "timesaver is working with certificates. If they are specified in params file,\n"
|
textblock "If you run the script with no parameters, it will execute the container 'normally': Run in detached mode with nginx automatically launched and logging to stdout. If you specified certificates, nginx will serve over SSL by default."
|
||||||
printf "the script will automatically bind-mount them so nginx serves content via SSL\n"
|
newline
|
||||||
printf "by default.\n\n"
|
textblock "Note: Containers (except shell) are always set to restart 'unless-stopped'. You must remove them manually if desired."
|
||||||
printf "If you run the script with no parameters, it will execute the container\n"
|
printf "%s" "$magenta"
|
||||||
printf "'normally': Run in detached mode with nginx automatically launched and\n"
|
newline
|
||||||
printf "logging to stdout. If you specified certificates, nginx will serve over SSL\n"
|
textblock "The script has the following parameters:"
|
||||||
printf "by default.\n"
|
textblockParam 'parameter in cyan' 'default in yellow'
|
||||||
printf "Note: Containers (except shell) are always set to restart 'unless-stopped'. You\n"
|
newline
|
||||||
printf "must remove them manually if desired.\n\n"
|
textblockParam '-n|--name' 'ab-nginx'
|
||||||
printf "${magenta}The script has the following parameters:\n"
|
textblock "Change the name of the container. This is cosmetic and does not affect operation in any way."
|
||||||
printf "${cyan}(parameter in cyan) ${yellow}(default in yellow)${norm}\n\n"
|
newline
|
||||||
printf "${cyan}-n|--name${norm}\n"
|
textblockParam '-s|--shell' 'off: run in detached mode'
|
||||||
printf "Change the name of the container. This is cosmetic and does not affect\n"
|
textblock "Enter the container using an interactive POSIX shell. This happens after startup operations but *before* nginx is actually started. This is a great way to see configuration changes possibly stopping nginx from starting normally."
|
||||||
printf "operation in any way.\n"
|
printf "%s" "$yellow"
|
||||||
printf "${yellow}(ab-nginx)${norm}\n\n"
|
newline
|
||||||
printf "${cyan}-s|--shell${norm}\n"
|
textblock "More information can be found at: https://git.asifbacchus.app/ab-docker/ab-nginx/wiki"
|
||||||
printf "Enter the container using an interactive POSIX shell. This happens after\n"
|
printf "%s%1000s\n" "$magenta" | tr " " "-" | cut -c -$width
|
||||||
printf "startup operations but *before* nginx is actually started. This is a great way\n"
|
|
||||||
printf "to see configuration changes possibly stopping nginx from starting normally.\n"
|
|
||||||
printf "${yellow}(off: run in detached mode)${norm}\n\n"
|
|
||||||
printf "${yellow}More information can be found at:\n"
|
|
||||||
printf "https://git.asifbacchus.app/ab-docker/ab-nginx/wiki\n"
|
|
||||||
printf "${magenta}%80s\n\n" | tr " " "-"
|
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newline () {
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
textblock () {
|
||||||
|
printf "%s\n" "$1" | fold -w "$width" -s
|
||||||
|
}
|
||||||
|
|
||||||
|
textblockParam() {
|
||||||
|
if [ -z "$2" ]; then
|
||||||
|
# no default
|
||||||
|
printf "%s%s%s\n" "$cyan" "$1" "$norm"
|
||||||
|
else
|
||||||
|
# default param provided
|
||||||
|
printf "%s%s %s(%s)%s\n" "$cyan" "$1" "$yellow" "$2" "$norm"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
### pre-requisite checks
|
### pre-requisite checks
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user