From f3d2ea2fbb347a9ebf1101dd5991e78895bc918b Mon Sep 17 00:00:00 2001 From: Staf Wagemakers Date: Sun, 17 Oct 2021 10:29:17 +0200 Subject: [PATCH] Skip chown/chmod argument added * -s Skip chown/chmod argument added * Improved Error handeling --- scripts/create_zone_config.sh | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/scripts/create_zone_config.sh b/scripts/create_zone_config.sh index 0eb76f2..38da019 100755 --- a/scripts/create_zone_config.sh +++ b/scripts/create_zone_config.sh @@ -1,8 +1,10 @@ #!/bin/bash -# creates zones.conf -set -e +set -o errexit +set -o pipefail +set -o nounset +# creates zones.conf usage() { echo >&2 echo >&2 "Usage: $(basename $0)" @@ -14,16 +16,17 @@ usage() { echo >&2 " -d Default: /etc/unbound/zones/" echo >&2 " The zones data source files" echo >&2 " -p Default: the realpath of zone files " + echo >&2 " -s Skip chown/chmod" echo >&2 exit 1 } - UnboundZoneCfg="/etc/unbound/unbound.conf.d/zones.conf" ZoneDataDir="/etc/unbound/zones/" ZonesPath="" +SkipPerms="" -while getopts “hd:f:p:” OPTION; do +while getopts “hsd:f:p:” OPTION; do case $OPTION in f) UnboundZoneCfg=$OPTARG @@ -34,6 +37,9 @@ while getopts “hd:f:p:” OPTION; do p) ZonesPath=$(echo $OPTARG | sed -e 's@/$@@') ;; + s) + SkipPerms=1 + ;; h) usage ;; @@ -77,7 +83,6 @@ while read zoneFile; do zoneFile="${ZonesPath}/${zoneBaseFile}" fi - echo "auth-zone:" >> $UnboundZoneCfg echo " name: $origin" >> $UnboundZoneCfg echo " zonefile: $zoneFile" >> $UnboundZoneCfg @@ -85,5 +90,7 @@ while read zoneFile; do done < <(find "$ZoneDataDir" -name "*.zone") -chown root:5000153 $UnboundZoneCfg -chmod 640 $UnboundZoneCfg +if [ "$SkipPerms" != "1" ]; then + chown root:5000153 $UnboundZoneCfg + chmod 640 $UnboundZoneCfg +fi