457fb39560e3f077a26d7fb7850abdaf9f2f160a
[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=`readlink -f ./tine20build`
11 TEMPDIR="$BASEDIR/temp"
12 MISCPACKAGESDIR="$BASEDIR/packages/misc"
13
14 CODENAME="Elena"
15 GITURL="http://git.tine20.org/git/tine20"
16
17 RELEASE=""
18 GITBRANCH="2015.07"
19 PACKAGEDIR=""
20
21 PATH=$MISCPACKAGESDIR:$TEMPDIR/tine20/vendor/bin:$PATH
22
23 #
24 # checkout url to local directory
25 #
26 function checkout()
27 {
28     echo "checkout files from git url $1 to $TEMPDIR/tine20 ... "
29     rm -rf $TEMPDIR/tine20
30     rm -rf $TEMPDIR/debian
31     rm -rf $TEMPDIR/fedora
32     rm -rf $TEMPDIR/Univention
33     
34     rm -rf $TEMPDIR/tine20.git
35     mkdir $TEMPDIR/tine20.git
36     cd $TEMPDIR/tine20.git
37     
38     git clone "$1" .
39
40     if [ -n "$GITBRANCH" ]; then
41         echo "checkout refspec"
42         git checkout $GITBRANCH
43         RETVAL=$?
44
45         if [ $RETVAL -ne 0 ]; then
46             echo "refspec $GITBRANCH not found. Either define a valid release name or a valid git refspec (-b)"
47             exit
48         fi
49     elif [ -n "$RELEASE" ]; then   
50         echo "checkout release tag"
51         git checkout refs/tags/${RELEASE/\~/-}
52         RETVAL=$?
53
54         if [ $RETVAL -ne 0 ]; then
55             echo "release tag refs/tags/$RELEASE not found. Either define a valid release name or a valid git refspec (-b)"
56             exit
57         fi
58     else
59         echo "You must either define a release (-r) or a branch (-b)"
60         exit
61     fi
62     
63     REVISION=$(git describe --tags)
64     if [ "$RELEASE" == "" ]; then
65         RELEASE=${REVISION}
66     fi
67
68     cd - > /dev/null
69
70     mv $TEMPDIR/tine20.git/tine20 $TEMPDIR/tine20
71     mv $TEMPDIR/tine20.git/scripts/packaging/debian $TEMPDIR/debian
72     mv $TEMPDIR/tine20.git/scripts/packaging/fedora $TEMPDIR/fedora
73     mv $TEMPDIR/tine20.git/scripts/packaging/Univention $TEMPDIR/Univention
74     rm -Rf $TEMPDIR/tine20.git
75     
76     echo "done"
77 }
78
79 ### create dirs ###
80 function createDirectories()
81 {
82     echo -n "creating directory structure $BASEDIR ... "
83     test -d $BASEDIR || mkdir -p $BASEDIR
84     
85     test -d $MISCPACKAGESDIR || mkdir -p $MISCPACKAGESDIR
86     test -d $TEMPDIR || mkdir -p $TEMPDIR
87     
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     # utc datetime, like this: 2013-09-24 14:27:06
127     local DATETIME=`date -u "+%F %T"`
128     
129     # set buildtype to DEBUG for beta releases
130     if [[ $RELEASE == *beta* ]]; then  
131         local BUILDTYPE="DEBUG";
132     else
133         local BUILDTYPE="RELEASE";
134     fi
135     
136     echo "RELEASE: $RELEASE REVISION: $REVISION CODENAME: $CODENAME BUILDTYPE: $BUILDTYPE";
137     
138     sed -i -e "s/'buildtype', 'DEVELOPMENT'/'buildtype', '$BUILDTYPE'/" $TEMPDIR/tine20/Tinebase/Core.php
139     sed -i -e "s/'buildtype', 'DEVELOPMENT'/'buildtype', '$BUILDTYPE'/" $TEMPDIR/tine20/Setup/Core.php
140     
141     sed -i -e "s#'TINE20_CODENAME',      Tinebase_Helper::getDevelopmentRevision()#'TINE20_CODENAME',      '$CODENAME'#" $TEMPDIR/tine20/Tinebase/Core.php
142     sed -i -e "s#'TINE20SETUP_CODENAME',       Tinebase_Helper::getDevelopmentRevision()#'TINE20SETUP_CODENAME',      '$CODENAME'#" $TEMPDIR/tine20/Setup/Core.php
143     sed -i -e "s/'TINE20_PACKAGESTRING', 'none'/'TINE20_PACKAGESTRING', '$RELEASE'/" $TEMPDIR/tine20/Tinebase/Core.php
144     sed -i -e "s/'TINE20SETUP_PACKAGESTRING', 'none'/'TINE20SETUP_PACKAGESTRING', '$RELEASE'/" $TEMPDIR/tine20/Setup/Core.php
145     sed -i -e "s/'TINE20_RELEASETIME',   'none'/'TINE20_RELEASETIME',   '$DATETIME'/" $TEMPDIR/tine20/Tinebase/Core.php
146     sed -i -e "s/'TINE20SETUP_RELEASETIME',   'none'/'TINE20SETUP_RELEASETIME',   '$DATETIME'/" $TEMPDIR/tine20/Setup/Core.php
147     sed -i -e "s/Tinebase_Helper::getDevelopmentRevision()/Tinebase_Helper::getCodename()/" $TEMPDIR/tine20/build.xml
148     
149     sed -i -e "s/Tine.clientVersion.buildRevision[^;]*/Tine.clientVersion.buildRevision = '$REVISION'/" $TEMPDIR/tine20/Tinebase/js/tineInit.js
150     sed -i -e "s/Tine.clientVersion.codeName[^;]*/Tine.clientVersion.codeName = '$CODENAME'/" $TEMPDIR/tine20/Tinebase/js/tineInit.js
151     sed -i -e "s/Tine.clientVersion.packageString[^;]*/Tine.clientVersion.packageString = '$RELEASE'/" $TEMPDIR/tine20/Tinebase/js/tineInit.js
152     sed -i -e "s/Tine.clientVersion.releaseTime[^;]*/Tine.clientVersion.releaseTime = '$DATETIME'/" $TEMPDIR/tine20/Tinebase/js/tineInit.js
153 }
154
155 function buildLangStats()
156 {
157     echo -n "building lang stats ... "
158     php -f $TEMPDIR/tine20/langHelper.php -- --statistics
159     echo "done"
160 }
161
162 function buildClient()
163 {
164     echo -n "building javascript clients ... "
165     $TEMPDIR/tine20/vendor/bin/phing -f $TEMPDIR/tine20/build.xml build
166     echo "done"
167 }
168
169 function createArchives()
170 {
171     echo "building Tine 2.0 single archives... "
172     CLIENTBUILDFILTER="FAT"
173     
174     for FILE in `ls $TEMPDIR/tine20`; do
175         UCFILE=`echo ${FILE} | tr '[A-Z]' '[a-z]'`
176         
177         if [ -d "$TEMPDIR/tine20/$FILE/translations" ]; then
178             case $FILE in
179                 Addressbook)
180                     # handled in Tinebase
181                     ;;
182                 Admin)
183                     # handled in Tinebase
184                     ;;
185                 Setup)
186                     # handled in Tinebase
187                     ;;
188
189                 Calendar)      
190                     echo " $FILE"
191                     echo -n "  cleanup "
192                     (cd $TEMPDIR/tine20/$FILE/js;  rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-"))
193                     (cd $TEMPDIR/tine20/$FILE/css; rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v print.css))
194                     echo "building "
195                     (cd $TEMPDIR/tine20; tar cjf ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.tar.bz2 $FILE)
196                     (cd $TEMPDIR/tine20; zip -qr ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.zip     $FILE)
197                     ;;
198
199                 Tinebase)
200                     echo " $FILE"
201                     echo -n "  cleanup "
202                     (cd $TEMPDIR/tine20/Addressbook/js;  rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-"))
203                     (cd $TEMPDIR/tine20/Addressbook/css; rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
204                     (cd $TEMPDIR/tine20/Admin/js;        rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-"))
205                     (cd $TEMPDIR/tine20/Admin/css;       rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
206                     (cd $TEMPDIR/tine20/Setup/js;        rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-"))
207                     (cd $TEMPDIR/tine20/Setup/css;       rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
208                     
209                     # Tinebase/js/ux/Printer/print.css
210                     (cd $TEMPDIR/tine20/Tinebase/js/ux/Printer; rm -rf $(ls | grep -v print.css))
211                     # Tinebase/js/ux/data/windowNameConnection*
212                     (cd $TEMPDIR/tine20/Tinebase/js/ux/data; rm -rf $(ls | grep -v windowNameConnection))
213                     (cd $TEMPDIR/tine20/Tinebase/js/ux;  rm -rf $(ls | grep -v Printer | grep -v data))
214                     (cd $TEMPDIR/tine20/Tinebase/js;     rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v Locale | grep -v ux | grep -v "\-lang\-"))
215                     (cd $TEMPDIR/tine20/Tinebase/css;    rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
216                     
217                     # cleanup ExtJS
218                     (cd $TEMPDIR/tine20/library/ExtJS/adapter; rm -rf $(ls | grep -v ext))
219                     (cd $TEMPDIR/tine20/library/ExtJS/src;     rm -rf $(ls | grep -v debug.js))
220                     (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))
221                     
222                     # cleanup OpenLayers
223                     (cd $TEMPDIR/tine20/library/OpenLayers;    rm -rf $(ls | grep -v img | grep -v license.txt | grep -v OpenLayers.js | grep -v theme))
224
225                     # cleanup qCal
226                     (cd $TEMPDIR/tine20/library/qCal;  rm -rf docs tests)
227
228                     # cleanup jsb2tk
229                     (cd $TEMPDIR/tine20/library/jsb2tk;  rm -rf JSBuilder2 tests)
230                     
231                     # save langStats
232                     (mv $TEMPDIR/tine20/langstatistics.json $TEMPDIR/tine20/Tinebase/translations/langstatistics.json)
233                     
234                     # remove composer dev requires
235                     composer install --no-dev -d $TEMPDIR/tine20
236                     
237                     rm -rf $TEMPDIR/tine20/vendor/zendframework/zendframework1
238                     rm -rf $TEMPDIR/tine20/vendor/phpdocumentor
239                     rm -rf $TEMPDIR/tine20/vendor/ezyang/htmlpurifier/{art,benchmarks,extras,maintenance,smoketests}
240                     
241                     find $TEMPDIR/tine20/vendor -name .gitignore -type f -print0 | xargs -0 rm -rf
242                     find $TEMPDIR/tine20/vendor -name .git       -type d -print0 | xargs -0 rm -rf
243                     find $TEMPDIR/tine20/vendor -name docs       -type d -print0 | xargs -0 rm -rf
244                     find $TEMPDIR/tine20/vendor -name examples   -type d -print0 | xargs -0 rm -rf
245                     find $TEMPDIR/tine20/vendor -name tests      -type d -print0 | xargs -0 rm -rf
246                     
247                     composer dumpautoload -d $TEMPDIR/tine20
248                     
249                     rm -rf $TEMPDIR/tine20/composer.*
250                     
251                     echo -n "building "
252                     local FILES="Addressbook Admin Setup Tinebase Zend images library vendor docs fonts themes" 
253                     local FILES="$FILES config.inc.php.dist index.php langHelper.php setup.php tine20.php bootstrap.php worker.php status.php"
254                     local FILES="$FILES CREDITS LICENSE PRIVACY README RELEASENOTES init_plugins.php chrome_web_app.json"
255                     
256                     (cd $TEMPDIR/tine20; tar cjf ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.tar.bz2 $FILES)
257                     (cd $TEMPDIR/tine20; zip -qr ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.zip     $FILES)
258                     
259                     echo ""
260                     ;;
261                     
262                 *)
263                     echo " $FILE"
264                     echo -n "  cleanup "
265                     (cd $TEMPDIR/tine20/$FILE/js;  rm -rf $(ls | grep -v ${CLIENTBUILDFILTER} | grep -v "\-lang\-" | grep -v "empty\.js"))
266                     (cd $TEMPDIR/tine20/$FILE/css; rm -rf $(ls | grep -v ${CLIENTBUILDFILTER}))
267                     echo "building "
268                     (cd $TEMPDIR/tine20; tar cjf ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.tar.bz2 $FILE)
269                     (cd $TEMPDIR/tine20; zip -qr ../../packages/tine20/$RELEASE/tine20-${UCFILE}_$RELEASE.zip     $FILE)
270                     ;;
271             esac
272             
273         fi
274     done
275 }
276
277 function createSpecialArchives()
278 {
279     echo "building Tine 2.0 allinone archive... "
280     rm -rf $TEMPDIR/allinone
281     mkdir $TEMPDIR/allinone
282     
283     for ARCHIVENAME in activesync calendar tinebase crm felamimail filemanager projects sales tasks timetracker; do
284         (cd $TEMPDIR/allinone; tar xjf ../../packages/tine20/$RELEASE/tine20-${ARCHIVENAME}_$RELEASE.tar.bz2)
285     done
286     
287     (cd $TEMPDIR/allinone; tar cjf ../../packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2 .)
288     (cd $TEMPDIR/allinone; zip -qr ../../packages/tine20/$RELEASE/tine20-allinone_$RELEASE.zip     .)
289     
290
291     echo "building Tine 2.0 voip archive... "
292     rm -rf $TEMPDIR/voip
293     mkdir $TEMPDIR/voip
294     
295     for ARCHIVENAME in phone voipmanager; do
296         (cd $TEMPDIR/voip; tar xjf ../../packages/tine20/$RELEASE/tine20-${ARCHIVENAME}_$RELEASE.tar.bz2)
297     done
298     
299     (cd $TEMPDIR/voip; tar cjf ../../packages/tine20/$RELEASE/tine20-voip_$RELEASE.tar.bz2 .)
300     (cd $TEMPDIR/voip; zip -qr ../../packages/tine20/$RELEASE/tine20-voip_$RELEASE.zip     .)
301 }
302
303 function setupComposer()
304 {
305     wget -O $MISCPACKAGESDIR/composer.phar https://getcomposer.org/composer.phar
306     chmod ugo+x $MISCPACKAGESDIR/composer.phar
307     (cd $MISCPACKAGESDIR; ln -sf composer.phar composer)
308
309     composer install -d $TEMPDIR/tine20
310 }
311
312 function setupPackageDir()
313 {
314     PACKAGEDIR="$BASEDIR/packages/tine20/$RELEASE"
315     rm -rf $PACKAGEDIR
316     mkdir -p $PACKAGEDIR
317 }
318
319 function packageTranslations()
320 {
321     echo -n "building translation files for translators... "
322     php -d include_path=".:$TEMPDIR/tine20:$TEMPDIR/tine20/library"  -f $TEMPDIR/tine20/langHelper.php -- --package=translations.tar.gz
323     mv $TEMPDIR/tine20/translations.tar.gz $PACKAGEDIR
324     echo "done"
325 }
326
327 function buildChecksum()
328 {
329     echo -n "calculating SHA1 checksums... "
330     
331     test -e $PACKAGEDIR/sha1sum_$RELEASE.txt && rm $PACKAGEDIR/sha1sum_$RELEASE.txt
332     
333     for fileName in $PACKAGEDIR/*; do
334         (cd $PACKAGEDIR; sha1sum `basename $fileName`) >> $PACKAGEDIR/sha1sum_$RELEASE.txt 2>&1
335     done
336     
337     echo "done"
338 }
339
340 function prepareDebianPackaging()
341 {
342     PACKAGEDIR="$BASEDIR/packages/debian/$RELEASE"
343     rm -rf $PACKAGEDIR
344     
345     # Replace all matches of - with .
346     DEBIANVERSION=${RELEASE//-/.}
347
348     mkdir -p "$PACKAGEDIR/tine20-$DEBIANVERSION"
349     
350     echo -n "preparing debian packaging directory in $PACKAGEDIR/tine20-$DEBIANVERSION ... "
351     
352     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2
353     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2
354     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2
355     cp $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig.tar.bz2
356     cp $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig-Courses.tar.bz2
357     cp $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig-HumanResources.tar.bz2
358     cp -r $BASEDIR/temp/debian $PACKAGEDIR/tine20-$DEBIANVERSION
359
360     echo "done"
361 }
362
363 function prepareUniventionPackaging()
364 {
365     PACKAGEDIR="$BASEDIR/packages/univention/$RELEASE"
366     rm -rf $PACKAGEDIR
367     
368     # Replace all matches of - with .
369     DEBIANVERSION=${RELEASE//-/.}
370
371     mkdir -p "$PACKAGEDIR/tine20-$DEBIANVERSION"
372     
373     echo -n "preparing univention packaging directory in $PACKAGEDIR/tine20-$DEBIANVERSION ... "
374     
375     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2
376     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2
377     tar -C $PACKAGEDIR/tine20-$DEBIANVERSION -xf $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2
378     cp $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig.tar.bz2
379     cp $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig-Courses.tar.bz2
380     cp $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2 $PACKAGEDIR/tine20_$DEBIANVERSION.orig-HumanResources.tar.bz2
381     cp -r $BASEDIR/temp/Univention/* $PACKAGEDIR/tine20-$DEBIANVERSION
382
383     echo "done"
384 }
385
386 function prepareFedoraPackaging()
387 {
388     PACKAGEDIR="$BASEDIR/packages/fedora/$RELEASE"
389     rm -rf $PACKAGEDIR
390     
391     # Replace all matches of - with .
392     RPMVERSION=${RELEASE//-/.}
393
394     mkdir -p "$PACKAGEDIR/tine20-$RPMVERSION"
395     
396     echo -n "preparing fedora packaging directory in $PACKAGEDIR/tine20-$RPMVERSION ... "
397     
398     cp -r $BASEDIR/temp/fedora/* $PACKAGEDIR/tine20-$RPMVERSION/
399     
400     cp $BASEDIR/packages/tine20/$RELEASE/tine20-allinone_$RELEASE.tar.bz2 $PACKAGEDIR/tine20-$RPMVERSION/SOURCES/
401     cp $BASEDIR/packages/tine20/$RELEASE/tine20-courses_$RELEASE.tar.bz2 $PACKAGEDIR/tine20-$RPMVERSION/SOURCES/
402     cp $BASEDIR/packages/tine20/$RELEASE/tine20-humanresources_$RELEASE.tar.bz2 $PACKAGEDIR/tine20-$RPMVERSION/SOURCES/
403
404     echo "done"
405 }
406
407 getOptions "$@"
408
409 createDirectories
410 checkout "$GITURL" "$GITBRANCH"
411 setupComposer
412 setupPackageDir
413 activateReleaseMode
414 buildLangStats
415 buildClient
416 createArchives
417 createSpecialArchives
418 packageTranslations
419 buildChecksum
420 prepareDebianPackaging
421 prepareFedoraPackaging
422 prepareUniventionPackaging