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.
6 #############################
8 #############################
10 ##Select the build target
11 BUILD_TARGET=${1:-none}
14 #BUILD_TARGET=debian_i386
15 #BUILD_TARGET=debian_amd64
16 #BUILD_TARGET=debian_armhf
19 ##Do we need to create the final archive
20 ARCHIVE_FOR_DISTRIBUTION=1
21 ##Which version name are we appending to the final archive
22 export BUILD_NAME=14.10-RC4
23 TARGET_DIR=Cura-${BUILD_NAME}-${BUILD_TARGET}
29 GIT_HASH=$(git rev-parse --short=4 HEAD)
31 ##Which versions of external programs to use
32 WIN_PORTABLE_PY_VERSION=2.7.2.1
34 ##Which CuraEngine to use
35 if [ -z ${CURA_ENGINE_REPO} ] ; then
36 CURA_ENGINE_REPO="https://github.com/alephobjects/CuraEngine"
39 #############################
41 #############################
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"
53 filename=`basename "$1"`
54 echo "Checking for $filename"
55 if [ ! -f "$filename" ]; then
59 echo "Failed to download $1"
68 echo "7z x -y $*" >> log.txt
71 echo "Failed to extract $*"
76 #############################
78 #############################
79 if [ "$BUILD_TARGET" = "none" ]; then
80 echo "You need to specify a build target with:"
83 echo "$0 debian_amd64"
84 echo "$0 debian_armhf"
90 if [ -z `which make` ]; then
96 # Change working directory to the directory the script is in
97 # http://stackoverflow.com/a/246128
98 SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
101 checkTool git "git: http://git-scm.com/"
102 checkTool curl "curl: http://curl.haxx.se/"
103 if [ $BUILD_TARGET = "win32" ]; then
104 #Check if we have 7zip, needed to extract and packup a bunch of packages for windows.
105 checkTool 7z "7zip: http://www.7-zip.org/"
106 checkTool $MAKE "mingw: http://www.mingw.org/"
108 #For building under MacOS we need gnutar instead of tar
109 if [ -z `which gnutar` ]; then
116 #############################
118 #############################
120 if [ "$BUILD_TARGET" = "darwin" ]; then
121 TARGET_DIR=Cura-${BUILD_NAME}-MacOS
123 rm -rf scripts/darwin/build
124 rm -rf scripts/darwin/dist
126 python build_app.py py2app
128 if [[ $rc != 0 ]]; then
129 echo "Cannot build app."
133 #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
134 echo $BUILD_NAME > scripts/darwin/dist/Cura.app/Contents/Resources/version
136 git clone ${CURA_ENGINE_REPO}
137 if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
138 $MAKE -C CuraEngine VERSION=${BUILD_NAME}
139 if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
140 cp CuraEngine/build/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
144 # Install QuickLook plugin
145 mkdir -p dist/Cura.app/Contents/Library/QuickLook
146 cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
150 $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
153 # Create sparse image for distribution
154 hdiutil detach /Volumes/Cura\ -\ Lulzbot/
155 rm -rf Cura.dmg.sparseimage
156 hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
157 hdiutil resize -size 500m Cura.dmg.sparseimage
158 hdiutil attach Cura.dmg.sparseimage
159 cp -a dist/Cura.app /Volumes/Cura\ -\ Lulzbot/Cura/
160 hdiutil detach /Volumes/Cura\ -\ Lulzbot
161 hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
165 #############################
166 # FreeBSD part by CeDeROM
167 #############################
169 if [ "$BUILD_TARGET" = "freebsd" ]; then
172 if [ ! -d "Power" ]; then
173 git clone https://github.com/GreatFruitOmsk/Power
180 git clone ${CURA_ENGINE_REPO}
181 if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
182 gmake -j4 -C CuraEngine VERSION=${BUILD_NAME}
183 if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
184 rm -rf scripts/freebsd/dist
185 mkdir -p scripts/freebsd/dist/share/cura
186 mkdir -p scripts/freebsd/dist/share/applications
187 mkdir -p scripts/freebsd/dist/bin
188 cp -a Cura scripts/freebsd/dist/share/cura/
189 cp -a resources scripts/freebsd/dist/share/cura/
190 cp -a plugins scripts/freebsd/dist/share/cura/
191 cp -a CuraEngine/build/CuraEngine scripts/freebsd/dist/share/cura/
192 cp scripts/freebsd/cura.py scripts/freebsd/dist/share/cura/
193 cp scripts/freebsd/cura.desktop scripts/freebsd/dist/share/applications/
194 cp scripts/freebsd/cura scripts/freebsd/dist/bin/
195 cp -a Power/power scripts/freebsd/dist/share/cura/
196 echo $BUILD_NAME > scripts/freebsd/dist/share/cura/Cura/version
197 #Create file list (pkg-plist)
198 cd scripts/freebsd/dist
199 find * -type f > ../pkg-plist
200 DIRLVL=20; while [ $DIRLVL -ge 0 ]; do
201 DIRS=`find share/cura -type d -depth $DIRLVL`
203 echo "@dirrm $DIR" >> ../pkg-plist
205 DIRLVL=`expr $DIRLVL - 1`
208 # Create archive or package if root
209 if [ `whoami` == "root" ]; then
210 echo "Are you root? Use the Port Luke! :-)"
212 echo "You are not root, building simple package archive..."
214 $TAR czf ../../${TARGET_DIR}.tar.gz dist/**
219 #############################
221 #############################
223 if [ "$BUILD_TARGET" = "debian_i386" ]; then
224 export CXX="g++ -m32"
225 if [ ! -d "Power" ]; then
226 git clone https://github.com/GreatFruitOmsk/Power
233 git clone ${CURA_ENGINE_REPO}
234 if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
235 $MAKE -C CuraEngine VERSION=${BUILD_NAME}
236 if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
237 rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
238 mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
239 cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
240 cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
241 cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
242 cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
243 cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
244 cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
245 echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
246 sudo chown root:root scripts/linux/${BUILD_TARGET} -R
247 sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
248 sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
250 dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}_i386.deb
251 sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
255 #############################
257 #############################
259 if [ "$BUILD_TARGET" = "debian_amd64" ]; then
260 export CXX="g++ -m64"
261 if [ ! -d "Power" ]; then
262 git clone https://github.com/GreatFruitOmsk/Power
269 git clone ${CURA_ENGINE_REPO}
270 if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
271 $MAKE -C CuraEngine VERSION=${BUILD_NAME}
272 if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
273 rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
274 mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
275 cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
276 cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
277 cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
278 cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
279 cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
280 cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
281 echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
282 sudo chown root:root scripts/linux/${BUILD_TARGET} -R
283 sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
284 sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
286 dpkg-deb -Zgzip --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}_amd64.deb
287 sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
291 #############################
293 #############################
295 if [ "$BUILD_TARGET" = "debian_armhf" ]; then
297 if [ ! -d "Power" ]; then
298 git clone https://github.com/GreatFruitOmsk/Power
305 git clone ${CURA_ENGINE_REPO}
306 if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
307 $MAKE -C CuraEngine VERSION=${BUILD_NAME}
308 if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
309 rm -rf scripts/linux/${BUILD_TARGET}/usr/share/cura
310 mkdir -p scripts/linux/${BUILD_TARGET}/usr/share/cura
311 cp -a Cura scripts/linux/${BUILD_TARGET}/usr/share/cura/
312 cp -a resources scripts/linux/${BUILD_TARGET}/usr/share/cura/
313 cp -a plugins scripts/linux/${BUILD_TARGET}/usr/share/cura/
314 cp -a CuraEngine/build/CuraEngine scripts/linux/${BUILD_TARGET}/usr/share/cura/
315 cp scripts/linux/cura.py scripts/linux/${BUILD_TARGET}/usr/share/cura/
316 cp -a Power/power scripts/linux/${BUILD_TARGET}/usr/share/cura/
317 echo $BUILD_NAME > scripts/linux/${BUILD_TARGET}/usr/share/cura/Cura/version
318 sudo chown root:root scripts/linux/${BUILD_TARGET} -R
319 sudo chmod 755 scripts/linux/${BUILD_TARGET}/usr -R
320 sudo chmod 755 scripts/linux/${BUILD_TARGET}/DEBIAN -R
322 dpkg-deb --build ${BUILD_TARGET} $(dirname ${TARGET_DIR})/cura_${BUILD_NAME}-${BUILD_TARGET}.deb
323 sudo chown `id -un`:`id -gn` ${BUILD_TARGET} -R
327 #############################
329 #############################
331 #############################
332 # Download all needed files.
333 #############################
335 if [ $BUILD_TARGET = "win32" ]; then
336 #Get portable python for windows and extract it. (Linux and Mac need to install python themselfs)
337 downloadURL http://ftp.nluug.nl/languages/python/portablepython/v2.7/PortablePython_${WIN_PORTABLE_PY_VERSION}.exe
338 downloadURL http://sourceforge.net/projects/pyserial/files/pyserial/2.5/pyserial-2.5.win32.exe
339 downloadURL http://sourceforge.net/projects/pyopengl/files/PyOpenGL/3.0.1/PyOpenGL-3.0.1.win32.exe
340 downloadURL http://sourceforge.net/projects/numpy/files/NumPy/1.6.2/numpy-1.6.2-win32-superpack-python2.7.exe
341 downloadURL http://videocapture.sourceforge.net/VideoCapture-0.9-5.zip
342 #downloadURL http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20120927-git-13f0cd6-win32-static.7z
343 downloadURL http://sourceforge.net/projects/comtypes/files/comtypes/0.6.2/comtypes-0.6.2.win32.exe
344 downloadURL http://www.uwe-sieber.de/files/ejectmedia.zip
345 #Get the power module for python
347 git clone https://github.com/GreatFruitOmsk/Power
349 git clone ${CURA_ENGINE_REPO}
350 if [ $? != 0 ]; then echo "Failed to clone CuraEngine"; exit 1; fi
353 #############################
355 #############################
357 mkdir -p ${TARGET_DIR}
360 if [ $BUILD_TARGET = "win32" ]; then
361 if [ -z `which i686-w64-mingw32-g++` ]; then
364 CXX=i686-w64-mingw32-g++
367 #For windows extract portable python to include it.
368 extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/App
369 extract PortablePython_${WIN_PORTABLE_PY_VERSION}.exe \$_OUTDIR/Lib/site-packages
370 extract pyserial-2.5.win32.exe PURELIB
371 extract PyOpenGL-3.0.1.win32.exe PURELIB
372 extract numpy-1.6.2-win32-superpack-python2.7.exe numpy-1.6.2-sse2.exe
373 extract numpy-1.6.2-sse2.exe PLATLIB
374 extract VideoCapture-0.9-5.zip VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd
375 #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe
376 #extract ffmpeg-20120927-git-13f0cd6-win32-static.7z ffmpeg-20120927-git-13f0cd6-win32-static/licenses
377 extract comtypes-0.6.2.win32.exe
378 extract ejectmedia.zip Win32
380 mkdir -p ${TARGET_DIR}/python
381 mkdir -p ${TARGET_DIR}/Cura/
382 mv \$_OUTDIR/App/* ${TARGET_DIR}/python
383 mv \$_OUTDIR/Lib/site-packages/wx* ${TARGET_DIR}/python/Lib/site-packages/
384 mv PURELIB/serial ${TARGET_DIR}/python/Lib
385 mv PURELIB/OpenGL ${TARGET_DIR}/python/Lib
386 mv PURELIB/comtypes ${TARGET_DIR}/python/Lib
387 mv PLATLIB/numpy ${TARGET_DIR}/python/Lib
388 mv Power/power ${TARGET_DIR}/python/Lib
389 mv VideoCapture-0.9-5/Python27/DLLs/vidcap.pyd ${TARGET_DIR}/python/DLLs
390 #mv ffmpeg-20120927-git-13f0cd6-win32-static/bin/ffmpeg.exe ${TARGET_DIR}/Cura/
391 #mv ffmpeg-20120927-git-13f0cd6-win32-static/licenses ${TARGET_DIR}/Cura/ffmpeg-licenses/
392 mv Win32/EjectMedia.exe ${TARGET_DIR}/Cura/
393 cp -a scripts/win32/nsisPlugins/libgcc_s_dw2-1.dll ${TARGET_DIR}
394 cp -a scripts/win32/nsisPlugins/libstdc++-6.dll ${TARGET_DIR}
400 rm -rf VideoCapture-0.9-5
401 rm -rf numpy-1.6.2-sse2.exe
402 #rm -rf ffmpeg-20120927-git-13f0cd6-win32-static
404 #Clean up portable python a bit, to keep the package size down.
405 rm -rf ${TARGET_DIR}/python/PyScripter.*
406 rm -rf ${TARGET_DIR}/python/Doc
407 rm -rf ${TARGET_DIR}/python/locale
408 rm -rf ${TARGET_DIR}/python/tcl
409 rm -rf ${TARGET_DIR}/python/Lib/test
410 rm -rf ${TARGET_DIR}/python/Lib/distutils
411 rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/tools
412 rm -rf ${TARGET_DIR}/python/Lib/site-packages/wx-2.8-msw-unicode/wx/locale
413 #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.
414 rm -rf ${TARGET_DIR}/python/Lib/OpenGL/DLLS/gle*
416 #Build the C++ engine
417 $MAKE -C CuraEngine VERSION=${BUILD_NAME} OS=Windows_NT CXX=${CXX}
418 if [ $? != 0 ]; then echo "Failed to build CuraEngine"; exit 1; fi
422 mkdir -p ${TARGET_DIR}/Cura ${TARGET_DIR}/resources ${TARGET_DIR}/plugins
423 cp -a Cura/* ${TARGET_DIR}/Cura
424 cp -a resources/* ${TARGET_DIR}/resources
425 cp -a plugins/* ${TARGET_DIR}/plugins
426 #Add cura version file
427 echo $BUILD_NAME > ${TARGET_DIR}/Cura/version
430 if [ $BUILD_TARGET = "win32" ]; then
431 cp -a scripts/${BUILD_TARGET}/*.bat $TARGET_DIR/
432 cp CuraEngine/build/CuraEngine.exe $TARGET_DIR
434 cp -a scripts/${BUILD_TARGET}/*.sh $TARGET_DIR/
438 if (( ${ARCHIVE_FOR_DISTRIBUTION} )); then
439 if [ $BUILD_TARGET = "win32" ]; then
440 #rm ${TARGET_DIR}.zip
442 #7z a ../${TARGET_DIR}.zip *
445 if [ ! -z `which wine` ]; then
446 #if we have wine, try to run our nsis script.
447 rm -rf scripts/win32/dist
448 ln -sf `pwd`/${TARGET_DIR} scripts/win32/dist
449 wine ~/.wine/drive_c/Program\ Files\ \(x86\)/NSIS/makensis.exe /DVERSION=${BUILD_NAME} scripts/win32/installer.nsi
450 if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
451 mv scripts/win32/Cura_${BUILD_NAME}-${REVISION}-${GIT_HASH}.exe ./
453 if [ -f '/c/Program Files (x86)/NSIS/makensis.exe' ]; then
454 rm -rf scripts/win32/dist
455 mv `pwd`/${TARGET_DIR} scripts/win32/dist
456 '/c/Program Files (x86)/NSIS/makensis.exe' -DVERSION=${BUILD_NAME} 'scripts/win32/installer.nsi' >> log.txt
457 if [ $? != 0 ]; then echo "Failed to package NSIS installer"; exit 1; fi
458 mv scripts/win32/Cura_${BUILD_NAME}.exe ./
461 echo "Archiving to ${TARGET_DIR}.tar.gz"
462 $TAR cfp - ${TARGET_DIR} | gzip --best -c > ${TARGET_DIR}.tar.gz
465 echo "Installed into ${TARGET_DIR}"