author | Tero Marttila <tero.marttila@aalto.fi> |
Thu, 26 Feb 2015 22:36:05 +0200 | |
changeset 628 | b10ad946d01d |
parent 627 | a81206440be2 |
child 629 | 7214fe5c6fac |
permissions | -rw-r--r-- |
627 | 1 |
## Generate updated output file from given command's stdout: |
2 |
# |
|
3 |
# do_update $out $BIN/cmd --args |
|
4 |
# |
|
5 |
# Writes output to a temporary .new file, optionally shows a diff of changes, and commits |
|
6 |
# the new version to $out (unless noop'd). |
|
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
7 |
function apply_cmd { |
627 | 8 |
local out="$1" |
9 |
local tmp="$out.new" |
|
10 |
||
11 |
debug "$out" |
|
628
b10ad946d01d
update: refactor into modularized lib/pvl/**.sh layout
Tero Marttila <tero.marttila@aalto.fi>
parents:
627
diff
changeset
|
12 |
cmd "${@:2}" > "$tmp" |
627 | 13 |
|
14 |
# compare |
|
15 |
if [ -e "$out" -a -z "$APPLY_DIFF" ]; then |
|
16 |
debug " changes:" |
|
17 |
||
18 |
# terse |
|
19 |
indent " " diff --unified=1 "$out" "$tmp" || true |
|
20 |
fi |
|
21 |
||
22 |
# deploy |
|
23 |
if [ "$APPLY" = 0 ]; then |
|
24 |
# cleanup |
|
25 |
debug " no-op" |
|
26 |
||
27 |
cmd rm "$tmp" |
|
28 |
else |
|
29 |
# commit |
|
30 |
debug " deploy" |
|
31 |
||
32 |
cmd mv "$tmp" "$out" |
|
33 |
fi |
|
34 |
} |
|
35 |