-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathupload-unbound-config
executable file
·76 lines (62 loc) · 1.9 KB
/
upload-unbound-config
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/sh -e
# path of the file on each target server
CONFFILE='/etc/unbound/censura-new.conf'
# list of target servers
# do not waste too much time trying to connect to unresponsive remote servers
RSYNC_OPTIONS='--timeout=30 -rt'
# the local file
CONF='lists/unbound.conf'
# override the list of target servers
if [ "$1" ]; then
SERVERS="$1"
fi
##############################################################################
copy_config() {
local file="$1"
local server rc
rc=0
for server in $SERVERS; do
dprintf "Copying to $server...\n"
if rsync $RSYNC_OPTIONS $file $server:$CONFFILE; then
dprintf "Succesfully copied to $server.\n"
# this script dynamically updates the running configuration
if ssh $server unbound-update-censorship; then
dprintf "Configuration successfully reloaded on $server.\n\n"
else
printf "ERROR: the configuration has not been correctly reloaded on $server!\n\n" >&2
rc=1
fi
else
printf "ERROR: the configuration has not been correctly copied to $server!\n\n" >&2
rc=1
fi
done
return $rc
}
if [ -t 0 ]; then VERBOSE=1; fi
dprintf() {
[ "$VERBOSE" ] || return 0
printf "$*"
}
##############################################################################
# debugging
if [ "$PWD" = "/home/md/projects/kit-censura" ]; then
rsync() { echo "DEBUG: rsync $*"; }
ssh() { echo "DEBUG: ssh $*"; }
fi
##############################################################################
if cmp -s $CONF $CONF.new; then
# the new config file is unchanged, we are done
dprintf "$CONF is unchanged, exiting.\n"
exit 0
fi
dprintf "$CONF has changed.\n"
# copy unbound.conf to the servers
# rename the file only if everything was successful
if copy_config $CONF.new; then
cp -a $CONF.new $CONF
else
rm -f $CONF.new
fi
exit 0