From a9ffc08e747e8cc76d0bf45db0d86f5277d6ea78 Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Sun, 30 Apr 2023 16:48:15 -0700 Subject: [PATCH] use "fail" to print/exit 1 --- ddns.sh | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/ddns.sh b/ddns.sh index 6559a7d..eae9bf0 100755 --- a/ddns.sh +++ b/ddns.sh @@ -19,10 +19,7 @@ CONFIG="${1:-}" PROVIDER= IP_ADDRESS="${IP_ADDRESS:-}" -if [ -z "$IP_ADDRESS" ]; then - echo "error: IP_ADDRESS variable is unset" - exit 1 -fi +[ -n "$IP_ADDRESS" ] || fail "error: IP_ADDRESS variable is unset" [ -z "$CONFIG" ] && usage # shellcheck source=/dev/null @@ -59,23 +56,19 @@ luadns() { local _zone_id # shellcheck disable=SC2016 _zone_id="$(echo "$_zones" | gojq --arg domain "$DOMAIN" ' .[] | select(.name==$domain) | .["id"] ' )" - [ -z "$_zone_id" ] && \ - ( echo "error: unable to get zone ID for $DOMAIN"; exit 1) + [ -n "$_zone_id" ] || fail "error: unable to get zone ID for $DOMAIN" local _zone _zone="$(luadns_get zones/"$_zone_id")" - [ -z "$_zone" ] && \ - ( echo "error: unable to get zone info for $DOMAIN"; exit 1) + [ -n "$_zone" ] || fail "error: unable to get zone info for $DOMAIN" local _dns_ip _dns_ip="$(echo "$_zone" | gojq '.["records"] | .[] | select(.type=="A") | .["content"] ' | sed 's|"||g' )" - [ -z "$_dns_ip" ] && \ - ( echo "error: unable to determine DNS IP for $DOMAIN"; exit 1) + [ -n "$_dns_ip" ] || fail "error: unable to determine DNS IP for $DOMAIN" local _record_id _record_id="$(echo "$_zone" | gojq '.["records"] | .[] | select(.type=="A") | .["id"] ' )" - [ -z "$_record_id" ] && \ - ( echo "error: unable to determine record ID"; exit 1) + [ -n "$_record_id" ] || fail "error: unable to determine record ID" if [ "$_dns_ip" != "$IP_ADDRESS" ]; then echo "IP in DNS is *not* expected ($_dns_ip), updating to $IP_ADDRESS" @@ -91,7 +84,6 @@ case "$PROVIDER" in luadns ;; *) - echo "unknown provider: $PROVIDER" - exit 1 + fail "error: unknown provider: $PROVIDER" ;; esac -- 2.45.2