chiark / gitweb /
Debian packaging now includes incremental release number.
[cura.git] / package.sh
1 #!/usr/bin/env bash
2
3 # This script is to package the Cura package for Windows/Linux and Mac OS X
4 # This script should run under Linux and Mac OS X, as well as Windows with Cygwin.
5
6 #############################
7 # CONFIGURATION
8 #############################
9
10 ##Select the build target
11 BUILD_TARGET=${1:-none}
12 #BUILD_TARGET=win32
13 #BUILD_TARGET=darwin
14 #BUILD_TARGET=debian_i386
15 #BUILD_TARGET=debian_amd64
16 #BUILD_TARGET=freebsd
17
18 ##Do we need to create the final archive
19 ARCHIVE_FOR_DISTRIBUTION=1
20 ##Which version name are we appending to the final archive
21 export BUILD_NAME=14.09
22 TARGET_DIR=Cura-${BUILD_NAME}-${BUILD_TARGET}
23
24 ##Debian package release
25 debian_64_release_counter=scripts/linux/debian_amd64_release
26 debian_64_release=$(<$debian_64_release_counter)
27 debian_32_release_counter=scripts/linux/debian_i386_release
28 debian_32_release=$(<$debian_32_release_counter)
29
30
31 ##Which versions of external programs to use
32 WIN_PORTABLE_PY_VERSION=2.7.2.1
33
34 ##Which CuraEngine to use
35 if [ -z ${CURA_ENGINE_REPO} ] ; then
36         CURA_ENGINE_REPO="https://github.com/alephobjects/CuraEngine"
37 fi
38
39 #############################
40 # Support functions
41 #############################
42 function checkTool
43 {
44         if [ -z "`which $1`" ]; then
45                 echo "The $1 command must be somewhere in your \$PATH."
46                 echo "Fix your \$PATH or install $2"
47                 exit 1
48         fi
49 }
50
51 function downloadURL
52 {
53         filename=`basename "$1"`
54         echo "Checking for $filename"
55         if [ ! -f "$filename" ]; then
56                 echo "Downloading $1"
57                 curl -L -O "$1"
58                 if [ $? != 0 ]; then
59                         echo "Failed to download $1"
60                         exit 1
61                 fi
62         fi
63 }
64
65 function extract
66 {
67         echo "Extracting $*"
68         echo "7z x -y $*" >> log.txt
69         7z x -y $* >> log.txt
70         if [ $? != 0 ]; then
71         echo "Failed to extract $*"
72         exit 1
73         fi
74 }
75
76 #############################
77 # Actual build script
78 #############################
79 if [ "$BUILD_TARGET" = "none" ]; then
80         echo "You need to specify a build target with:"
81         echo "$0 win32"
82         echo "$0 debian_i368"
83         echo "$0 debian_amd64"
84         echo "$0 darwin"
85         echo "$0 freebsd"
86         exit 0
87 fi
88
89 # Change working directory to the directory the script is in
90 # http://stackoverflow.com/a/246128
91 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
92 cd $SCRIPT_DIR
93
94 checkTool git "git: http://git-scm.com/"
95 checkTool curl "curl: http://curl.haxx.se/"
96 if [ $BUILD_TARGET = "win32" ]; then
97         #Check if we have 7zip, needed to extract and packup a bunch of packages for windows.
98         checkTool 7z "7zip: http://www.7-zip.org/"
99         checkTool mingw32-make "mingw: http://www.mingw.org/"
100 fi
101 #For building under MacOS we need gnutar instead of tar
102 if [ -z `which gnutar` ]; then
103         TAR=tar
104 else
105         TAR=gnutar
106 fi
107
108
109 #############################
110 # Darwin
111 #############################
112
113 if [ "$BUILD_TARGET" = "darwin" ]; then
114     TARGET_DIR=Cura-${BUILD_NAME}-MacOS
115
116         rm -rf scripts/darwin/build
117         rm -rf scripts/darwin/dist
118
119         python build_app.py py2app
120         rc=$?
121         if [[ $rc != 0 ]]; then
122                 echo "Cannot build app."
123                 exit 1
124         fi
125
126     #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
127     echo $BUILD_NAME > scripts/darwin/dist/Cura.app/Contents/Resources/version
128         rm -rf CuraEngine
129         git clone ${CURA_ENGINE_REPO}
130     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
131         make -C CuraEngine VERSION=${BUILD_NAME}
132     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
133         cp CuraEngine/build/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
134
135         cd scripts/darwin
136
137         # Install QuickLook plugin
138         mkdir -p dist/Cura.app/Contents/Library/QuickLook
139         cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
140
141         # Archive app
142         cd dist
143         $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
144         cd ..
145
146         # Create sparse image for distribution
147         hdiutil detach /Volumes/Cura\ -\ Ultimaker/
148         rm -rf Cura.dmg.sparseimage
149         hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
150         hdiutil resize -size 500m Cura.dmg.sparseimage
151         hdiutil attach Cura.dmg.sparseimage
152         cp -a dist/Cura.app /Volumes/Cura\ -\ Ultimaker/Cura/
153         hdiutil detach /Volumes/Cura\ -\ Ultimaker
154         hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
155         exit
156 fi
157
158 #############################
159 # FreeBSD part by CeDeROM
160 #############################
161
162 if [ "$BUILD_TARGET" = "freebsd" ]; then
163         export CXX="c++"
164         rm -rf Power
165         if [ ! -d "Power" ]; then
166                 git clone https://github.com/GreatFruitOmsk/Power
167         else
168                 cd Power
169                 git pull
170                 cd ..
171         fi
172         rm -rf CuraEngine
173         git clone ${CURA_ENGINE_REPO}
174     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
175         gmake -j4 -C CuraEngine VERSION=${BUILD_NAME}
176     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
177         rm -rf scripts/freebsd/dist
178         mkdir -p scripts/freebsd/dist/share/cura
179         mkdir -p scripts/freebsd/dist/share/applications
180         mkdir -p scripts/freebsd/dist/bin
181         cp -a Cura scripts/freebsd/dist/share/cura/
182         cp -a resources scripts/freebsd/dist/share/cura/
183         cp -a plugins scripts/freebsd/dist/share/cura/
184         cp -a CuraEngine/build/CuraEngine scripts/freebsd/dist/share/cura/
185         cp scripts/freebsd/cura.py scripts/freebsd/dist/share/cura/
186         cp scripts/freebsd/cura.desktop scripts/freebsd/dist/share/applications/
187         cp scripts/freebsd/cura scripts/freebsd/dist/bin/
188         cp -a Power/power scripts/freebsd/dist/share/cura/
189         echo $BUILD_NAME > scripts/freebsd/dist/share/cura/Cura/version
190         #Create file list (pkg-plist)
191         cd scripts/freebsd/dist
192         find * -type f > ../pkg-plist
193         DIRLVL=20; while [ $DIRLVL -ge 0 ]; do
194                 DIRS=`find share/cura -type d -depth $DIRLVL`
195                 for DIR in $DIRS; do
196                         echo "@dirrm $DIR" >> ../pkg-plist
197                 done
198                 DIRLVL=`expr $DIRLVL - 1`
199         done
200         cd ..
201         # Create archive or package if root
202         if [ `whoami` == "root" ]; then
203             echo "Are you root? Use the Port Luke! :-)"
204         else
205             echo "You are not root, building simple package archive..."
206             pwd
207             $TAR czf ../../${TARGET_DIR}.tar.gz dist/**
208         fi
209         exit
210 fi
211
212 #############################
213 # Debian 32bit .deb
214 #############################
215
216 if [ "$BUILD_TARGET" = "debian_i386" ]; then
217         ((debian_32_release += 1))
218         echo $debian_32_release > $debian_32_release_counter
219     export CXX="g++ -m32"
220         if [ ! -d "Power" ]; then
221                 git clone https://github.com/GreatFruitOmsk/Power
222         else
223                 cd Power
224                 git pull
225                 cd ..
226         fi
227         rm -rf CuraEngine
228         git clone ${CURA_ENGINE_REPO}
229     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
230         make -C CuraEngine VERSION=${BUILD_NAME}
231     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
232         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
233         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
234         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
235         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
236         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
237         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
238         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
239         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
240         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
241         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
242         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
243         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
244         cd scripts/linux
245         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${debian_32_release}-${BUILD_TARGET}.deb
246         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
247         exit
248 fi
249
250 #############################
251 # Debian 64bit .deb
252 #############################
253
254 if [ "$BUILD_TARGET" = "debian_amd64" ]; then
255         ((debian_64_release += 1))
256         echo $debian_64_release > $debian_64_release_counter
257     export CXX="g++ -m64"
258         if [ ! -d "Power" ]; then
259                 git clone https://github.com/GreatFruitOmsk/Power
260         else
261                 cd Power
262                 git pull
263                 cd ..
264         fi
265         rm -rf CuraEngine
266         git clone ${CURA_ENGINE_REPO}
267     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
268         make -C CuraEngine
269     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
270         rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
271         mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
272         cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
273         cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
274         cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
275         cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
276         cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
277         cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
278         echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
279         sudo chown root:root scripts/linux/${BUILD_TARGET} -R
280         sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
281         sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
282         cd scripts/linux
283         dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${debian_64_release}-${BUILD_TARGET}.deb
284         sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
285         exit
286 fi
287
288 #############################
289 # Rest
290 #############################
291
292 #############################
293 # Download all needed files.
294 #############################
295
296 if [ $BUILD_TARGET = "win32" ]; then
297         #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
298         downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
299         downloadURL http://sourceforge.net/projects/pyserial/files/pyserial/2.5/pyserial-2.5.win32.exe
300         downloadURL http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
301         downloadURL http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/numpy-1.6.2-win32-superpack-python2.7.exe
302         downloadURL http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip
303         #downloadURL http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20120927-git-13f0cd6-win32-static.7z
304         downloadURL http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe
305         downloadURL http://www.uwe-sieber.de/files/ejectmedia.zip
306         #Get the power module for python
307         rm -rf Power
308         git clone https://github.com/GreatFruitOmsk/Power
309         rm -rf CuraEngine
310         git clone ${CURA_ENGINE_REPO}
311     if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
312 fi
313
314 #############################
315 # Build the packages
316 #############################
317 rm -rf ${TARGET_DIR}
318 mkdir -p ${TARGET_DIR}
319
320 rm -f log.txt
321 if [ $BUILD_TARGET = "win32" ]; then
322         #For windows extract portable python to include it.
323         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
324         extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
325         extract pyserial-2.5.win32.exe PURELIB
326         extract PyOpenGL-3.0.1.win32.exe PURELIB
327         extract numpy-1.6.2-win32-superpack-python2.7.exe numpy-1.6.2-sse2.exe
328         extract numpy-1.6.2-sse2.exe PLATLIB
329         extract VideoCapture-0.9-5.zip VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd
330         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe
331         #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/licenses
332         extract comtypes-0.6.2.win32.exe
333         extract ejectmedia.zip Win32
334
335         mkdir -p ${TARGET_DIR}/python
336         mkdir -p ${TARGET_DIR}/Cura/
337         mv \$_OUTDIR/App/* ${TARGET_DIR}/python
338         mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
339         mv PURELIB/serial ${TARGET_DIR}/python/Lib
340         mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
341         mv PURELIB/comtypes ${TARGET_DIR}/python/Lib
342         mv PLATLIB/numpy ${TARGET_DIR}/python/Lib
343         mv Power/power ${TARGET_DIR}/python/Lib
344         mv VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd ${TARGET_DIR}/python/DLLs
345         #mv ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe ${TARGET_DIR}/Cura/
346         #mv ffmpeg-20120927-git-13f0cd6-win32-static/licenses ${TARGET_DIR}/Cura/ffmpeg-licenses/
347         mv Win32/EjectMedia.exe ${TARGET_DIR}/Cura/
348         
349         rm -rf Power/
350         rm -rf \$_OUTDIR
351         rm -rf PURELIB
352         rm -rf PLATLIB
353         rm -rf VideoCapture-0.9-5
354         rm -rf numpy-1.6.2-sse2.exe
355         #rm -rf ffmpeg-20120927-git-13f0cd6-win32-static
356
357         #Clean up portable python a bit, to keep the package size down.
358         rm -rf ${TARGET_DIR}/python/PyScripter.*
359         rm -rf ${TARGET_DIR}/python/Doc
360         rm -rf ${TARGET_DIR}/python/locale
361         rm -rf ${TARGET_DIR}/python/tcl
362         rm -rf ${TARGET_DIR}/python/Lib/test
363         rm -rf ${TARGET_DIR}/python/Lib/distutils
364         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
365         rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/locale
366         #Remove the gle files because they require MSVCR71.dll, which is not included. We also don't need gle, so it's safe to remove it.
367         rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
368
369     #Build the C++ engine
370         mingw32-make -C CuraEngine VERSION=${BUILD_NAME}
371     if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
372 fi
373
374 #add Cura
375 mkdir -p ${TARGET_DIR}/Cura ${TARGET_DIR}/resources ${TARGET_DIR}/plugins
376 cp -a Cura/* ${TARGET_DIR}/Cura
377 cp -a resources/* ${TARGET_DIR}/resources
378 cp -a plugins/* ${TARGET_DIR}/plugins
379 #Add cura version file
380 echo $BUILD_NAME > ${TARGET_DIR}/Cura/version
381
382 #add script files
383 if [ $BUILD_TARGET = "win32" ]; then
384     cp -a scripts/${BUILD_TARGET}/*.bat $TARGET_DIR/
385     cp CuraEngine/build/CuraEngine.exe $TARGET_DIR
386 else
387     cp -a scripts/${BUILD_TARGET}/*.sh $TARGET_DIR/
388 fi
389
390 #package the result
391 if (( ${ARCHIVE_FOR_DISTRIBUTION} )); then
392         if [ $BUILD_TARGET = "win32" ]; then
393                 #rm ${TARGET_DIR}.zip
394                 #cd ${TARGET_DIR}
395                 #7z a ../${TARGET_DIR}.zip *
396                 #cd ..
397
398                 if [ ! -z `which wine` ]; then
399                         #if we have wine, try to run our nsis script.
400                         rm -rf scripts/win32/dist
401                         ln -sf `pwd`/${TARGET_DIR} scripts/win32/dist
402                         wine ~/.wine/drive_c/Program\ Files/NSIS/makensis.exe /DVERSION=${BUILD_NAME} scripts/win32/installer.nsi
403             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
404                         mv scripts/win32/Cura_${BUILD_NAME}.exe ./
405                 fi
406                 if [ -f '/c/Program Files (x86)/NSIS/makensis.exe' ]; then
407                         rm -rf scripts/win32/dist
408                         mv `pwd`/${TARGET_DIR} scripts/win32/dist
409                         '/c/Program Files (x86)/NSIS/makensis.exe' -DVERSION=${BUILD_NAME} 'scripts/win32/installer.nsi' >> log.txt
410             if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
411                         mv scripts/win32/Cura_${BUILD_NAME}.exe ./
412                 fi
413         else
414                 echo "Archiving to ${TARGET_DIR}.tar.gz"
415                 $TAR cfp - ${TARGET_DIR} | gzip --best -c > ${TARGET_DIR}.tar.gz
416         fi
417 else
418         echo "Installed into ${TARGET_DIR}"
419 fi