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
declare -a ZONE_FILES=()
+# shellcheck disable=SC2034
DESCRIPTION=$( cat <<-EOF
Creating zones from zone files on the local PowerDNS service.
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
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
if [[ "${i}" == "0" && "${arg}" == '--' ]] ; then
continue
fi
- i=$(( $i + 1 ))
+ i=$(( i + 1 ))
ZONE_FILES+=( "${arg}" )
done
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
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
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}\""
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\""
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\""
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}\""
info "Executing: ${cmd}"
else
debug "Executing: ${cmd}"
+ # shellcheck disable=SC2086
+ eval ${cmd} 2>&1 | grep -vi 'gpgsql Connection successful'
fi
}