64 apply_cmd "$out" cat \ |
68 apply_cmd "$out" cat \ |
65 "$src" |
69 "$src" |
66 fi |
70 fi |
67 } |
71 } |
68 |
72 |
69 |
73 ## Check if the given zone needs to be updated; update serial if so |
70 ## Update list of zone $INCLUDEs from zone file |
|
71 # |
74 # |
72 # update_zone_includes var/include-cache/$zone etc/zones/$zone |
75 # check_zone_serial var/serials/$zone $serial $zone_deps... |
73 # |
|
74 function update_zone_includes { |
|
75 local out="$1" |
|
76 local src="$2" |
|
77 local includes="$ZONES_INCLUDE" |
|
78 |
|
79 if [ "$UPDATE_INCLUDES" = 1 ]; then |
|
80 log_force "$out: Force zone includes: $src" |
|
81 |
|
82 elif apply_check "$out" "$src"; then |
|
83 log_skip "$out: Skip zone includes: $src" |
|
84 |
|
85 return |
|
86 |
|
87 elif [ "$UPDATE_INCLUDES" = 0 ]; then |
|
88 log_noop "$out: Noop zone includes: $src" |
|
89 |
|
90 return |
|
91 else |
|
92 log_apply "$out: Update zone includes: $src" |
|
93 fi |
|
94 |
|
95 apply_cmd "$out" $OPT/bin/pvl.dns-includes \ |
|
96 --include-path=$ZONES_INCLUDE \ |
|
97 "$src" |
|
98 } |
|
99 |
|
100 ## Update the cached .serial for the given zone, if the zone has changed: |
|
101 # |
|
102 # update_serial var/serials/$zone $serial $deps... |
|
103 # |
76 # |
104 # Supports UPDATE_SERIAL= |
77 # Supports UPDATE_SERIAL= |
105 function update_zone_serial { |
78 function check_zone_serial { |
106 local out="$1" |
79 local out="$1" |
107 local serial="$2" |
80 local serial="$2" |
|
81 local srcs=(${@:3}) |
108 |
82 |
109 local old=$(test -e "$out" && cat "$out" || echo '') |
83 local old=$(test -e "$out" && cat "$out" || echo '') |
110 |
84 |
111 # test |
85 # test |
112 if [ "$UPDATE_SERIAL" = 1 ]; then |
86 if [ "$UPDATE_SERIAL" = 1 ]; then |
113 log_force "$out: Force serial $old <- $serial" |
87 log_force "$out: Force serial $old <- $serial" |
114 |
88 |
115 elif apply_check "$out" "${@:3}"; then |
|
116 log_skip "$out: Skip serial: $old <- $serial" |
|
117 |
|
118 return |
|
119 |
|
120 elif [ "$UPDATE_SERIAL" = 0 ]; then |
89 elif [ "$UPDATE_SERIAL" = 0 ]; then |
121 log_noop "$out: Noop serial: $old <- $serial" |
90 log_noop "$out: Noop serial: $old <- $serial" |
122 |
91 |
123 return |
92 return 0 |
|
93 |
|
94 elif apply_check "$out" ${srcs[@]:-}; then |
|
95 return 0 |
124 |
96 |
125 else |
97 else |
126 log_apply "$out: Update serial: $old <- $serial" |
98 log_apply "$out: Update serial: $old <- $serial" |
127 fi |
99 fi |
128 |
100 |
129 echo "$serial" > $out |
101 echo "$serial" > $out |
|
102 |
|
103 return 1 |
130 } |
104 } |
131 |
105 |
132 ## Generate zone file from source using pvl.dns-process: |
106 ## Generate zone file from source using pvl.dns-process: |
133 # |
107 # |
134 # update_zone var/zones/$zone etc/zones/$zone var/serials/$zone |
108 # update_zone var/zones/$zone etc/zones/$zone var/serials/$zone |
135 # |
109 # |
136 # Sets the SOA serial, and adjusts the $INCLUDE paths |
110 # Updates the SOA serial, and adjusts the $INCLUDE paths |
137 function update_zone { |
111 function update_zone { |
|
112 local update_serial= |
|
113 |
|
114 local OPTIND |
|
115 while getopts 's:' opt; do case $opt in |
|
116 s) update_serial=$OPTARG ;; |
|
117 esac done |
|
118 shift $(($OPTIND - 1)) |
|
119 |
138 local out="$1" |
120 local out="$1" |
139 local src="$2" |
121 local src="$2" |
140 local serial="$3" |
122 local serial="$3" |
141 local serial_opt= |
123 local zone_serial= |
|
124 |
142 local msg="$out: Generate zone: $src" |
125 local msg="$out: Generate zone: $src" |
|
126 local include_cache=$(include_cache_path $src) |
|
127 local srcs=($(include_cache $include_cache)) |
|
128 |
|
129 if check_zone_serial "$serial" $update_serial ${srcs[@]:-}; then |
|
130 zone_serial=$(cat $serial) |
143 |
131 |
144 if [ -n "$serial" -a -f "$serial" ]; then |
132 log_skip "$out: Skip zone: $src @ $zone_serial <- $update_serial" |
145 serial_opt="--serial=$(cat "$serial")" |
133 |
146 elif [ "$UPDATE_SERIAL" = 0 ]; then |
|
147 warn "$out: omit noop'd serial" |
|
148 else |
134 else |
149 fail "$out: missing serial: $serial" |
135 zone_serial=$(cat $serial) |
150 fi |
|
151 |
136 |
152 if apply_check "$out" "${@:2}"; then |
137 log_apply "$out: Generate zone: $src @ $zone_serial" |
153 log_skip "$msg" |
138 |
154 else |
|
155 log_apply "$msg" |
|
156 |
|
157 apply_cmd "$out" $OPT/bin/pvl.dns-process \ |
139 apply_cmd "$out" $OPT/bin/pvl.dns-process \ |
158 $serial_opt \ |
140 --serial=$zone_serial \ |
159 --include-path=$ZONES_INCLUDE \ |
141 --include-path=$ZONES_INCLUDE \ |
|
142 --include-trace=$include_cache \ |
160 "$src" |
143 "$src" |
161 fi |
144 fi |
162 } |
145 } |
163 |
146 |
164 ## Test zone file for validity using named-checkzone: |
147 ## Test zone file for validity using named-checkzone: |