author | terom |
Sat, 26 Apr 2014 23:55:18 +0300 | |
changeset 100 | 44c32fd60997 |
parent 98 | a3734856e0fa |
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) |
|
100 | 7 |
OPT=/opt/pvl-verkko |
8 |
LIB=/opt/pvl-dns/lib |
|
82 | 9 |
else |
100 | 10 |
SRV=${SRV:-/srv/verkko} |
11 |
OPT=${SRV:-/opt/pvl-verkko} |
|
12 |
LIB=/opt/pvl-dns/lib |
|
82 | 13 |
cd $SRV |
14 |
fi |
|
2 | 15 |
|
100 | 16 |
source $LIB/update |
44 | 17 |
|
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
18 |
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
|
19 |
## Commit |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
20 |
# pre-commit check |
13 | 21 |
log "Testing hosts..." |
82 | 22 |
for hosts in $(list_files etc/hosts); do |
23 |
log_warn "TODO: check_hosts $hosts" |
|
24 |
done |
|
36
3208cd6540dc
update: restructure zones/, manage .pvl
Tero Marttila <terom@paivola.fi>
parents:
32
diff
changeset
|
25 |
|
95
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
26 |
# 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
|
27 |
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
|
28 |
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
|
29 |
} |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
30 |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
31 |
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
|
32 |
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
|
33 |
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
|
34 |
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
|
35 |
else |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
36 |
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
|
37 |
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
|
38 |
fi |
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
94
diff
changeset
|
39 |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
87
diff
changeset
|
40 |
## Hosts |
84
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
etc/hosts/forward/$zone/* |
82 | 45 |
done |
36
3208cd6540dc
update: restructure zones/, manage .pvl
Tero Marttila <terom@paivola.fi>
parents:
32
diff
changeset
|
46 |
|
82 | 47 |
log "Updating DHCP hosts..." |
98
a3734856e0fa
use hosts/dhcp/%** to create dhcp hosts configs
Tero Marttila <terom@paivola.fi>
parents:
95
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
$(expand_files "etc/hosts/dhcp/$hosts") |
82 | 51 |
done |
84
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
52 |
|
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
82
diff
changeset
|
53 |
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
|
54 |
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
|
55 |
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
|
56 |
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
|
57 |
done |
62
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
61
diff
changeset
|
58 |
|
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
87
diff
changeset
|
59 |
## Zones |
38
39799fc994e9
update: unify [check/copy/update/link]_[hosts/zone/serial]
Tero Marttila <terom@paivola.fi>
parents:
37
diff
changeset
|
60 |
log "Copying zone includes..." |
82 | 61 |
for zone in $(list_files etc/zones/includes); do |
85 | 62 |
copy "var/zones/includes/$zone" "etc/zones/includes/$zone" |
82 | 63 |
done |
18
826103fe3c8c
update: abspath; fixup serials log; indent log_cmd
Tero Marttila <terom@paivola.fi>
parents:
17
diff
changeset
|
64 |
|
82 | 65 |
log "Updating zone serials..." |
66 |
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
|
67 |
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
|
68 |
"etc/zones/$zone" $(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/) |
82 | 69 |
done |
13 | 70 |
|
38
39799fc994e9
update: unify [check/copy/update/link]_[hosts/zone/serial]
Tero Marttila <terom@paivola.fi>
parents:
37
diff
changeset
|
71 |
log "Updating zones..." |
82 | 72 |
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
|
73 |
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
|
74 |
$(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/) |
82 | 75 |
done |
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
76 |
|
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
77 |
log "Updating DHCP confs..." |
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
78 |
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
|
79 |
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
|
80 |
done |
94
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
81 |
} |
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
82 |
|
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
83 |
function deploy { |
90
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
84 |
## Check |
10 | 85 |
log "Testing zones..." |
82 | 86 |
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
|
87 |
check_zone "var/zones/$zone" $zone |
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
88 |
done |
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
89 |
|
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
90 |
log "Testing DHCP confs..." |
90
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
91 |
for conf in var/dhcp/*.conf; do |
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
89
diff
changeset
|
92 |
check_dhcp $conf |
82 | 93 |
done |
66
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
64
diff
changeset
|
94 |
|
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
|
95 |
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
|
96 |
reload_zones |
44 | 97 |
|
66
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
64
diff
changeset
|
98 |
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
|
99 |
reload_dhcp |
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
64
diff
changeset
|
100 |
|
44 | 101 |
} |
102 |
||
103 |
## Main entry point |
|
104 |
function main { |
|
105 |
parse_args "$@" |
|
106 |
||
62
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
61
diff
changeset
|
107 |
## Input dirs |
100 | 108 |
for dir in etc etc/zones etc/hosts; do |
82 | 109 |
[ -d $dir ] || die "Missing directory: $dir" |
110 |
done |
|
44 | 111 |
|
112 |
## Output dirs |
|
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
113 |
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
|
114 |
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
|
115 |
ensure_dir $dir |
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
61
diff
changeset
|
116 |
done |
91
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
117 |
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
|
118 |
ensure_dir $dir |
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
90
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
for dir in var/zones/hosts/forward var/zones/hosts/reverse; do |
82 | 124 |
ensure_dir $dir |
30
1a8bc67b1eb7
update: link_zones for paivola.*.zone -> paivola.zone
Tero Marttila <terom@paivola.fi>
parents:
29
diff
changeset
|
125 |
done |
1a8bc67b1eb7
update: link_zones for paivola.*.zone -> paivola.zone
Tero Marttila <terom@paivola.fi>
parents:
29
diff
changeset
|
126 |
|
44 | 127 |
## 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
|
128 |
commit |
89
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
87
diff
changeset
|
129 |
update |
94
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
93
diff
changeset
|
130 |
deploy |
2 | 131 |
} |
132 |
||
7
f4457348faa0
update: function update { ... }, color logging, update_serial
Tero Marttila <terom@paivola.fi>
parents:
2
diff
changeset
|
133 |
main "$@" |