-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgen-template.sh
56 lines (46 loc) · 1003 Bytes
/
gen-template.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
#!/usr/bin/env bash
#set -v
rm -f templates/*.bak templates/*.tmp
mkdir -p doc
list="$*"
[[ $list = "" ]] && list="$(/bin/ls templates/)"
awkprog='
/@@MODULE\(.*\)@@/ {
gsub(/@@MODULE\(/,"templates/module/");
gsub(/\)@@/,"");
system("cat " $0);
next
}
/@@EXEC\(.*\)@@/ {
gsub(/@@EXEC\(/,"");
gsub(/\)@@\r?/,"");
system($0);
#print;
next
}
{ print $0 }
'
CRLF=0
uname -s | grep -q CYGWIN && CRLF=1
for fname in $list
do
src="setup/$fname"
[[ -f $src ]] || src="templates/$fname"
if [[ -f "$src" ]]
then
dest="doc/$fname"
ext="${dest##*.}"
#[[ $ext == edit-list ]] && continue
[[ $ext = "sh" || $ext = "bat" || $ext = "h" ]] && dest="$fname"
[[ $fname = "INSTALL.txt" ]] && dest="$fname"
#echo "|$src|$dest|"
if ((CRLF)) && [[ $ext = bat || $ext = txt ]]
then
awk "$awkprog" $src | sed -f templates.sed | sed 's/$/\r/' >$dest
else
awk "$awkprog" $src | sed -f templates.sed >$dest
fi
[[ $ext = "sh" ]] && chmod a+x "$fname"
fi
done
exit 0