refactor(SCRIPT): replace in-line printf styles
This commit is contained in:
parent
b617b7e633
commit
5a313ea778
60
ab-nginx.sh
60
ab-nginx.sh
@ -21,7 +21,6 @@ else
|
|||||||
width=80
|
width=80
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
### parameter defaults
|
### parameter defaults
|
||||||
shell=false
|
shell=false
|
||||||
container_name="ab-nginx"
|
container_name="ab-nginx"
|
||||||
@ -34,18 +33,17 @@ unset SERVERS_DIR
|
|||||||
unset WEBROOT_DIR
|
unset WEBROOT_DIR
|
||||||
unset vmount
|
unset vmount
|
||||||
|
|
||||||
|
|
||||||
### functions
|
### functions
|
||||||
|
|
||||||
checkExist() {
|
checkExist() {
|
||||||
if [ "$1" = 'file' ]; then
|
if [ "$1" = 'file' ]; then
|
||||||
if [ ! -f "$2" ]; then
|
if [ ! -f "$2" ]; then
|
||||||
printf "${err}\nCannot find file: '$2'. Exiting.\n${norm}"
|
printf "%s\nCannot find file: '$2'. Exiting.\n%s" "$err" "$norm"
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
elif [ "$1" = 'dir' ]; then
|
elif [ "$1" = 'dir' ]; then
|
||||||
if [ ! -d "$2" ]; then
|
if [ ! -d "$2" ]; then
|
||||||
printf "${err}\nCannot find directory: '$2'. Exiting.\n${norm}"
|
printf "%s\nCannot find directory: '$2'. Exiting.\n$%s" "$err" "$norm"
|
||||||
exit 3
|
exit 3
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -95,13 +93,12 @@ textblockParam() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
### pre-requisite checks
|
### pre-requisite checks
|
||||||
|
|
||||||
# is user root or in the docker group?
|
# is user root or in the docker group?
|
||||||
if [ ! "$(id -u)" -eq 0 ]; then
|
if [ ! "$(id -u)" -eq 0 ]; then
|
||||||
if ! id -Gn | grep docker >/dev/null; then
|
if ! id -Gn | grep docker >/dev/null; then
|
||||||
printf "${err}\nYou must either be root or in the 'docker' group to run this script since you must be able to actually start the container! Exiting.\n${norm}"
|
printf "%s\nYou must either be root or in the 'docker' group to run this script since you must be able to actually start the container! Exiting.\n$%s" "$err" "$norm"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -110,7 +107,7 @@ fi
|
|||||||
checkExist 'file' './ab-nginx.params'
|
checkExist 'file' './ab-nginx.params'
|
||||||
|
|
||||||
# read .params file
|
# read .params file
|
||||||
. ./ab-nginx.params
|
. "./ab-nginx.params"
|
||||||
|
|
||||||
# fix case of TLS13_ONLY var
|
# fix case of TLS13_ONLY var
|
||||||
if [ "$TLS13_ONLY" ]; then
|
if [ "$TLS13_ONLY" ]; then
|
||||||
@ -125,7 +122,7 @@ if [ "$SSL_CHAIN" ]; then checkExist 'file' "$SSL_CHAIN"; fi
|
|||||||
# check for DHparam if using TLS1.2
|
# check for DHparam if using TLS1.2
|
||||||
if [ "$TLS13_ONLY" = 'FALSE' ]; then
|
if [ "$TLS13_ONLY" = 'FALSE' ]; then
|
||||||
if [ -z "$DH" ]; then
|
if [ -z "$DH" ]; then
|
||||||
printf "${err}\nA DHparam file must be specified when using TLS 1.2. Exiting.${norm}\n"
|
printf "%s\nA DHparam file must be specified when using TLS 1.2. Exiting.%s\n" "$err" "$norm"
|
||||||
exit 5
|
exit 5
|
||||||
else
|
else
|
||||||
checkExist 'file' "$DH"
|
checkExist 'file' "$DH"
|
||||||
@ -163,7 +160,6 @@ fi
|
|||||||
# trim leading whitespace
|
# trim leading whitespace
|
||||||
vmount=${vmount##[[:space:]]}
|
vmount=${vmount##[[:space:]]}
|
||||||
|
|
||||||
|
|
||||||
# process startup parameters
|
# process startup parameters
|
||||||
while [ $# -gt 0 ]; do
|
while [ $# -gt 0 ]; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -179,15 +175,15 @@ while [ $# -gt 0 ]; do
|
|||||||
-n | --name)
|
-n | --name)
|
||||||
# container name
|
# container name
|
||||||
if [ -z "$2" ]; then
|
if [ -z "$2" ]; then
|
||||||
printf "${err}\nNo container name specified. Exiting.\n${norm}"
|
printf "%s\nNo container name specified. Exiting.\n%s" "$err" "$norm"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
container_name="$2"
|
container_name="$2"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
printf "${err}\nUnknown option: %s\n" "$1"
|
printf "%s\nUnknown option: %s\n" "$err" "$1"
|
||||||
printf "Use '--help' for valid options.\n\n${norm}"
|
printf "Use '--help' for valid options.\n\n%s" "$norm"
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -195,33 +191,32 @@ while [ $# -gt 0 ]; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# create network if it doesn't already exist
|
# create network if it doesn't already exist
|
||||||
docker network inspect ${NETWORK} > /dev/null 2>&1 || \
|
docker network inspect ${NETWORK} >/dev/null 2>&1 ||
|
||||||
docker network create \
|
docker network create \
|
||||||
--attachable \
|
--attachable \
|
||||||
--driver=bridge \
|
--driver=bridge \
|
||||||
--subnet=${SUBNET} \
|
--subnet=${SUBNET} \
|
||||||
${NETWORK}
|
${NETWORK}
|
||||||
|
|
||||||
|
|
||||||
# run without TLS
|
# run without TLS
|
||||||
if [ -z "$SSL_CERT" ]; then
|
if [ -z "$SSL_CERT" ]; then
|
||||||
if [ $shell = 'true' ]; then
|
if [ $shell = 'true' ]; then
|
||||||
# exec shell
|
# exec shell
|
||||||
printf "${cyan}\nRunning SHELL on %s...${norm}\n" "$container_name"
|
printf "%s\nRunning SHELL on %s...%s\n" "$cyan" "$container_name" "$norm"
|
||||||
docker run --rm -it --name ${container_name} \
|
docker run --rm -it --name "${container_name}" \
|
||||||
--env-file ab-nginx.params \
|
--env-file ab-nginx.params \
|
||||||
-e SERVER_NAMES="$HOSTNAMES" \
|
-e SERVER_NAMES="$HOSTNAMES" \
|
||||||
$vmount \
|
"${vmount}" \
|
||||||
--network=${NETWORK} \
|
--network=${NETWORK} \
|
||||||
-p ${HTTP_PORT}:80 \
|
-p ${HTTP_PORT}:80 \
|
||||||
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
|
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
|
||||||
else
|
else
|
||||||
# exec normally
|
# exec normally
|
||||||
printf "${cyan}\nRunning NGINX on %s...${norm}\n" "$container_name"
|
printf "%s\nRunning NGINX on %s...%s\n" "$cyan" "$container_name" "$norm"
|
||||||
docker run -d --name ${container_name} \
|
docker run -d --name "${container_name}" \
|
||||||
--env-file ab-nginx.params \
|
--env-file ab-nginx.params \
|
||||||
-e SERVER_NAMES="$HOSTNAMES" \
|
-e SERVER_NAMES="$HOSTNAMES" \
|
||||||
$vmount \
|
"${vmount}" \
|
||||||
--network=${NETWORK} \
|
--network=${NETWORK} \
|
||||||
-p ${HTTP_PORT}:80 \
|
-p ${HTTP_PORT}:80 \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
@ -231,11 +226,11 @@ if [ -z "$SSL_CERT" ]; then
|
|||||||
elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'FALSE' ]; then
|
elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'FALSE' ]; then
|
||||||
if [ $shell = 'true' ]; then
|
if [ $shell = 'true' ]; then
|
||||||
# exec shell
|
# exec shell
|
||||||
printf "${cyan}\nRunning SHELL on %s (TLS 1.2)...${norm}\n" "$container_name"
|
printf "%s\nRunning SHELL on %s (TLS 1.2)...%s\n" "$cyan" "$container_name" "$norm"
|
||||||
docker run --rm -it --name ${container_name} \
|
docker run --rm -it --name "${container_name}" \
|
||||||
--env-file ab-nginx.params \
|
--env-file ab-nginx.params \
|
||||||
-e SERVER_NAMES="$HOSTNAMES" \
|
-e SERVER_NAMES="$HOSTNAMES" \
|
||||||
$vmount \
|
"${vmount}" \
|
||||||
--network=${NETWORK} \
|
--network=${NETWORK} \
|
||||||
-v "$SSL_CERT":/certs/fullchain.pem:ro \
|
-v "$SSL_CERT":/certs/fullchain.pem:ro \
|
||||||
-v "$SSL_KEY":/certs/privkey.pem:ro \
|
-v "$SSL_KEY":/certs/privkey.pem:ro \
|
||||||
@ -245,11 +240,11 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'FALSE' ]; then
|
|||||||
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
|
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
|
||||||
else
|
else
|
||||||
# exec normally
|
# exec normally
|
||||||
printf "${cyan}\nRunning NGINX on %s (TLS 1.2)...${norm}\n" "$container_name"
|
printf "%s\nRunning NGINX on %s (TLS 1.2)...%s\n" "$cyan" "$container_name" "$norm"
|
||||||
docker run -d --name ${container_name} \
|
docker run -d --name "${container_name}" \
|
||||||
--env-file ab-nginx.params \
|
--env-file ab-nginx.params \
|
||||||
-e SERVER_NAMES="$HOSTNAMES" \
|
-e SERVER_NAMES="$HOSTNAMES" \
|
||||||
$vmount \
|
"${vmount}" \
|
||||||
--network=${NETWORK} \
|
--network=${NETWORK} \
|
||||||
-v "$SSL_CERT":/certs/fullchain.pem:ro \
|
-v "$SSL_CERT":/certs/fullchain.pem:ro \
|
||||||
-v "$SSL_KEY":/certs/privkey.pem:ro \
|
-v "$SSL_KEY":/certs/privkey.pem:ro \
|
||||||
@ -263,11 +258,11 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'FALSE' ]; then
|
|||||||
elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'TRUE' ]; then
|
elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'TRUE' ]; then
|
||||||
if [ $shell = 'true' ]; then
|
if [ $shell = 'true' ]; then
|
||||||
# exec shell
|
# exec shell
|
||||||
printf "${cyan}\nRunning SHELL on %s (TLS 1.3)...${norm}\n" "$container_name"
|
printf "%s\nRunning SHELL on %s (TLS 1.3)...%s\n" "$cyan" "$container_name" "$norm"
|
||||||
docker run --rm -it --name ${container_name} \
|
docker run --rm -it --name "${container_name}" \
|
||||||
--env-file ab-nginx.params \
|
--env-file ab-nginx.params \
|
||||||
-e SERVER_NAMES="$HOSTNAMES" \
|
-e SERVER_NAMES="$HOSTNAMES" \
|
||||||
$vmount \
|
"${vmount}" \
|
||||||
--network=${NETWORK} \
|
--network=${NETWORK} \
|
||||||
-v "$SSL_CERT":/certs/fullchain.pem:ro \
|
-v "$SSL_CERT":/certs/fullchain.pem:ro \
|
||||||
-v "$SSL_KEY":/certs/privkey.pem:ro \
|
-v "$SSL_KEY":/certs/privkey.pem:ro \
|
||||||
@ -276,11 +271,11 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'TRUE' ]; then
|
|||||||
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
|
docker.asifbacchus.app/nginx/ab-nginx:latest /bin/sh
|
||||||
else
|
else
|
||||||
# exec normally
|
# exec normally
|
||||||
printf "${cyan}\nRunning NGINX on %s (TLS 1.3)...${norm}\n" "$container_name"
|
printf "%s\nRunning NGINX on %s (TLS 1.3)...%s\n" "$cyan" "$container_name" "$norm"
|
||||||
docker run -d --name ${container_name} \
|
docker run -d --name "${container_name}" \
|
||||||
--env-file ab-nginx.params \
|
--env-file ab-nginx.params \
|
||||||
-e SERVER_NAMES="$HOSTNAMES" \
|
-e SERVER_NAMES="$HOSTNAMES" \
|
||||||
$vmount \
|
"${vmount}" \
|
||||||
--network=${NETWORK} \
|
--network=${NETWORK} \
|
||||||
-v "$SSL_CERT":/certs/fullchain.pem:ro \
|
-v "$SSL_CERT":/certs/fullchain.pem:ro \
|
||||||
-v "$SSL_KEY":/certs/privkey.pem:ro \
|
-v "$SSL_KEY":/certs/privkey.pem:ro \
|
||||||
@ -291,6 +286,5 @@ elif [ "$SSL_CERT" ] && [ "$TLS13_ONLY" = 'TRUE' ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
### exit gracefully
|
### exit gracefully
|
||||||
exit 0
|
exit 0
|
Loading…
Reference in New Issue
Block a user