From: Frank Brehm Date: Wed, 18 Jan 2023 11:11:01 +0000 (+0100) Subject: Fixing scripts/create-pdns-zones-from-files X-Git-Tag: 0.8.1^2~1 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=85e2966a6a75467b4d3b46c693fa671be4f9cb76;p=pixelpark%2Fpp-admin-tools.git Fixing scripts/create-pdns-zones-from-files --- diff --git a/scripts/create-pdns-zones-from-files b/scripts/create-pdns-zones-from-files index 0bee14f..03825ff 100755 --- a/scripts/create-pdns-zones-from-files +++ b/scripts/create-pdns-zones-from-files @@ -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 }