104 fi |
104 fi |
105 } |
105 } |
106 |
106 |
107 ## Update .serial number: |
107 ## Update .serial number: |
108 # |
108 # |
109 # do_update_serial $serial |
109 # do_update_serial .../serials/$zone $serial |
110 # |
110 # |
111 # Shows old/new serial on debug. |
|
112 function do_update_serial { |
111 function do_update_serial { |
113 local serial="$1" |
112 local dst="$1" |
114 |
113 local serial="$2" |
115 # read |
114 |
116 local old=$(test -e "$serial" && cat "$serial" || echo '') |
115 echo $serial > $dst |
117 |
|
118 cmd $OPT/bin/pvl.dns-serial "$serial" |
|
119 |
|
120 # read |
|
121 local new=$(cat "$serial") |
|
122 |
|
123 debug " $old -> $new" |
|
124 } |
116 } |
125 |
117 |
126 |
118 |
127 ## Generate new serial for zone using pvl.dns-serial, if the zone data has changed: |
119 ## Generate new serial for zone using pvl.dns-serial, if the zone data has changed: |
128 # |
120 # |
129 # update_serial $zone $deps... |
121 # update_serial .../serials/$zone $serial $deps... |
130 # |
122 # |
131 # Supports SERIAL_FORCE/NOOP. |
123 # Supports SERIAL_FORCE/NOOP. |
132 # Updates $SERIALS/$zone.serial. |
124 # Updates $SERIALS/$zone.serial. |
133 function update_serial { |
125 function update_serial { |
|
126 local dst="$1"; shift |
134 local serial="$1"; shift |
127 local serial="$1"; shift |
|
128 |
|
129 local old=$(test -e "$dst" && cat "$dst" || echo '') |
135 |
130 |
136 # test |
131 # test |
137 if [ $SERIAL_FORCE ]; then |
132 if [ $SERIAL_FORCE ]; then |
138 log_force "Updating $serial: forced" |
133 log_force "Updating $dst: $old <- $serial: forced" |
139 |
134 |
140 do_update_serial "$serial" |
135 do_update_serial "$dst" "$serial" |
141 |
136 |
142 elif ! check_update "$serial" "$@"; then |
137 elif ! check_update "$dst" "$@"; then |
143 log_skip "Updating $serial: not changed" |
138 log_skip "Updating $dst: $old <- $serial: not changed" |
144 |
139 |
145 elif [ $SERIAL_NOOP ]; then |
140 elif [ $SERIAL_NOOP ]; then |
146 log_noop "Updating $serial: skipped" |
141 log_noop "Updating $dst: $old <- $serial: skipped" |
147 |
142 |
148 else |
143 else |
149 log_update "Updating $serial..." |
144 log_update "Updating $dst: $old <- $serial" |
150 |
145 |
151 do_update_serial "$serial" |
146 do_update_serial "$dst" "$serial" |
152 fi |
147 fi |
153 } |
148 } |
154 |
149 |
155 ## Generate zone file from source using pvl.dns-zone: |
150 ## Generate zone file from source using pvl.dns-zone: |
156 # |
151 # |
157 # update_zone out/zones/$zone in/zones/$zone var/serials/$zone |
152 # update_zone out/zones/$zone in/zones/$zone var/serials/$zone |
158 function update_zone { |
153 function update_zone { |
159 local out="$1" |
154 local out="$1"; shift |
160 local src="$2" |
155 local src="$1"; shift |
161 local serial="$3" |
156 local serial="$1"; shift |
162 local serial_opt= |
157 local serial_opt= |
163 |
158 |
164 if [ -n "$serial" -a -f "$serial" ]; then |
159 if [ -n "$serial" -a -f "$serial" ]; then |
165 serial_opt="--serial=$(cat "$serial")" |
160 serial_opt="--serial=$(cat "$serial")" |
166 |
|
167 elif [ $SERIAL_NOOP ]; then |
161 elif [ $SERIAL_NOOP ]; then |
168 warn "$out: noop'd serial, omitting" |
162 warn "$out: noop'd serial, omitting" |
169 else |
163 else |
170 fail "$out: missing serial: $serial" |
164 fail "$out: missing serial: $serial" |
171 fi |
165 fi |
172 |
166 |
173 if check_update "$out" "$src" "$serial"; then |
167 if check_update "$out" "$src" "$serial" "$@"; then |
174 log_update "Generating $out <- $src..." |
168 log_update "Generating $out <- $src..." |
175 |
169 |
176 do_update "$out" $OPT/bin/pvl.dns-zone "$src" \ |
170 do_update "$out" $OPT/bin/pvl.dns-zone "$src" \ |
177 --include-path=$SRV/var/zones \ |
171 --include-path=$SRV/var/zones \ |
178 $serial_opt |
172 $serial_opt |
354 ## Commit changes to version control: |
348 ## Commit changes to version control: |
355 # |
349 # |
356 # commit_data |
350 # commit_data |
357 # |
351 # |
358 # Invokes `hg commit`, first showing the diff. |
352 # Invokes `hg commit`, first showing the diff. |
359 function commit { |
353 function update_commit { |
360 local repo=$1 |
354 local repo=$1 |
361 local commit_msg="$COMMIT_MSG" |
355 local commit_msg="$COMMIT_MSG" |
362 |
356 |
363 local msg="Commit changes" |
357 local msg="Commit changes" |
364 |
358 |
365 # operate? |
359 # operate? |
366 if [ $COMMIT_FORCE ]; then |
360 if [ $COMMIT_FORCE ]; then |
367 log_force "$msg..." |
361 log_force "$msg: $commit_msg" |
368 |
362 |
369 do_commit "$commit_msg" |
363 do_commit "$commit_msg" |
370 |
364 |
371 elif ! hg_modified $repo; then |
365 elif ! hg_modified $repo; then |
372 log_warn "$msg: no changes" |
366 log_warn "$msg: no changes" |