author | Tero Marttila <terom@paivola.fi> |
Mon, 09 Mar 2015 21:17:06 +0200 | |
changeset 736 | 75938aa0390b |
parent 671 | 72143af5afbd |
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 |
|
671
72143af5afbd
lib/pvl: pvl/apply: fix APPLY_DIFF
Tero Marttila <terom@paivola.fi>
parents:
629
diff
changeset
|
15 |
if [ -e "$out" -a -n "$APPLY_DIFF" ]; then |
627 | 16 |
debug " changes:" |
17 |
||
18 |
# terse |
|
629 | 19 |
cmd_indent " " diff --unified=1 "$out" "$tmp" || true |
627 | 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 |
|
629 | 30 |
debug " apply" |
627 | 31 |
|
32 |
cmd mv "$tmp" "$out" |
|
33 |
fi |
|
34 |
} |
|
35 |