]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Fixing scripts/create-pdns-zones-from-files
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 18 Jan 2023 11:11:01 +0000 (12:11 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 18 Jan 2023 11:11:17 +0000 (12:11 +0100)
scripts/create-pdns-zones-from-files

index 0bee14f9d1e9e02df0497d9aacb70d65f8ce467a..03825ff74169b4ac719d6eefaac24d542b6683e4 100755 (executable)
@@ -3,13 +3,15 @@
 set -e
 set -u
 
-BASE_NAME="$( basename ${0} )"
-MY_REAL_NAME=$( readlink -f $0 )
+BASE_NAME="$( basename "${0}" )"
+MY_REAL_NAME=$( readlink -f "$0" )
+# shellcheck disable=SC2034
 BIN_DIR=$( dirname "${MY_REAL_NAME}" )
 
 RC_FILE='/usr/libexec/pixelpark/functions.rc'
 
 if [[ -f "${RC_FILE}" ]] ; then
+    # shellcheck disable=SC1090
     . "${RC_FILE}"
 else
     echo "Bash resource file '${RC_FILE}' not found" >&2
@@ -24,6 +26,7 @@ ERRORS="0"
 
 declare -a ZONE_FILES=()
 
+# shellcheck disable=SC2034
 DESCRIPTION=$( cat <<-EOF
        Creating zones from zone files on the local PowerDNS service.
 
@@ -56,12 +59,12 @@ usage() {
 get_options() {
 
     local tmp=
-    local base_dir=
 
     set +e
-    tmp=$( getopt -o ${STD_SHORT_OPTIONS}C: \
-                  --long ${STD_LONG_OPTIONS},customer:,tsig-key: \
+    tmp=$( getopt -o "${STD_SHORT_OPTIONS}C:" \
+                  --long "${STD_LONG_OPTIONS},customer:,tsig-key:" \
                   -n "${BASE_NAME}" -- "$@" )
+    # shellcheck disable=SC2181
     if [[ $? != 0 ]] ; then
         echo "" >&2
         usage >&2
@@ -84,17 +87,17 @@ get_options() {
 
     while [[ "$i" -lt "${len}" ]] ; do
 
-        j=$(( $i + 1 ))
+        j=$(( i + 1 ))
         arg="${REMAINING_OPTS[$i]}"
 
         case "${arg}" in
             -C|--customer)
                 CUSTOMER="${REMAINING_OPTS[$j]}"
-                i=$(( $i + 2 ))
+                i=$(( i + 2 ))
                 ;;
             --tsig-key)
                 TSIG_KEY="${REMAINING_OPTS[$j]}"
-                i=$(( $i + 2 ))
+                i=$(( i + 2 ))
                 ;;
             *)  echo -e "Internal error - option '${RED}${arg}${NORMAL} was wrong!"
                 exit 1
@@ -122,7 +125,7 @@ get_options() {
         if [[ "${i}" == "0" && "${arg}" == '--' ]] ; then
             continue
         fi
-        i=$(( $i + 1 ))
+        i=$(( i + 1 ))
         ZONE_FILES+=( "${arg}" )
     done
 
@@ -155,7 +158,8 @@ get_options() {
         fi
     done
 
-    local pong=$( pdns_control rping | tr '[:upper:]' '[:lower:]' || true )
+    local pong=
+    pong=$( pdns_control rping | tr '[:upper:]' '[:lower:]' || true )
     if [[ "${pong}" != 'pong' ]] ; then
         error "The PowerDNS server service seems not to be active and running."
         exit 2
@@ -168,20 +172,22 @@ create_zone() {
 
     local zone_file="$1"
 
-    local zone=$( grep -P -i '^\S+\s+\d+\s+IN\s+SOA\s' "${zone_file}" | \
-                  grep -P -o '^(\S+)' | \
-                  sed -e 's/\.*$//' )
+    local zone=
+    zone=$( grep -P -i '^\S+\s+(\d+\s+)?IN\s+SOA\s' "${zone_file}" | \
+            grep -P -o '^(\S+)' | \
+            sed -e 's/\.*$//' )
 
     if [[ -z "${zone}" ]] ; then
         error "Did not found a valid SOA record in zone file '${RED}${zone_file}${NORMAL}'."
-        ERRORS=$(( $ERRORS + 1 ))
+        ERRORS=$(( ERRORS + 1 ))
         return
     fi
 
-    local existing=$( pdnsutil list-zone "${zone}" 2>/dev/null || true )
+    local existing=
+    existing=$( pdnsutil list-zone "${zone}" 2>/dev/null || true )
     if [[ -n "${existing}" ]] ; then
         error "Zone '${RED}${zone}${NORMAL}' is already existing in PowerDNS."
-        ERRORS=$(( $ERRORS + 1 ))
+        ERRORS=$(( ERRORS + 1 ))
         return
     fi
 
@@ -197,6 +203,8 @@ create_zone() {
         info "Executing: ${cmd}"
     else
         debug "Executing: ${cmd}"
+        # shellcheck disable=SC2086
+        eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful'
     fi
 
     cmd="pdnsutil set-account \"${zone}\" \"${CUSTOMER}\""
@@ -204,6 +212,8 @@ create_zone() {
         info "Executing: ${cmd}"
     else
         debug "Executing: ${cmd}"
+        # shellcheck disable=SC2086
+        eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful'
     fi
 
     cmd="pdnsutil set-kind \"${zone}\" \"master\""
@@ -211,6 +221,8 @@ create_zone() {
         info "Executing: ${cmd}"
     else
         debug "Executing: ${cmd}"
+        # shellcheck disable=SC2086
+        eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful'
     fi
 
     cmd="pdnsutil set-meta \"${zone}\" \"SOA-EDIT-API\" \"DEFAULT\""
@@ -218,6 +230,8 @@ create_zone() {
         info "Executing: ${cmd}"
     else
         debug "Executing: ${cmd}"
+        # shellcheck disable=SC2086
+        eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful'
     fi
 
     cmd="pdnsutil set-meta \"${zone}\" \"TSIG-ALLOW-AXFR\" \"${TSIG_KEY}\""
@@ -225,6 +239,8 @@ create_zone() {
         info "Executing: ${cmd}"
     else
         debug "Executing: ${cmd}"
+        # shellcheck disable=SC2086
+        eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful'
     fi
 
 }