-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·72 lines (65 loc) · 1.18 KB
/
deploy.sh
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
#!/bin/sh
usage() {
echo "Usage: $0 -a"
echo " $0 -e pattern [pattern ...]"
echo " $0 pattern [pattern ...]"
exit 1
}
MAP_FILE="map.txt"
PARSE_TEMPLATE="bin/parse-template.sh"
PATTERN=""
GREP_OPTIONS="-qE"
WHICH="/usr/bin/which"
CP="$(${WHICH} cp)"
GREP="$(${WHICH} grep)"
SED="$(${WHICH} sed)"
# parse command line arguments and generate a extended grep pattern
if [ $# -eq 0 ]; then
usage
else
case "$1" in
-a)
PATTERN=".*"
shift
;;
-e)
GREP_OPTIONS="${GREP_OPTIONS} -v"
shift
;;
-*)
usage
;;
*)
PATTERN="$1"
shift
;;
esac
for i in "$@"; do
# escape -'s
i=$(echo "$i" | "$SED" 's/-/\\-/')
if [ -z "$PATTERN" ]; then
PATTERN="$i"
else
PATTERN="$PATTERN|$i"
fi
done
fi
while read src dest; do
# expand src and dest so that their contents can be expanded by
# the shell later
src=$(eval echo $src)
dest=$(eval echo $dest)
# only process file if "file" string matches the src name
echo "$src" | "$GREP" $GREP_OPTIONS "$PATTERN"
if [ $? -eq 0 ]; then
case "$src" in
*.template)
"$PARSE_TEMPLATE" "$src" > "$dest"
echo "'${src%.template}' -> '$dest'"
;;
*)
"$CP" -v "$src" "$dest"
;;
esac
fi
done < "$MAP_FILE"