aboutsummaryrefslogtreecommitdiffstats
path: root/painless-le.sh
diff options
context:
space:
mode:
authorThomas Lange <code@nerdmind.de>2016-12-22 03:45:07 +0100
committerThomas Lange <code@nerdmind.de>2016-12-22 03:45:07 +0100
commitd9778c52bb81490596591a9763c9654de4ecf39a (patch)
tree32690fea4af464975a8e2de8a2ea38ef1887a580 /painless-le.sh
parent3823bca2fd8ef55d5c197abf306b4ea56eb5b5d5 (diff)
downloadpainlessle-d9778c52bb81490596591a9763c9654de4ecf39a.tar.gz
painlessle-d9778c52bb81490596591a9763c9654de4ecf39a.tar.xz
painlessle-d9778c52bb81490596591a9763c9654de4ecf39a.zip
Parsing command-line arguments with the getopts shell builtin.
Diffstat (limited to 'painless-le.sh')
-rwxr-xr-xpainless-le.sh25
1 files changed, 22 insertions, 3 deletions
diff --git a/painless-le.sh b/painless-le.sh
index efd0bc2..160f5a8 100755
--- a/painless-le.sh
+++ b/painless-le.sh
@@ -13,8 +13,27 @@
# #
#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
-[ -z "$1" ] && echo 'Missing argument $1' && exit 1 || ARGUMENT_DIRECTORY="$1"
-[ -z "$2" ] && echo 'Missing argument $2' && exit 1 || ARGUMENT_HOSTNAMES="$2"
+#===============================================================================
+# Parsing command-line arguments with the getopts shell builtin
+#===============================================================================
+while getopts :i:h: opt
+do
+ case $opt in
+ i) ARGUMENT_DIRECTORY="$OPTARG" ;;
+ h) ARGUMENT_HOSTNAMES="$OPTARG" ;;
+ esac
+done
+
+#===============================================================================
+# Checking if all required command-line arguments are provided
+#===============================================================================
+[ -z "${ARGUMENT_DIRECTORY}" ] && echo "$0: Missing argument: [-i directory]" >&2
+[ -z "${ARGUMENT_HOSTNAMES}" ] && echo "$0: Missing argument: [-h hostnames]" >&2
+
+#===============================================================================
+# Abort execution if required command-line argument is missing
+#===============================================================================
+[ -z "${ARGUMENT_DIRECTORY}" ] || [ -z "${ARGUMENT_HOSTNAMES}" ] && exit 1
#===============================================================================
# Define the ACME endpoint address
@@ -48,7 +67,7 @@ openssl req -config <(cat "${OPENSSLCONF}" <(printf "[SAN]\nsubjectAltName=DNS:`
# Checking if Certificate-Signing-Request (CSR) was successfully created
#===============================================================================
if [ $? != 0 ]; then
- echo "[ABORTING]: Certificate-Signing-Request (CSR) could not be created!"
+ echo "$0: Certificate-Signing-Request (CSR) could not be created!" >&2
exit 1
fi