-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdate-serials
executable file
·85 lines (65 loc) · 1.42 KB
/
update-serials
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
#!/bin/bash
# Copyright 2014-2015 Richard Russon (FlatCap)
# Licensed under the GPLv3
PATH="/var/named/bin:/usr/bin:/usr/sbin"
source log.sh
export TZ="UTC"
set -o errexit # set -e
set -o nounset # set -u
renice --priority 19 --pid $$ > /dev/null
ionice --class 3 --pid $$ > /dev/null
shopt -s nullglob
function finish()
{
local RETVAL=$?
[ $RETVAL = 0 ] || log_error "${0##*/} failed: $RETVAL"
}
function usage()
{
echo "Usage: ${0##*/} [zonefile...]"
exit 1
}
cd /var/named
trap finish EXIT
if [ $# = 0 ]; then
FILE_LIST=(*.db)
if [ ${#FILE_LIST[@]} = 0 ]; then
echo "No zone files"
exit 1
fi
DATE=""
else
if [ "$1" = "-d" -a $# -gt 1 ]; then
DATE="$2"
shift 2
fi
for i in "$@"; do
if [ -f "$i.db" ]; then
FILE_LIST=($i.db)
else
echo "Zone file doesn't exist: $i.db"
exit 1
fi
done
fi
SERIAL="${DATE:-$(date '+%Y%m%d')}00"
for FILE in ${FILE_LIST[@]}; do
if [ ! -s "$FILE" ]; then
echo "File doesn't exist: $FILE"
continue
fi
ZONE="${FILE%.db}"
ZONE_SERIAL=$(/usr/sbin/named-checkzone $ZONE $FILE | grep --extended-regexp --no-filename --only-matching '[0-9]{10}')
if [ -z "$ZONE_SERIAL" ]; then
echo "Bad zone file: $FILE"
exit 1
fi
[ $ZONE_SERIAL -gt $SERIAL ] && SERIAL=$ZONE_SERIAL
done
: $((SERIAL++))
log_info "Update zone file serial numbers"
for FILE in ${FILE_LIST[@]}; do
ZONE="${FILE%.db}"
sed -i "s/\<[0-9]\{10\}\>/$SERIAL/" $FILE
echo -e "\t$ZONE" "$SERIAL"
done