From fc8b29443cabb2b62d5084ddee6742046f8de008 Mon Sep 17 00:00:00 2001 From: Jan-Philipp Litza Date: Tue, 14 Jun 2016 18:15:33 +0200 Subject: [PATCH] Use case statement instead of many if's --- example-dns-01-nsupdate-script.md | 36 +++++++++++++------------------ 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/example-dns-01-nsupdate-script.md b/example-dns-01-nsupdate-script.md index 40cd638..bfe9975 100644 --- a/example-dns-01-nsupdate-script.md +++ b/example-dns-01-nsupdate-script.md @@ -14,30 +14,24 @@ This hook script uses the nsupdate utility from the bind package to solve dns-01 set -e set -u set -o pipefail -umask 077 NSUPDATE="nsupdate -k /path/to/Kdnsupdatekey.private" -done="no" -if [[ "$1" = "deploy_challenge" ]]; then - printf "update add _acme-challenge.%s. 300 in TXT \"%s\"\n\n" "${2}" "${4}" | $NSUPDATE - done="yes" -fi - -if [[ "$1" = "clean_challenge" ]]; then - printf "update delete _acme-challenge.%s. 300 in TXT \"%s\"\n\n" "${2}" "${4}" | $NSUPDATE - done="yes" -fi - -if [[ "${1}" = "deploy_cert" ]]; then - # do nothing for now - done="yes" -fi - -if [[ ! "${done}" = "yes" ]]; then - echo Unkown hook "${1}" - exit 1 -fi +case "$1" in + "deploy_challenge") + printf "update add _acme-challenge.%s. 300 in TXT \"%s\"\n\n" "${2}" "${4}" | $NSUPDATE + ;; + "clean_challenge") + printf "update delete _acme-challenge.%s. 300 in TXT \"%s\"\n\n" "${2}" "${4}" | $NSUPDATE + ;; + "deploy_cert") + # do nothing for now + ;; + *) + echo Unkown hook "${1}" + exit 1 + ;; +esac exit 0 ``` \ No newline at end of file