627
|
1 |
# Idempotent refreshable operations
|
|
2 |
|
|
3 |
apply_GETOPTS='pFn'
|
|
4 |
|
|
5 |
APPLY=
|
|
6 |
APPLY_DIFF=
|
|
7 |
|
|
8 |
function apply_help {
|
|
9 |
cat <<END
|
|
10 |
Apply:
|
|
11 |
-p show changes
|
|
12 |
-F force-updates without checking src mtime
|
|
13 |
-n no-op/mock-update; don't actually change/deploy anything; implies -SpC
|
|
14 |
END
|
|
15 |
}
|
|
16 |
|
|
17 |
function apply_opt {
|
|
18 |
local opt=$1
|
|
19 |
local optarg="$2"
|
|
20 |
|
|
21 |
case $opt in
|
|
22 |
p) APPLY_DIFF=1 ;;
|
|
23 |
F) APPLY=1 ;;
|
|
24 |
|
|
25 |
n)
|
|
26 |
APPLY=0
|
|
27 |
APPLY_DIFF=1
|
|
28 |
;;
|
|
29 |
*) return 1
|
|
30 |
esac
|
|
31 |
}
|
|
32 |
|
|
33 |
. $LIB/pvl/apply/dir.sh
|
|
34 |
. $LIB/pvl/apply/link.sh
|
|
35 |
. $LIB/pvl/apply/cmd.sh
|
|
36 |
. $LIB/pvl/apply/cat.sh
|
|
37 |
|
|
38 |
## Compare the given output file with all given source files:
|
|
39 |
#
|
|
40 |
# check_update $out ${deps[@]} && do_update $out ... || ...
|
|
41 |
#
|
|
42 |
# Returns true if the output file needs to be updated.
|
|
43 |
function apply_check {
|
|
44 |
local update=
|
|
45 |
local out="$1"
|
|
46 |
|
|
47 |
debug "$out"
|
|
48 |
|
|
49 |
if [ ${#@} -eq 1 ]; then
|
|
50 |
debug " update: unknown deps"
|
|
51 |
return 0
|
|
52 |
|
|
53 |
elif [ ! -e "$out" ]; then
|
|
54 |
debug " update: dest missing"
|
|
55 |
return 0
|
|
56 |
|
|
57 |
elif [ "$APPLY" = 1]; then
|
|
58 |
debug " update: forced"
|
|
59 |
return 2
|
|
60 |
fi
|
|
61 |
|
|
62 |
# check deps
|
|
63 |
for dep in "${@:2}"; do
|
|
64 |
# check
|
|
65 |
if [ ! -e "$dep" ]; then
|
|
66 |
warn "$out: Missing source: $dep"
|
|
67 |
|
|
68 |
elif [ "$out" -ot "$dep" ]; then
|
|
69 |
debug " update: $dep"
|
|
70 |
return 1
|
|
71 |
else
|
|
72 |
debug " check: $dep"
|
|
73 |
fi
|
|
74 |
done
|
|
75 |
|
|
76 |
debug " up-to-date"
|
|
77 |
return 0
|
|
78 |
}
|