3 # Copyright (c) 2008,2009 Tobias Sarnowski <sarnowski@new-thoughts.org>
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 # get configfile to use
18 if [ -z "$1" ] ||
[ ! -r "$1" ]; then
19 echo "Usage: $0 <configfile>" >&2
23 # get absolute path of project
28 configfile
=$PROJECTDIR/$
(basename $1)
31 # find the right "sed"
32 # use GNU sed if available, nessecary on OpenBSD
33 # cause sed don't supports -i (infile)
34 [ ! -z "$(which gsed)" ] && SED
=gsed
37 # include config file for direct usage of variables
40 # reset paths to absolute
41 BUILDDIR
=$PROJECTDIR/$BUILDDIR
42 SRCDIR
=$PROJECTDIR/$SRCDIR
44 # create temporary directory
47 # make the source dir the working dir so that
48 # find prints relative paths
51 # find out the actual version
52 VERSION
=$
(..
/scripts
/generate_version.sh
)
53 VERSION_FULL
=$
(..
/scripts
/generate_version.sh
--full)
54 echo " VSN $VERSION_FULL"
56 # process every listed file
57 find $FILES_TO_PROCESS |
while read file; do
58 if [ -d $file ] && [ ! -d $BUILDDIR/$file ]; then
59 # create the directory
61 mkdir
-p $BUILDDIR/$file
63 elif [ -f $file ]; then
66 if [ $file -ot $BUILDDIR/$file ]; then
70 # what type of file do we have?
71 filetype
=$
(file $file | cut
-d' ' -f2)
72 if [ "$filetype" = "ASCII" ] \
73 ||
[ "$filetype" = "XML" ] \
74 ||
[ "$filetype" = "HTML" ]
78 cp $file $BUILDDIR/$file
81 $SED "s/%%VERSION%%/$VERSION/g" -i $BUILDDIR/$file
82 $SED "s/%%VERSION_FULL%%/$VERSION_FULL/g" -i $BUILDDIR/$file
84 # parse the config file
85 cat $configfile |
while read line
; do
88 line
=$
(echo $line |
sed 's/#.*//')
90 # sort out invalid lines
91 if [ -z "$(echo $line | grep '=')" ]; then
96 key
=$
(echo $line | cut
-d'=' -f1)
97 value
=$
(echo $line | cut
-d'=' -f2-)
99 # do not process special keywords
101 "FILES_TO_PROCESS") continue;;
102 "BUILDDIR") continue;;
105 # strip " from strings
106 value
=$
(echo $value |
sed 's/^"//' |
sed 's/"$//')
109 value
=$
(echo $value |
sed 's/\//\\\//')
111 # replace %%<key>%% with <value>
112 $SED "s/%%$key%%/$value/g" -i $BUILDDIR/$file
118 cp $file $BUILDDIR/$file