| 1530 |
dpurdie |
1 |
####################################################################################################
|
|
|
2 |
# This is a class action script for the replace class
|
|
|
3 |
# For each file in this class it will replace any replace tags in that file as it copies it to dest.
|
|
|
4 |
# It searches the src file for <REPLACETAG-XXX> and for each one it
|
|
|
5 |
# Looks for Environment var XXX and if it exists it is used to replace the tag in the file
|
|
|
6 |
# otherwise it prints a warning if the Var does not exist.
|
|
|
7 |
# If no tags are found in the file it is simply copied to dest
|
|
|
8 |
# These environment vars are setup by pkginfo or request script
|
|
|
9 |
# Just need to make sure that these vars match the XXX portion of the REPLACETAG
|
|
|
10 |
####################################################################################################
|
|
|
11 |
|
|
|
12 |
getList()
|
|
|
13 |
{
|
|
|
14 |
sed -n '
|
|
|
15 |
:start
|
|
|
16 |
/<REPLACETAG/{
|
|
|
17 |
:leading
|
|
|
18 |
/^<REPLACETAG/!{
|
|
|
19 |
# while replace tag not at beginning of line remove leading chars
|
|
|
20 |
s/^<\{0,1\}[^<]*//
|
|
|
21 |
b leading
|
|
|
22 |
}
|
|
|
23 |
# we now should have replace tag at start of line
|
|
|
24 |
# save line
|
|
|
25 |
h
|
|
|
26 |
# print 1st REPLACETAG, ie remove all after tag and print line
|
|
|
27 |
s/^<\(REPLACETAG[^>]*\)>.*$/\1/p
|
|
|
28 |
#restore orignial line & remove printed replace & jump to start to see if any more on same line
|
|
|
29 |
x
|
|
|
30 |
s/^<REPLACETAG[^>]*>\(.*\)$/\1/
|
|
|
31 |
b start
|
|
|
32 |
}' $1 | sort | uniq | awk 'BEGIN { ORS=" " } { print $0 }'
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
Warn=
|
|
|
36 |
|
|
|
37 |
while read src dest
|
|
|
38 |
do
|
|
|
39 |
if [ "$src" != "/dev/null" ]; then
|
|
|
40 |
# Get list of REPLACETAG- in current file
|
|
|
41 |
LIST=`getList $src`
|
|
|
42 |
Msg=
|
|
|
43 |
sedArgs=
|
|
|
44 |
|
|
|
45 |
for tag in $LIST
|
|
|
46 |
do
|
|
|
47 |
# Remove REPLACETAG- from front of tag to get the enviroment var name
|
|
|
48 |
var=`echo $tag | sed 's|^REPLACETAG-||'`
|
|
|
49 |
# now eval the name and expand the var to get contents into repl
|
|
|
50 |
repl=`eval echo \\$$var`
|
|
|
51 |
|
|
|
52 |
if [ -n "$repl" ]; then
|
|
|
53 |
Msg="$Msg [$tag=$repl]\n"
|
|
|
54 |
sedArgs="$sedArgs -e 's|<$tag>|$repl|g'"
|
|
|
55 |
else
|
|
|
56 |
Warn="$Warn===>WARNING: Install Environment Var [$var] does not exist for replacement in [$dest]\n"
|
|
|
57 |
fi
|
|
|
58 |
done
|
|
|
59 |
|
|
|
60 |
installf -c replace $PKGINST $dest f
|
|
|
61 |
if [ -n "$sedArgs" ]; then
|
|
|
62 |
printf "$dest <Replacements as follows>\n$Msg"
|
|
|
63 |
eval sed $sedArgs $src > $dest
|
|
|
64 |
else
|
|
|
65 |
printf "$dest <No Replacements Found>\n$Msg"
|
|
|
66 |
cp $src $dest
|
|
|
67 |
fi
|
|
|
68 |
fi
|
|
|
69 |
done
|
|
|
70 |
|
|
|
71 |
if [ "$1" = "ENDOFCLASS" ]; then
|
|
|
72 |
installf -f -c replace $PKGINST
|
|
|
73 |
echo "Replacements Completed"
|
|
|
74 |
if [ -n "$Warn" ]; then
|
|
|
75 |
printf "$Warn"
|
|
|
76 |
fi
|
|
|
77 |
fi
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
|
|
|
95 |
|
|
|
96 |
|
|
|
97 |
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
|
101 |
|