| author | Tero Marttila <terom@paivola.fi> |
| Thu, 18 Sep 2014 21:13:23 +0300 | |
| changeset 624 | 889ecd6dcb4e |
| parent 623 | 44c32fd60997 |
| child 627 | a81206440be2 |
| permissions | -rwxr-xr-x |
| 525 | 1 |
#!/bin/bash |
2 |
# vim: set ft=sh : |
|
3 |
||
|
617
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
616
diff
changeset
|
4 |
# Bootstrap |
| 605 | 5 |
if [ $0 == './update' ]; then |
6 |
SRV=$(pwd) |
|
| 623 | 7 |
OPT=/opt/pvl-verkko |
8 |
LIB=/opt/pvl-dns/lib |
|
| 605 | 9 |
else |
| 623 | 10 |
SRV=${SRV:-/srv/verkko}
|
11 |
OPT=${SRV:-/opt/pvl-verkko}
|
|
12 |
LIB=/opt/pvl-dns/lib |
|
| 605 | 13 |
cd $SRV |
14 |
fi |
|
| 525 | 15 |
|
| 623 | 16 |
source $LIB/update |
| 567 | 17 |
|
|
618
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
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:
617
diff
changeset
|
19 |
## Commit |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
diff
changeset
|
20 |
# pre-commit check |
| 536 | 21 |
log "Testing hosts..." |
| 605 | 22 |
for hosts in $(list_files etc/hosts); do |
23 |
log_warn "TODO: check_hosts $hosts" |
|
24 |
done |
|
|
559
3208cd6540dc
update: restructure zones/, manage .pvl
Tero Marttila <terom@paivola.fi>
parents:
555
diff
changeset
|
25 |
|
|
618
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
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:
617
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:
617
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:
617
diff
changeset
|
29 |
} |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
diff
changeset
|
30 |
|
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
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:
617
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:
617
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:
617
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:
617
diff
changeset
|
35 |
else |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
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:
617
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:
617
diff
changeset
|
38 |
fi |
|
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
diff
changeset
|
39 |
|
|
612
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
610
diff
changeset
|
40 |
## Hosts |
|
607
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
605
diff
changeset
|
41 |
log "Updating forward host zones..." |
|
616
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:
614
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:
614
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:
614
diff
changeset
|
44 |
etc/hosts/forward/$zone/* |
| 605 | 45 |
done |
|
559
3208cd6540dc
update: restructure zones/, manage .pvl
Tero Marttila <terom@paivola.fi>
parents:
555
diff
changeset
|
46 |
|
| 605 | 47 |
log "Updating DHCP hosts..." |
|
621
a3734856e0fa
use hosts/dhcp/%** to create dhcp hosts configs
Tero Marttila <terom@paivola.fi>
parents:
618
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:
618
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:
618
diff
changeset
|
50 |
$(expand_files "etc/hosts/dhcp/$hosts") |
| 605 | 51 |
done |
|
607
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
605
diff
changeset
|
52 |
|
|
77df429f63a3
update: full host forward/dhcp/reverse zones
Tero Marttila <terom@paivola.fi>
parents:
605
diff
changeset
|
53 |
log "Updating reverse host zones..." |
|
616
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:
614
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:
614
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:
614
diff
changeset
|
56 |
etc/hosts/reverse/$zone/* |
|
610
cb4607af8663
add etc/reverse-zones-hosts support, in preference to a magical include-based mechanism..
Tero Marttila <terom@paivola.fi>
parents:
608
diff
changeset
|
57 |
done |
|
585
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
584
diff
changeset
|
58 |
|
|
612
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
610
diff
changeset
|
59 |
## Zones |
|
561
39799fc994e9
update: unify [check/copy/update/link]_[hosts/zone/serial]
Tero Marttila <terom@paivola.fi>
parents:
560
diff
changeset
|
60 |
log "Copying zone includes..." |
| 605 | 61 |
for zone in $(list_files etc/zones/includes); do |
| 608 | 62 |
copy "var/zones/includes/$zone" "etc/zones/includes/$zone" |
| 605 | 63 |
done |
|
541
826103fe3c8c
update: abspath; fixup serials log; indent log_cmd
Tero Marttila <terom@paivola.fi>
parents:
540
diff
changeset
|
64 |
|
| 605 | 65 |
log "Updating zone serials..." |
66 |
for zone in $(list_files etc/zones); do |
|
|
618
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
diff
changeset
|
67 |
update_serial "var/serials/$zone" $serial \ |
|
614
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
diff
changeset
|
68 |
"etc/zones/$zone" $(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/) |
| 605 | 69 |
done |
| 536 | 70 |
|
|
561
39799fc994e9
update: unify [check/copy/update/link]_[hosts/zone/serial]
Tero Marttila <terom@paivola.fi>
parents:
560
diff
changeset
|
71 |
log "Updating zones..." |
| 605 | 72 |
for zone in $(list_files etc/zones); do |
|
618
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
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:
617
diff
changeset
|
74 |
$(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/) |
| 605 | 75 |
done |
|
614
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
diff
changeset
|
76 |
|
|
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
diff
changeset
|
77 |
log "Updating DHCP confs..." |
|
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
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:
613
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:
613
diff
changeset
|
80 |
done |
|
617
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
616
diff
changeset
|
81 |
} |
|
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
616
diff
changeset
|
82 |
|
|
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
616
diff
changeset
|
83 |
function deploy {
|
|
613
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
612
diff
changeset
|
84 |
## Check |
| 533 | 85 |
log "Testing zones..." |
| 605 | 86 |
for zone in $(list_files etc/zones); do |
|
613
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
612
diff
changeset
|
87 |
check_zone "var/zones/$zone" $zone |
|
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
612
diff
changeset
|
88 |
done |
|
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
612
diff
changeset
|
89 |
|
|
614
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
diff
changeset
|
90 |
log "Testing DHCP confs..." |
|
613
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
612
diff
changeset
|
91 |
for conf in var/dhcp/*.conf; do |
|
5b33ccac38ad
update_zone --include-path, log_check
Tero Marttila <terom@paivola.fi>
parents:
612
diff
changeset
|
92 |
check_dhcp $conf |
| 605 | 93 |
done |
|
589
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
587
diff
changeset
|
94 |
|
|
584
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:
581
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:
581
diff
changeset
|
96 |
reload_zones |
| 567 | 97 |
|
|
589
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
587
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:
587
diff
changeset
|
99 |
reload_dhcp |
|
482d06935d96
update: cmd_test; check_dhcp_hosts after do_reload_zones; reload_dhcp
Tero Marttila <terom@paivola.fi>
parents:
587
diff
changeset
|
100 |
|
| 567 | 101 |
} |
102 |
||
103 |
## Main entry point |
|
104 |
function main {
|
|
|
624
889ecd6dcb4e
split LOG_* and UPDATE_* from lib/update.args into lib/update.*; fixup check_link and do_link for relative targets
Tero Marttila <terom@paivola.fi>
parents:
623
diff
changeset
|
105 |
log_init |
|
889ecd6dcb4e
split LOG_* and UPDATE_* from lib/update.args into lib/update.*; fixup check_link and do_link for relative targets
Tero Marttila <terom@paivola.fi>
parents:
623
diff
changeset
|
106 |
|
| 567 | 107 |
parse_args "$@" |
108 |
||
|
585
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
584
diff
changeset
|
109 |
## Input dirs |
| 623 | 110 |
for dir in etc etc/zones etc/hosts; do |
| 605 | 111 |
[ -d $dir ] || die "Missing directory: $dir" |
112 |
done |
|
| 567 | 113 |
|
114 |
## Output dirs |
|
|
614
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
diff
changeset
|
115 |
ensure_dir var |
|
618
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
diff
changeset
|
116 |
for dir in var/dhcp var/zones var/include-cache var/serials; do |
|
585
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
584
diff
changeset
|
117 |
ensure_dir $dir |
|
65bf391fd2f3
update: link + check dhcpd hosts from settings/dhcp/... -> dhcp/...
Tero Marttila <terom@paivola.fi>
parents:
584
diff
changeset
|
118 |
done |
|
614
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
diff
changeset
|
119 |
for dir in var/dhcp/hosts; do |
|
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
diff
changeset
|
120 |
ensure_dir $dir |
|
acb2fb235eb2
use new var/dhcp/hosts layout with update_dhcp_conf
Tero Marttila <terom@paivola.fi>
parents:
613
diff
changeset
|
121 |
done |
|
616
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:
614
diff
changeset
|
122 |
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:
614
diff
changeset
|
123 |
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:
614
diff
changeset
|
124 |
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:
614
diff
changeset
|
125 |
for dir in var/zones/hosts/forward var/zones/hosts/reverse; do |
| 605 | 126 |
ensure_dir $dir |
|
553
1a8bc67b1eb7
update: link_zones for paivola.*.zone -> paivola.zone
Tero Marttila <terom@paivola.fi>
parents:
552
diff
changeset
|
127 |
done |
|
1a8bc67b1eb7
update: link_zones for paivola.*.zone -> paivola.zone
Tero Marttila <terom@paivola.fi>
parents:
552
diff
changeset
|
128 |
|
| 567 | 129 |
## Go |
|
618
a756f317d083
update: commit before update, and use the hg commit timestamp as the serial
Tero Marttila <terom@paivola.fi>
parents:
617
diff
changeset
|
130 |
commit |
|
612
51270237a6ff
cleanup update, reintroduce separate hg repo
Tero Marttila <terom@paivola.fi>
parents:
610
diff
changeset
|
131 |
update |
|
617
1b02d8075676
cleanup main update script somewhat
Tero Marttila <terom@paivola.fi>
parents:
616
diff
changeset
|
132 |
deploy |
| 525 | 133 |
} |
134 |
||
|
530
f4457348faa0
update: function update { ... }, color logging, update_serial
Tero Marttila <terom@paivola.fi>
parents:
525
diff
changeset
|
135 |
main "$@" |