preparing for Collin
[tine20] / scripts / packaging / build-tine20-packages.sh
1 #!/bin/bash
2
3 # Version: $Id$
4
5 # examples
6 # $ ./build-tine20-packages.sh -s "http://git.tine20.org/git/tine20" -b master -r "2011_01_beta3-1" -c "Kristina"
7 # $ ./build-tine20-packages.sh -s "http://git.tine20.org/git/tine20" -b 2011-01 -r "2011-01-3" -c "Kristina"
8
9 ## GLOBAL VARIABLES ##
10 BASEDIR="./tine20build"
11 TEMPDIR="$BASEDIR/temp"
12 MISCPACKAGESDIR="$BASEDIR/packages/misc"
13
14 CODENAME="Collin"
15 GITURL="http://git.tine20.org/git/tine20"
16
17 RELEASE=""
18 GITBRANCH=""
19 PACKAGEDIR=""
20
21 #
22 # checkout url to local directory
23 #
24 function checkout()
25 {
26     echo "checkout files from git url $1 to $TEMPDIR/tine20 ... "
27     rm -rf $TEMPDIR/tine20
28     rm -rf $TEMPDIR/debian
29     rm -rf $TEMPDIR/fedora
30     rm -rf $TEMPDIR/Univention
31     
32     rm -rf $TEMPDIR/tine20.git
33     mkdir $TEMPDIR/tine20.git
34     cd $TEMPDIR/tine20.git
35     
36     git clone "$1" .
37
38     if [ -n "$GITBRANCH" ]; then
39         echo "checkout refspec"
40         git checkout $GITBRANCH
41         RETVAL=$?
42
43         if [ $RETVAL -ne 0 ]; then
44             echo "refspec $GITBRANCH not found. Either define a valid release name or a valid git refspec (-b)"
45             exit
46         fi
47     elif [ -n "$RELEASE" ]; then   
48         echo "checkout release tag"
49         git checkout refs/tags/$RELEASE
50         RETVAL=$?
51
52         if [ $RETVAL -ne 0 ]; then
53             echo "release tag refs/tags/$RELEASE not found. Either define a valid release name or a valid git refspec (-b)"
54             exit
55         fi
56     else
57         echo "You must either define a release (-r) or a branch (-b)"
58         exit
59     fi
60     
61     REVISION=$(git describe --tags)
62     if [ "$RELEASE" == "" ]; then
63         RELEASE=${REVISION}
64     fi
65
66     cd - > /dev/null
67
68     mv $TEMPDIR/tine20.git/tine20 $TEMPDIR/tine20
69     mv $TEMPDIR/tine20.git/scripts/packaging/debian $TEMPDIR/debian
70     mv $TEMPDIR/tine20.git/scripts/packaging/fedora $TEMPDIR/fedora
71     mv $TEMPDIR/tine20.git/scripts/packaging/Univention $TEMPDIR/Univention
72     rm -Rf $TEMPDIR/tine20.git
73     
74     echo "done"
75 }
76
77 ### create dirs ###
78 function createDirectories()
79 {
80     echo -n "creating directory structure $BASEDIR ... "
81     test -d $BASEDIR || mkdir -p $BASEDIR
82     
83     test -d $MISCPACKAGESDIR || mkdir -p $MISCPACKAGESDIR
84     test -d $TEMPDIR || mkdir -p $TEMPDIR
85     
86     #rm -rf $TEMPDIR/*
87     #test -d $TEMPDIR/Setup || mkdir $TEMPDIR/Setup
88     echo "done"
89 }
90
91 function getOptions()
92 {
93     while getopts "pr:s:b:c:" optname
94     do
95         case "$optname" in
96           "c")
97             CODENAME=$OPTARG
98             ;;
99           "b")
100             GITBRANCH=$OPTARG
101             ;;
102           "s")
103             GITURL=$OPTARG
104             ;;
105           "r")
106             # release
107             RELEASE=$OPTARG 
108             ;;
109           "?")
110             echo "Unknown option $OPTARG"
111             ;;
112           ":")
113             echo "No argument value for option $OPTARG"
114             ;;
115           *)
116           # Should not occur
117             echo "Unknown error while processing options"
118             ;;
119         esac
120         #echo "OPTIND is now $OPTIND"
121     done
122 }
123
124 function activateReleaseMode()
125 {
126     local DATETIME=`date "+%F %X%:z"`
127     
128     # set buildtype to DEBUG for beta releases
129     if [[ $RELEASE == *beta* ]]; then  
130         local BUILDTYPE="DEBUG";
131     else
132         local BUILDTYPE="RELEASE";
133     fi
134     
135     echo "RELEASE: $RELEASE REVISION: $REVISION CODENAME: $CODENAME BUILDTYPE: $BUILDTYPE";
136     
137     sed -i -e "s/'buildtype', 'DEVELOPMENT'/'buildtype', '$BUILDTYPE'/" $TEMPDIR/tine20/Tinebase/Core.php
138     sed -i -e "s/'buildtype', 'DEVELOPMENT'/'buildtype', '$BUILDTYPE'/" $TEMPDIR/tine20/Setup/Core.php
139     
140     sed -i -e "s#'TINE20_CODENAME',      getDevelopmentRevision()#'TINE20_CODENAME',      '$CODENAME'#" $TEMPDIR/tine20/Tinebase/Core.php
141     sed -i -e "s#'TINE20SETUP_CODENAME',       getDevelopmentRevision()#'TINE20SETUP_CODENAME',      '$CODENAME'#" $TEMPDIR/tine20/Setup/Core.php
142     sed -i -e "s/'TINE20_PACKAGESTRING', 'none'/'TINE20_PACKAGESTRING', '$RELEASE'/" $TEMPDIR/tine20/Tinebase/Core.php
143     sed -i -e "s/'TINE20SETUP_PACKAGESTRING', 'none'/'TINE20SETUP_PACKAGESTRING', '$RELEASE'/" $TEMPDIR/tine20/Setup/Core.php
144     sed -i -e "s/'TINE20_RELEASETIME',   'none'/'TINE20_RELEASETIME',   '$DATETIME'/" $TEMPDIR/tine20/Tinebase/Core.php
145     sed -i -e "s/'TINE20SETUP_RELEASETIME',   'none'/'TINE20SETUP_RELEASETIME',   '$DATETIME'/" $TEMPDIR/tine20/Setup/Core.php
146     
147     sed -i -e "s/Tine.clientVersion.buildRevision[^;]*/Tine.clientVersion.buildRevision = '$REVISION'/" $TEMPDIR/tine20/Tinebase/js/tineInit.js
148     sed -i -e "s/Tine.clientVersion.codeName[^;]*/Tine.clientVersion.codeName = '$CODENAME'/" $TEMPDIR/tine20/Tinebase/js/tineInit.js
149     sed -i -e "s/Tine.clientVersion.packageString[^;]*/Tine.clientVersion.packageString = '$RELEASE'/" $TEMPDIR/tine20/Tinebase/js/tineInit.js
150     sed -i -e "s/Tine.clientVersion.releaseTime[^;]*/Tine.clientVersion.releaseTime = '$DATETIME'/" $TEMPDIR/tine20/Tinebase/js/tineInit.js
151 }
152
153 function buildLangStats()
154 {
155     echo -n "building lang stats ... "
156     php -f $TEMPDIR/tine20/langHelper.php -- --statistics
157     echo "done"
158 }
159
160 function buildClient()
161 {
162     echo -n "building javascript clients ... "
163     phing -f $TEMPDIR/tine20/build.xml build
164     echo "done"
165 }
166
167 function createArchives()
168 {
169     echo "building Tine 2.0 single archives... "
170     CLIENTBUILDFILTER="FAT"
171     
172     for FILE in `ls $TEMPDIR/tine20`; do
173         UCFILE=`echo ${FILE} | tr '[A-Z]' '[a-z]'`
174         
175         if [ -d "$TEMPDIR/tine20/$FILE/translations" ]; then
176             case $FILE in
177                 Addressbook)
178                     # handled in Tinebase
179                     ;;
180                 Admin)
181                     # handled in Tinebase
182                     ;;
183                 Setup)
184                     # handled in Tinebase
185                     ;;
186
187                 Calendar)      
188                     echo " $FILE"
189                     echo -n "  cleanup "
190                     (cd $TEMPDIR/tine20/$FILE/js;  rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-"))
191                     (cd $TEMPDIR/tine20/$FILE/css; rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v print.css))
192                     echo "building "
193                     (cd $TEMPDIR/tine20; tar cjf ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.tar.bz2 $FILE)
194                     (cd $TEMPDIR/tine20; zip -qr ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.zip     $FILE)
195                     ;;
196
197                 Tinebase)
198                     echo " $FILE"
199                     echo -n "  cleanup "
200                     (cd $TEMPDIR/tine20/Addressbook/js;  rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-"))
201                     (cd $TEMPDIR/tine20/Addressbook/css; rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
202                     (cd $TEMPDIR/tine20/Admin/js;        rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-"))
203                     (cd $TEMPDIR/tine20/Admin/css;       rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
204                     (cd $TEMPDIR/tine20/Setup/js;        rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-"))
205                     (cd $TEMPDIR/tine20/Setup/css;       rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
206                     
207                     # Tinebase/js/ux/Printer/print.css
208                     (cd $TEMPDIR/tine20/Tinebase/js/ux/Printer; rm -rf $(ls | grep -v print.css))
209                     (cd $TEMPDIR/tine20/Tinebase/js/ux;  rm -rf $(ls | grep -v Printer))
210                     (cd $TEMPDIR/tine20/Tinebase/js;     rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v Locale | grep -v ux | grep -v "\-lang\-"))
211                     (cd $TEMPDIR/tine20/Tinebase/css;    rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
212                     
213                     # cleanup ExtJS
214                     (cd $TEMPDIR/tine20/library/ExtJS/adapter; rm -rf $(ls | grep -v ext))
215                     (cd $TEMPDIR/tine20/library/ExtJS/src;     rm -rf $(ls | grep -v debug.js))
216                     (cd $TEMPDIR/tine20/library/ExtJS;         rm -rf $(ls | grep -v adapter | grep -v ext-all-debug.js | grep -v ext-all.js | grep -v resources | grep -v src))
217                     
218                     ## cleanup HTMLPurifier
219                     #(cd $TEMPDIR/tine20/library/HTMLPurifier;  rm -rf HTMLPurifier.*.php)
220
221                     # cleanup OpenLayers
222                     (cd $TEMPDIR/tine20/library/OpenLayers;    rm -rf $(ls | grep -v img | grep -v license.txt | grep -v OpenLayers.js | grep -v theme))
223
224                     ## cleanup PHPExcel
225                     #(cd $TEMPDIR/tine20/library/PHPExcel/PHPExcel/Shared;  rm -rf PDF)
226                     
227                     # cleanup qCal
228                     (cd $TEMPDIR/tine20/library/qCal;  rm -rf docs tests)
229
230                     # cleanup jsb2tk
231                     (cd $TEMPDIR/tine20/library/jsb2tk;  rm -rf JSBuilder2 tests)
232                     
233                     # save langStats
234                     (mv $TEMPDIR/tine20/langstatistics.json $TEMPDIR/tine20/Tinebase/translations/langstatistics.json)
235                     
236                     echo -n "building "
237                     local FILES="Addressbook Admin Setup Tinebase Zend images library vendor docs fonts config.inc.php.dist index.php langHelper.php LICENSE PRIVACY README RELEASENOTES CREDITS setup.php tine20.php bootstrap.php worker.php status.php"
238                     (cd $TEMPDIR/tine20; tar cjf ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.tar.bz2 $FILES)
239                     (cd $TEMPDIR/tine20; zip -qr ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.zip     $FILES)
240                     
241                     echo ""
242                     ;;
243                     
244                 *)
245                     echo " $FILE"
246                     echo -n "  cleanup "
247                     (cd $TEMPDIR/tine20/$FILE/js;  rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-" | grep -v "empty\.js"))
248                     (cd $TEMPDIR/tine20/$FILE/css; rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
249                     echo "building "
250                     (cd $TEMPDIR/tine20; tar cjf ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.tar.bz2 $FILE)
251                     (cd $TEMPDIR/tine20; zip -qr ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.zip     $FILE)
252                     ;;
253             esac
254             
255         fi
256     done
257 }
258
259 function createSpecialArchives()
260 {
261     echo "building Tine 2.0 allinone archive... "
262     rm -rf $TEMPDIR/allinone
263     mkdir $TEMPDIR/allinone
264     
265     for ARCHIVENAME in activesync calendar tinebase crm felamimail filemanager projects sales tasks timetracker; do
266         (cd $TEMPDIR/allinone; tar xjf ../../packages/tine20/$RELEASE/tine20-${ARCHIVENAME}_$RELEASE.tar.bz2)
267     done
268     
269     (cd $TEMPDIR/allinone; tar cjf ../../packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2 .)
270     (cd $TEMPDIR/allinone; zip -qr ../../packages/tine20/$RELEASE/tine20-allinone_$RELEASE.zip     .)
271     
272
273     echo "building Tine 2.0 voip archive... "
274     rm -rf $TEMPDIR/voip
275     mkdir $TEMPDIR/voip
276     
277     for ARCHIVENAME in phone voipmanager; do
278         (cd $TEMPDIR/voip; tar xjf ../../packages/tine20/$RELEASE/tine20-${ARCHIVENAME}_$RELEASE.tar.bz2)
279     done
280     
281     (cd $TEMPDIR/voip; tar cjf ../../packages/tine20/$RELEASE/tine20-voip_$RELEASE.tar.bz2 .)
282     (cd $TEMPDIR/voip; zip -qr ../../packages/tine20/$RELEASE/tine20-voip_$RELEASE.zip     .)
283 }
284
285 function setupPackageDir()
286 {
287     PACKAGEDIR="$BASEDIR/packages/tine20/$RELEASE"
288     rm -rf $PACKAGEDIR
289     mkdir -p $PACKAGEDIR
290 }
291
292 function packageTranslations()
293 {
294     echo -n "building translation files for translators... "
295     php -d include_path=".:$TEMPDIR/tine20:$TEMPDIR/tine20/library"  -f $TEMPDIR/tine20/langHelper.php -- --package=translations.tar.gz
296     mv $TEMPDIR/tine20/translations.tar.gz $PACKAGEDIR
297     echo "done"
298 }
299
300 function buildChecksum()
301 {
302     echo -n "calculating SHA1 checksums... "
303     
304     test -e $PACKAGEDIR/sha1sum_$RELEASE.txt && rm $PACKAGEDIR/sha1sum_$RELEASE.txt
305     
306     for fileName in $PACKAGEDIR/*; do
307         (cd $PACKAGEDIR; sha1sum `basename $fileName`) >> $PACKAGEDIR/sha1sum_$RELEASE.txt 2>&1
308     done
309     
310     echo "done"
311 }
312
313 function prepareDebianPackaging()
314 {
315     PACKAGEDIR="$BASEDIR/packages/debian/$RELEASE"
316     rm -rf $PACKAGEDIR
317     
318     # Replace all matches of - with .
319     DEBIANVERSION=${RELEASE//-/.}
320
321     mkdir -p "$PACKAGEDIR/tine20-$DEBIANVERSION"
322     
323     echo -n "preparing debian packaging directory in $PACKAGEDIR/tine20-$DEBIANVERSION ... "
324     
325     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2
326     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2
327     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2
328     cp $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig.tar.bz2
329     cp $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig-Courses.tar.bz2
330     cp $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig-HumanResources.tar.bz2
331     cp -r $BASEDIR/temp/debian $PACKAGEDIR/tine20-$DEBIANVERSION
332
333     echo "done"
334 }
335
336 function prepareUniventionPackaging()
337 {
338     PACKAGEDIR="$BASEDIR/packages/univention/$RELEASE"
339     rm -rf $PACKAGEDIR
340     
341     # Replace all matches of - with .
342     DEBIANVERSION=${RELEASE//-/.}
343
344     mkdir -p "$PACKAGEDIR/tine20-$DEBIANVERSION"
345     
346     echo -n "preparing univention packaging directory in $PACKAGEDIR/tine20-$DEBIANVERSION ... "
347     
348     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2
349     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2
350     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2
351     cp $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig.tar.bz2
352     cp $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig-Courses.tar.bz2
353     cp $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig-HumanResources.tar.bz2
354     cp -r $BASEDIR/temp/Univention/* $PACKAGEDIR/tine20-$DEBIANVERSION
355
356     echo "done"
357 }
358
359 function prepareFedoraPackaging()
360 {
361     PACKAGEDIR="$BASEDIR/packages/fedora/$RELEASE"
362     rm -rf $PACKAGEDIR
363     
364     # Replace all matches of - with .
365     RPMVERSION=${RELEASE//-/.}
366
367     mkdir -p "$PACKAGEDIR/tine20-$RPMVERSION"
368     
369     echo -n "preparing fedora packaging directory in $PACKAGEDIR/tine20-$RPMVERSION ... "
370     
371     cp -r $BASEDIR/temp/fedora/* $PACKAGEDIR/tine20-$RPMVERSION/
372     
373     cp $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2 $PACKAGEDIR/tine20-$RPMVERSION/SOURCES/
374     cp $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2 $PACKAGEDIR/tine20-$RPMVERSION/SOURCES/
375     cp $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2 $PACKAGEDIR/tine20-$RPMVERSION/SOURCES/
376
377     echo "done"
378 }
379
380 getOptions "$@"
381
382 createDirectories
383 checkout "$GITURL" "$GITBRANCH"
384 setupPackageDir
385 activateReleaseMode
386 buildLangStats
387 buildClient
388 createArchives
389 createSpecialArchives
390 packageTranslations
391 buildChecksum
392 prepareDebianPackaging
393 prepareFedoraPackaging
394 prepareUniventionPackaging