Skip to content

Commit

Permalink
Skip chown/chmod argument added
Browse files Browse the repository at this point in the history
* -s Skip chown/chmod argument added
* Improved Error handeling
  • Loading branch information
stafwag committed Oct 17, 2021
1 parent 8207d1e commit f3d2ea2
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions scripts/create_zone_config.sh
Original file line number Diff line number Diff line change
@@ -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)"
Expand All @@ -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 getoptshd:f:p:” OPTION; do
while getoptshsd:f:p:” OPTION; do
case $OPTION in
f)
UnboundZoneCfg=$OPTARG
Expand All @@ -34,6 +37,9 @@ while getopts “hd:f:p:” OPTION; do
p)
ZonesPath=$(echo $OPTARG | sed -e 's@/$@@')
;;
s)
SkipPerms=1
;;
h)
usage
;;
Expand Down Expand Up @@ -77,13 +83,14 @@ while read zoneFile; do
zoneFile="${ZonesPath}/${zoneBaseFile}"
fi


echo "auth-zone:" >> $UnboundZoneCfg
echo " name: $origin" >> $UnboundZoneCfg
echo " zonefile: $zoneFile" >> $UnboundZoneCfg
echo >> $UnboundZoneCfg

done < <(find "$ZoneDataDir" -name "*.zone")

chown root:5000153 $UnboundZoneCfg
chmod 640 $UnboundZoneCfg
if [ "$SkipPerms" != "1" ]; then
chown root:5000153 $UnboundZoneCfg
chmod 640 $UnboundZoneCfg
fi

0 comments on commit f3d2ea2

Please sign in to comment.