-
Notifications
You must be signed in to change notification settings - Fork 5
/
deploy.tpl
94 lines (81 loc) · 1.78 KB
/
deploy.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
set -e
usage() {
echo "Usage: $1 [ABSOLUTE_PATH]"
exit 1
}
main() {
local progname
local dst
local config
local genfiles
local renames
local make
progname=$(basename "$0")
while [ $# -gt 0 ]; do
case $1 in
-h|--help)
usage "$progname"
;;
-c|--config)
config="$2"
shift
shift
;;
-g|--genfiles)
genfiles="$2"
shift
shift
;;
-r|--renames)
renames="$2"
shift
shift
;;
-m|--make)
make="$2"
shift
shift
;;
*)
dst="$1"
shift
break
;;
esac
done
if [ -z "$dst" ]; then
echo "$progname: must have [ABSOLUTE_PATH]"
echo "Try '$progname -h' for more information."
exit 1
fi
local canonical
canonical="$(realpath --canonicalize-missing "$dst")"
if [ "$dst" != "$canonical" ] && [ "$dst" != "$canonical/" ]; then
echo "$progname: '$dst' is not an absolute path"
echo "Try '$progname -h' for more information."
exit 1
fi
mkdir --parents "$dst"
cp --recursive --parents --target-directory "$dst" -- *
for file in $genfiles; do
if [ -L "$dst/$file" ]; then
unlink "$dst/$file"
fi
cp --force --dereference --no-preserve=all --parents --target-directory "$dst" "$file"
done
cp --force "$make" "$dst/make"
cp --force --no-preserve=all "$config" "$dst/config.mk"
for rename in $renames; do
IFS=':' read -r from to <<EOF
$rename
EOF
mkdir --parents "$dst"/"$(dirname "$to")"
cp --force --dereference --no-preserve=all "$from" "$dst"/"$to"
done
if ! [ -z "$@" ]; then
"$dst/make" "$@"
fi
exit $?
}
main --genfiles "${GENFILES}" --renames "${RENAMES}" --make "${MAKE}" --config "${CONFIG}" "$@"