+
+#############################
+# Darwin
+#############################
+
+if [ "$BUILD_TARGET" = "darwin" ]; then
+ TARGET_DIR=Cura-${BUILD_NAME}-MacOS
+
+ rm -rf scripts/darwin/build
+ rm -rf scripts/darwin/dist
+
+ python build_app.py py2app
+ rc=$?
+ if [[ $rc != 0 ]]; then
+ echo "Cannot build app."
+ exit 1
+ fi
+
+ #Add cura version file (should read the version from the bundle with pyobjc, but will figure that out later)
+ echo $BUILD_NAME > scripts/darwin/dist/Cura.app/Contents/Resources/version
+ rm -rf CuraEngine
+ git clone ${CURA_ENGINE_REPO}
+ make -C CuraEngine
+ cp CuraEngine/CuraEngine scripts/darwin/dist/Cura.app/Contents/Resources/CuraEngine
+
+ cd scripts/darwin
+
+ # Install QuickLook plugin
+ mkdir -p dist/Cura.app/Contents/Library/QuickLook
+ cp -a STLQuickLook.qlgenerator dist/Cura.app/Contents/Library/QuickLook/
+
+ # Archive app
+ cd dist
+ $TAR cfp - Cura.app | gzip --best -c > ../../../${TARGET_DIR}.tar.gz
+ cd ..
+
+ # Create sparse image for distribution
+ hdiutil detach /Volumes/Cura\ -\ Ultimaker/
+ rm -rf Cura.dmg.sparseimage
+ hdiutil convert DmgTemplateCompressed.dmg -format UDSP -o Cura.dmg
+ hdiutil resize -size 500m Cura.dmg.sparseimage
+ hdiutil attach Cura.dmg.sparseimage
+ cp -a dist/Cura.app /Volumes/Cura\ -\ Ultimaker/Cura/
+ hdiutil detach /Volumes/Cura\ -\ Ultimaker
+ hdiutil convert Cura.dmg.sparseimage -format UDZO -imagekey zlib-level=9 -ov -o ../../${TARGET_DIR}.dmg
+ exit
+fi
+
+#############################
+# Debian .deb
+#############################
+
+if [ "$BUILD_TARGET" = "debian" ]; then
+ if [ ! -d "Power" ]; then
+ git clone https://github.com/GreatFruitOmsk/Power
+ else
+ cd Power
+ git pull
+ cd ..
+ fi
+ rm -rf CuraEngine
+ git clone ${CURA_ENGINE_REPO}
+ make -C CuraEngine
+ rm -rf scripts/linux/debian/usr/share/cura
+ mkdir -p scripts/linux/debian/usr/share/cura
+ cp -a Cura scripts/linux/debian/usr/share/cura/
+ cp -a CuraEngine/CuraEngine scripts/linux/debian/usr/share/cura/
+ cp scripts/linux/cura.py scripts/linux/debian/usr/share/cura/
+ cp -a Power/power scripts/linux/debian/usr/share/cura/
+ echo $BUILD_NAME > scripts/linux/debian/usr/share/cura/Cura/version
+ sudo chown root:root scripts/linux/debian -R
+ sudo chmod 755 scripts/linux/debian/usr -R
+ sudo chmod 755 scripts/linux/debian/DEBIAN -R
+ cd scripts/linux
+ dpkg-deb --build debian ${TARGET_DIR}.deb
+ sudo chown `id -un`:`id -gn` debian -R
+ exit
+fi
+
+#############################
+# Rest
+#############################
+