-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoa
More file actions
executable file
·114 lines (95 loc) · 3.2 KB
/
Copy pathsoa
File metadata and controls
executable file
·114 lines (95 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
soa_usage() {
t=$([ -t 0 ] && echo true || echo false)
mdformat $t <<EOusage | ${PAGER:-cat}
**NAME**
${0##*/} - update SOA serial number in zonefile
**SYNOPSIS**
${0##*/} [**-vqdn**] _zonefile_
**DESCRIPTION**
Finds a zonefile's SOA record and updates the serial number
based on the current date, using the format YYYYMMDDII, where II
is 00 if the previous serial number was "older", or increments
by 1 if the old SOA matched the current date.
Options:
-h This help
-r RCSify the SOA file
-R Don't RCSify the SOA file
-v Verbose, default if on terminal
-q Quiet, default if not on terminal
-d Debug
-n Just show what we re doing, don't actually do it
It's likely you'd want to use -d and -n together when testing.
Quiet mode turns off debug. Last option wins.
RCS will be used automatically if the SOA file is RCSified and
checked in. This behiour is suppressed with **-R**. Specifying **-r**
will basically cause the update to fail if the file can't be
RCSified for some reason (tools not available, etc.) If the SOA
file is already checked out then it will not be checked in.
**EXAMPLES**
${0##*/} /etc/named/master/example.com.zonefile
**SEE ALSO**
EOusage
}
mdformat() {
local md so us mr me
local t="${1:-false}"
if "$t" || [ -t 1 ]; then
if [[ $(uname -s) = Linux ]]; then
# https://www.linuxcommand.org/lc3_adv_tput.php
md=$(tput -T "${TERM:-xterm}" bold) # bold
so=$(tput -T "${TERM:-xterm}" rev) # standout (inverse?)
us=$(tput -T "${TERM:-xterm}" smul) # underline
#mr=$(tput mr) # reverse
me=$(tput -T "${TERM:-xterm}" sgr0) # exit attributes
else
md=$(tput md) # bold
so=$(tput so) # standout (inverse?)
us=$(tput us) # underline
#mr=$(tput mr) # reverse
me=$(tput me) # exit attributes
fi
fi
sed -E \
-e "s/\*\*([^*]+)\*\*/$md\1$me/g" \
-e "s/\*([^*]+)\*/$us\1$me/g" \
-e "s/_([^_]+)_/$us\1$me/g" \
-e "s/^#+ *(.+)/$so\1$me/g" \
-e "s/#([^#]+)#/$mr\1$me/g"
}
Verbose=$([ -t 0 ] && echo true || echo false)
Quiet=false; Debug=false; Doit=true
while getopts hrRvqdn opt; do
case "$opt" in
h) soa_usage; exit 0 ;;
r) useRCS=true ;;
R) useRCS=false ;;
v) Verbose=true; Quiet=false ;;
q) Verbose=false; Quiet=true; Debug=false ;;
d) Verbose=true; Quiet=false; Debug=true ;;
n) Doit=false ;;
*) soa_usage; exit 64 ;;
esac
done
shift $((OPTIND - 1))
SOAfile="$1"
err=""
if [ -z "$SOAfile" ]; then
err="No file specified. -h for help"
elif [ ! -e "$SOAfile" ]; then
err="File not found: $SOAfile"
fi
if [ -n "$err" ]; then
printf 'ERROR: %s\n' "$err" >&2
exit 64
fi
read line soa < <(awk -v field=5 '/^@/ { if($2=="IN"){field++} if($6=="("){field++} for(i=1;i<field;i++){if(i==NF){field=field-NF;getline;i=1}} print NR,$field}' $SOAfile)
newsoa=$(date '+%Y%m%d00')
while [[ $((newsoa++)) -le "$soa" ]]; do :; done
printf -v cmd 'sed -i.bak -e "%ds/%s/%s/" "%s"' "$line" "$soa" "$newsoa" "$SOAfile"
#$Verbose && printf "%s: %s -> %s\n" "$SOAfile" "$soa" "$newsoa"
#$Debug && echo "sed -i.bak \"${line}s/$soa/$newsoa/\" \"$SOAfile\""
#$Doit && sed -i.bak "${line}s/$soa/$newsoa/" "$SOAfile"; then
$Verbose && printf "%s: %s -> %s\n" "$SOAfile" "$soa" "$newsoa"
$Debug && printf 'DEBUG: %s\n' "$cmd"
$Doit && eval $cmd