-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-old-keys
executable file
·76 lines (56 loc) · 1.14 KB
/
delete-old-keys
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
#!/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"
}
trap finish EXIT
cd /var/named
[ -d "$DNSSEC_KEY_DIR" ] || exit 0
FILES="$(find "$DNSSEC_KEY_DIR" -type f -name K\*)"
IGNORE=()
SAFE=()
DELETE=()
DATE_NOW=${1:-$(date "+%Y%m%d%H%M%S")}
for f in $FILES; do
EXPIRY=$(awk '/Delete/{ print $3 ? $3 : $2 }' $f)
if [ -z "$EXPIRY" ]; then
IGNORE+=($f)
continue
fi
if [ $DATE_NOW -gt $EXPIRY ]; then
DELETE+=($f)
else
SAFE+=($f)
fi
done
log_info "Delete old keys"
if [ ${#SAFE[@]} -gt 0 ]; then
echo "Safe:"
for f in ${SAFE[@]}; do
echo -e "\t$f"
done
fi
if [ ${#IGNORE[@]} -gt 0 ]; then
echo "Ignore:"
for f in ${IGNORE[@]}; do
echo -e "\t$f"
done
fi
if [ ${#DELETE[@]} -gt 0 ]; then
log_warning "Delete:"
for f in ${DELETE[@]}; do
log_warning "\t$f"
rm --force "$f"
done
fi