-
Notifications
You must be signed in to change notification settings - Fork 2
/
update_serial.example
executable file
·87 lines (69 loc) · 1.75 KB
/
update_serial.example
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
#!/bin/bash
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
# more details.
#
# You should have received a copy of the GNU General Public License version 3
# along with this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# (c) 2016 Valentin Samir
next=0
for args in "$@"; do
if [ $next -ge 1 ]; then
view=$args
next=0
fi
if [[ "$args" = "--view" ]]; then
next=1
fi
done
if [ -z "$view" ]; then
view="internet"
fi
if [[ "$1" = "--view" ]]; then
shift 2
fi
if [ -z "$1" ]; then
echo "Usage: $0 (zone_name) [zone_name] [...] [--view view_name]"
exit 1
fi
echo Using view $view
while [ -n "$1" ]; do
file=$(echo /etc/bind/zones/db.$1)
if [ ! -f "$file" ]; then
echo "File $file not found"
exit 1
fi
/usr/sbin/rndc freeze $1 IN $view &>/dev/null
serial=$(grep '[0-9]\{10\}' "$file" | head -n 1 | awk '{print $1}')
if [ -z "$serial" ]; then
echo "Serial not found"
exit 1
fi
if [ ${#serial} -ne 10 ]; then
echo "Bad serial $serial should be of length 10"
exit 1
fi
today=$(date +%Y%m%d)
serial_date=${serial:0:8}
serial_id=$(echo ${serial:8} | sed 's/^0*//')
if [ "$serial_id" = "99" ]; then
echo "Maximum serial reach for today"
exit 1
fi
if [ $today = $serial_date ]; then
new_id=$(printf "%02d" $((serial_id + 1)))
else
new_id="01"
fi
sed -i "s/$serial/$today$new_id/" "$file"
/usr/sbin/rndc thaw $1 IN $view
echo -n "$1: "
/usr/sbin/rndc reload $1 IN $view
shift
if [[ "$1" = "--view" ]]; then
shift 2
fi
done