author | Tero Marttila <terom@paivola.fi> |
Sun, 22 Dec 2013 15:33:32 +0200 | |
changeset 98 | a3734856e0fa |
parent 95 | a756f317d083 |
child 100 | 44c32fd60997 |
permissions | -rwxr-xr-x |
2 | 1 |
#!/bin/bash |
2 |
# vim: set ft=sh : |
|
3 |
||
94
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
4 |
# Bootstrap |
82 | 5 |
if [ $0 == './update' ]; then |
6 |
SRV=$(pwd) |
|
7 |
OPT=./opt |
|
8 |
else |
|
9 |
SRV=${SRV:-/srv/dns} |
|
10 |
OPT=${SRV:-/srv/dns/opt} |
|
11 |
cd $SRV |
|
12 |
fi |
|
2 | 13 |
|
82 | 14 |
source lib/update |
44 | 15 |
|
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
16 |
function commit { |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
17 |
## Commit |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
18 |
# pre-commit check |
13 | 19 |
log "Testing hosts..." |
82 | 20 |
for hosts in $(list_files etc/hosts); do |
21 |
log_warn "TODO: check_hosts $hosts" |
|
22 |
done |
|
36
3208cd6540dc
update: restructure zones/, manage .pvl
Tero Marttila <terom@paivola.fi>
parents:
32
diff
changeset
|
23 |
|
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
24 |
# commit, unless noop'd |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
25 |
log "Commit..." |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
26 |
update_commit etc |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
27 |
} |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
28 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
29 |
function update { |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
30 |
if hg_modified etc; then |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
31 |
serial=$(unix_time) |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
32 |
log_warn "Using local unix time for uncommited changes: $serial" |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
33 |
else |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
34 |
serial=$(hg_time etc) |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
35 |
log_update "Using HG commit timestamp: $serial" |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
36 |
fi |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
37 |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
87
diff
changeset
|
38 |
## Hosts |
84
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
39 |
log "Updating forward host zones..." |
93
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
40 |
for zone in $(list_dirs etc/hosts/forward); do |
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
41 |
update_hosts_forward "var/zones/hosts/forward/$zone" "$zone" \ |
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
42 |
etc/hosts/forward/$zone/* |
82 | 43 |
done |
36
3208cd6540dc
update: restructure zones/, manage .pvl
Tero Marttila <terom@paivola.fi>
parents:
32
diff
changeset
|
44 |
|
82 | 45 |
log "Updating DHCP hosts..." |
98
a3734856e0fa
use hosts/dhcp/%** to create dhcp hosts configs
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
46 |
for hosts in $(list etc/hosts/dhcp); do |
a3734856e0fa
use hosts/dhcp/%** to create dhcp hosts configs
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
47 |
update_hosts_dhcp "var/dhcp/hosts/$hosts.conf" $hosts \ |
a3734856e0fa
use hosts/dhcp/%** to create dhcp hosts configs
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
48 |
$(expand_files "etc/hosts/dhcp/$hosts") |
82 | 49 |
done |
84
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
50 |
|
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
51 |
log "Updating reverse host zones..." |
93
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
52 |
for zone in $(list_dirs etc/hosts/reverse); do |
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
53 |
update_hosts_reverse "var/zones/hosts/reverse/$zone" "$zone" \ |
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
54 |
etc/hosts/reverse/$zone/* |
87
cb4607af8663
add etc/reverse-zones-hosts support, in preference to a magical include-based mechanism..
Tero Marttila <terom@paivola.fi>
parents:
85
diff
changeset
|
55 |
done |
62
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
61
diff
changeset
|
56 |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
87
diff
changeset
|
57 |
## Zones |
38
39799fc994e9
update: unify [check/copy/update/link]_[hosts/zone/serial]
Tero Marttila <terom@paivola.fi>
parents:
37
diff
changeset
|
58 |
log "Copying zone includes..." |
82 | 59 |
for zone in $(list_files etc/zones/includes); do |
85 | 60 |
copy "var/zones/includes/$zone" "etc/zones/includes/$zone" |
82 | 61 |
done |
18
826103fe3c8c
update: abspath; fixup serials log; indent log_cmd
Tero Marttila <terom@paivola.fi>
parents:
17
diff
changeset
|
62 |
|
82 | 63 |
log "Updating zone serials..." |
64 |
for zone in $(list_files etc/zones); do |
|
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
65 |
update_serial "var/serials/$zone" $serial \ |
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
66 |
"etc/zones/$zone" $(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/) |
82 | 67 |
done |
13 | 68 |
|
38
39799fc994e9
update: unify [check/copy/update/link]_[hosts/zone/serial]
Tero Marttila <terom@paivola.fi>
parents:
37
diff
changeset
|
69 |
log "Updating zones..." |
82 | 70 |
for zone in $(list_files etc/zones); do |
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
71 |
update_zone "var/zones/$zone" "etc/zones/$zone" "var/serials/$zone" \ |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
72 |
$(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/) |
82 | 73 |
done |
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
74 |
|
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
75 |
log "Updating DHCP confs..." |
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
76 |
for conf in $(list_files etc/dhcp); do |
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
77 |
update_dhcp_conf "var/dhcp/$conf" "etc/dhcp/$conf" |
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
78 |
done |
94
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
79 |
} |
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
80 |
|
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
81 |
function deploy { |
90
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
82 |
## Check |
10 | 83 |
log "Testing zones..." |
82 | 84 |
for zone in $(list_files etc/zones); do |
90
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
85 |
check_zone "var/zones/$zone" $zone |
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
86 |
done |
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
87 |
|
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
88 |
log "Testing DHCP confs..." |
90
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
89 |
for conf in var/dhcp/*.conf; do |
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
90 |
check_dhcp $conf |
82 | 91 |
done |
66
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
64
diff
changeset
|
92 |
|
61
22b58b938fd0
update: rename deploy_zones -> reload_zones; move related do_* from lib/update.updates -> lib/update.operations where they belong
Tero Marttila <terom@paivola.fi>
parents:
58
diff
changeset
|
93 |
log "Reload zones..." |
22b58b938fd0
update: rename deploy_zones -> reload_zones; move related do_* from lib/update.updates -> lib/update.operations where they belong
Tero Marttila <terom@paivola.fi>
parents:
58
diff
changeset
|
94 |
reload_zones |
44 | 95 |
|
66
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
64
diff
changeset
|
96 |
log "Reload dhcp..." |
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
64
diff
changeset
|
97 |
reload_dhcp |
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
64
diff
changeset
|
98 |
|
44 | 99 |
} |
100 |
||
101 |
## Main entry point |
|
102 |
function main { |
|
103 |
parse_args "$@" |
|
104 |
||
62
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
61
diff
changeset
|
105 |
## Input dirs |
87
cb4607af8663
add etc/reverse-zones-hosts support, in preference to a magical include-based mechanism..
Tero Marttila <terom@paivola.fi>
parents:
85
diff
changeset
|
106 |
for dir in etc etc/zones etc/hosts opt; do |
82 | 107 |
[ -d $dir ] || die "Missing directory: $dir" |
108 |
done |
|
44 | 109 |
|
110 |
## Output dirs |
|
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
111 |
ensure_dir var |
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
112 |
for dir in var/dhcp var/zones var/include-cache var/serials; do |
62
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
61
diff
changeset
|
113 |
ensure_dir $dir |
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
61
diff
changeset
|
114 |
done |
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
115 |
for dir in var/dhcp/hosts; do |
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
116 |
ensure_dir $dir |
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
117 |
done |
93
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
118 |
for dir in var/zones/includes var/zones/hosts; do |
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
119 |
ensure_dir $dir |
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
120 |
done |
1a313b7b6d40
change how hosts forward zones are generated, to use a similar technique as for reverse zones, with both using etc/hosts/{forward,reverse} -> var/zones/hosts/{forward,reverse}
Tero Marttila <terom@paivola.fi>
parents:
91
diff
changeset
|
121 |
for dir in var/zones/hosts/forward var/zones/hosts/reverse; do |
82 | 122 |
ensure_dir $dir |
30
1a8bc67b1eb7
update: link_zones for paivola.*.zone -> paivola.zone
Tero Marttila <terom@paivola.fi>
parents:
29
diff
changeset
|
123 |
done |
1a8bc67b1eb7
update: link_zones for paivola.*.zone -> paivola.zone
Tero Marttila <terom@paivola.fi>
parents:
29
diff
changeset
|
124 |
|
44 | 125 |
## Go |
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
126 |
commit |
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
87
diff
changeset
|
127 |
update |
94
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
128 |
deploy |
2 | 129 |
} |
130 |
||
7
f4457348faa0
update: function update { ... }, color logging, update_serial
Tero Marttila <terom@paivola.fi>
parents:
2
diff
changeset
|
131 |
main "$@" |