From 35215a4678627f29fe791d51e71d5cc0dd4840f7 Mon Sep 17 00:00:00 2001 From: Thomas Lange Date: Tue, 1 Nov 2022 20:38:08 +0100 Subject: Process command-line options without getopts The "getopts" shell built-in works perfectly with short options but does not support long options, unfortunately. To be more flexible when adding new options, get rid of "getopts" and use a traditional loop instead. --- package/sbin/painless-le | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/package/sbin/painless-le b/package/sbin/painless-le index 2a0a75f..177662d 100755 --- a/package/sbin/painless-le +++ b/package/sbin/painless-le @@ -22,28 +22,28 @@ #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%# #=============================================================================== -# Define ACME endpoint address and BEFORE/AFTER commands +# Define ACME endpoint URL #=============================================================================== ACME_ENDPOINT="https://acme-v02.api.letsencrypt.org/directory" #ACME_ENDPOINT="https://acme-staging-v02.api.letsencrypt.org/directory" #=============================================================================== -# Normalize command-line arguments with GNU getopt +# Normalize command-line argument string #=============================================================================== eval set -- "$(getopt -o K:I:C:F: -- "$@")" #=============================================================================== -# Parse command-line options with getopts +# Parse command-line options #=============================================================================== -while getopts :K:I:C:F: option -do - case $option in - K) OPT_CONFIDENTIAL="$OPTARG" ;; - I) OPT_INTERMEDIATE="$OPTARG" ;; - C) OPT_CERTIFICATE_ONLY="$OPTARG" ;; - F) OPT_CERTIFICATE_FULL="$OPTARG" ;; +while true; do + case "$1" in + -K) OPT_CONFIDENTIAL="$2"; shift 2;; + -I) OPT_INTERMEDIATE="$2"; shift 2;; + -C) OPT_CERTIFICATE_ONLY="$2"; shift 2;; + -F) OPT_CERTIFICATE_FULL="$2"; shift 2;; + --) shift; break;; esac -done; shift $((OPTIND-1)) +done #=============================================================================== # Set positional argument variables -- cgit v1.2.3