chiark / gitweb /
Fix resources, imports and indentations.
[cura.git] / scripts / osx64 / Cura.app / Contents / MacOS / Cura
1 #!/bin/sh
2
3 SCRIPTDIR=`dirname "$0"`
4 RESDIR=${SCRIPTDIR}/../Resources/
5 PKGDIR=${SCRIPTDIR}/../Pkgs/
6
7 #run the path_helper to set the $PATH for accessing python
8 if [ -x /usr/libexec/path_helper ]; then
9         eval `/usr/libexec/path_helper -s`
10 fi
11
12 displayMessage()
13 {
14         /usr/bin/osascript > /dev/null <<-EOF
15 tell application "System Events"
16         activate
17         display dialog "$@" buttons {"Ok"}
18 end tell
19 EOF
20 }
21
22 #Testing for python2.7, which we need and is not always installed on MacOS 1.6
23 PY="python2.7"
24 $PY -c ''
25 if [ $? != 0 ]; then
26         displayMessage "Python 2.7 is missing from your system. Cura requires Python2.7.\nStarting the installer" $PATH
27         # Install python2.7
28         hdiutil attach $PKGDIR/python-2.7.3-macosx10.6.dmg
29         open -W /Volumes/Python\ 2.7.3/Python.mpkg
30         hdiutil detach /Volumes/Python\ 2.7.3
31         # Check the installation
32         $PY -c ''
33         if [ $? != 0 ]; then
34                 displayMessage "Failed to install python2.7"
35                 exit 1
36         fi
37 fi
38
39 #Next check for numpy, numpy does not always run under 64bit, so we need to check if we need to use "arch -i386"
40 $PY -c 'import numpy' 2> /dev/null
41 if [ $? != 0 ]; then
42         PY="arch -i386 python2.7"
43         $PY -c 'import numpy'
44         if [ $? != 0 ]; then
45                 displayMessage "Numpy is missing from your system, this is required.\nStarting the installer"
46                 # Install numpy
47                 hdiutil attach $PKGDIR/numpy-1.6.2-py2.7-python.org-macosx10.3.dmg
48                 open -W /Volumes/numpy/numpy-1.6.2-py2.7.mpkg
49                 hdiutil detach /Volumes/numpy
50                 #After installing numpy, we need to check if we need to use arch -386 again
51                 PY="python2.7"
52                 $PY -c 'import numpy'
53                 if [ $? != 0 ]; then
54                         PY="arch -i386 python2.7"
55                         $PY -c 'import numpy'
56                         if [ $? != 0 ]; then
57                                 displayMessage "Failed to install numpy."
58                                 exit 1
59                         fi
60                 fi
61         fi
62 fi
63
64 #Check for wxPython
65 $PY -c 'import wx'
66 if [ $? != 0 ]; then
67         displayMessage "wxPython is missing from your system. Cura requires wxPython.\nStarting the installer"
68         # Start wxPython installer
69         hdiutil attach $PKGDIR/wxPython2.9-osx-2.9.4.0-cocoa-py2.7.dmg
70         open -W /Volumes/wxPython2.9-osx-2.9.4.0-cocoa-py2.7/wxPython2.9-osx-cocoa-py2.7.pkg
71         hdiutil detach /Volumes/wxPython2.9-osx-2.9.4.0-cocoa-py2.7
72         #Check if wxPython is installed correctly
73         $PY -c 'import wx'
74         if [ $? != 0 ]; then
75                 displayMessage "Failed to properly install wxPython."
76                 exit 1
77         fi
78 fi
79
80 #Check for PyOpenGL
81 $PY -c 'import OpenGL'
82 if [ $? != 0 ]; then
83         # Unpackage PyOpenGL
84         if [ ! -d "$PKGDIR/PyOpenGL-3.0.2/build/lib" ]; then
85                 cd $PKGDIR
86                 tar -xzf PyOpenGL-3.0.2.tar.gz
87                 cd PyOpenGL-3.0.2
88                 $PY setup.py build
89         fi
90         export PYTHONPATH="$PYTHONPATH:$PKGDIR/PyOpenGL-3.0.2/build/lib"
91         # Test if the installation was succesful
92         echo $PYTHONPATH
93         $PY -c 'import OpenGL'
94         if [ $? != 0 ]; then
95                 displayMessage "Failed to properly use PyOpenGL."
96                 exit 1
97         fi
98 fi
99
100 #Check for pyserial
101 $PY -c 'import serial'
102 if [ $? != 0 ]; then
103         #Unpackage PySerial
104         if [ ! -d "$PKGDIR/pyserial-2.6/build/lib" ]; then
105                 cd $PKGDIR
106                 tar -xzf pyserial-2.6.tar.gz
107                 cd pyserial-2.6
108                 $PY setup.py build
109         fi
110         export PYTHONPATH="$PYTHONPATH:$PKGDIR/pyserial-2.6/build/lib"
111
112         #Test if we have pyserial now
113         $PY -c 'import serial'
114         if [ $? != 0 ]; then
115                 displayMessage "Failed to properly use PySerial."
116                 exit 1
117         fi
118 fi
119
120 #All checks passed, start Cura
121 $PY "${RESDIR}Cura/cura.py" &
122 sleep 1
123
124 exit 0