Code

Fix bug #482993: Python extensions not working on Mac OS X 10.6
[inkscape.git] / packaging / macosx / Resources / bin / inkscape
1 #!/bin/sh
2 #
3 # Author: Aaron Voisine <aaron@voisine.org>
4 # Inkscape Modifications:
5 #       Michael Wybrow <mjwybrow@users.sourceforge.net>
6 #       Jean-Olivier Irisson <jo.irisson@gmail.com>
7 #
9 CWD="`(cd \"\`dirname \\\"$0\\\"\`\"; echo \"$PWD\")`"
10 # e.g. /Applications/Inkscape.app/Contents/Resources/bin
11 TOP="`dirname \"$CWD\"`"
12 # e.g. /Applications/Inkscape.app/Contents/Resources
15 # Brutally add many things to the PATH. If the directories do not exist, they won't be used anyway. 
16 # People should really use ~/.macosx/environment.plist to set environment variables as explained by Apple:
17 #       http://developer.apple.com/qa/qa2001/qa1067.html
18 # but since no one does, we correct this by making the 'classic' PATH additions here:
19 #       /usr/local/bin which, though standard, doesn't seem to be in the PATH
20 #       newer python as recommended by MacPython http://www.python.org/download/mac/
21 #       Fink
22 #       MacPorts (former DarwinPorts)
23 #       LaTeX distribution for Mac OS X
24 export PATH="/usr/texbin:/opt/local/bin:/sw/bin/:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/bin:$CWD:$PATH"
26 # Put /usr/bin at beginning of path so we make sure we use Apple's python 
27 # over one that may be installed be Macports, Fink or some other means.
28 export PATH="/usr/bin:$PATH"
30 # On Snow Leopard, use the 32-bit version of python from Universal build.
31 # This is because our bundled i386 python libraries are 32-bit only.
32 export VERSIONER_PYTHON_PREFER_32_BIT=yes
35 # Setup PYTHONPATH to use python modules shipped with Inkscape
36 ARCH=`arch`
37 PYTHON_VERS=`python -V 2>&1 | cut -c 8-10`
38 export PYTHONPATH="$TOP/python/site-packages/$ARCH/$PYTHON_VERS"
39 # NB: we are only preprending some stuff to the default python path so if the directory does not exist it should not harm the rest
41 # No longer required if path rewriting has been conducted.
42 # export DYLD_LIBRARY_PATH="$TOP/lib"
44 mkdir -p "${HOME}/.inkscape-etc"
46 export FONTCONFIG_PATH="$TOP/etc/fonts"
47 export PANGO_RC_FILE="$HOME/.inkscape-etc/pangorc"
48 export GTK_IM_MODULE_FILE="$HOME/.inkscape-etc/gtk.immodules"
49 export GDK_PIXBUF_MODULE_FILE="$HOME/.inkscape-etc/gdk-pixbuf.loaders"
50 export GTK_DATA_PREFIX="$TOP"
51 export GTK_EXE_PREFIX="$TOP"
52 export GNOME_VFS_MODULE_CONFIG_PATH="$TOP/etc/gnome-vfs-2.0/modules"
53 export GNOME_VFS_MODULE_PATH="$TOP/lib/gnome-vfs-2.0/modules"
54 export XDG_DATA_DIRS="$TOP/share"
55 export ASPELL_CONF="prefix $TOP;"
57 # Note: This requires the path with the exact ImageMagic version number.
58 #        Also, that ImageMagick will only work if it does not find a 
59 #        version installed into the same PREFIX as it was originally 
60 #        installed.  Luckily, this is very unlikely given the extra long 
61 #        and strangely named install prefix we use.
62 #        The actual version is inserted by the packaging script.
63 export MAGICK_CONFIGURE_PATH="$TOP/lib/ImageMagick-IMAGEMAGICKVER/config:$TOP/share/ImageMagick-IMAGEMAGICKVER/config"
64 export MAGICK_CODER_FILTER_PATH="$TOP/lib/ImageMagick-IMAGEMAGICKVER/modules-Q16/filters"
65 export MAGICK_CODER_MODULE_PATH="$TOP/lib/ImageMagick-IMAGEMAGICKVER/modules-Q16/coders"
67 export INKSCAPE_SHAREDIR="$TOP"
68 # TODO: move the share directory to a its own folder to make things a bit cleaner in the app bundle
69 export INKSCAPE_PLUGINDIR="$TOP/lib/inkscape"
70 export INKSCAPE_LOCALEDIR="$TOP/locale"
72 # Handle the case where the directory storing Inkscape has special characters
73 # ('#', '&', '|') in the name.  These need to be escaped to work properly for 
74 # various configuration files.
75 ESCAPEDTOP=`echo "$TOP" | sed 's/#/\\\\\\\\#/' | sed 's/&/\\\\\\&/g' | sed 's/|/\\\\\\|/g'`
77 # Set GTK theme (only if there is no .gtkrc-2.0 in the user's home)
78 if [[ ! -e "$HOME/.gtkrc-2.0" ]]; then
79         # Appearance setting
80         aquaStyle=`defaults read "Apple Global Domain" AppleAquaColorVariant 2>/dev/null`
81         # 1 for aqua, 6 for graphite, inexistant if the default color was never changed
82         if [[ "$aquaStyle" == "" ]]; then
83                 aquaStyle=1             # set aqua as default
84         fi
86         # Highlight Color setting
87         hiliColor=`defaults read "Apple Global Domain" AppleHighlightColor 2>/dev/null`
88         # a RGB value, with components between 0 and 1, also inexistant if it was not changed
89         if [[ "$hiliColor" == "" ]]; then
90                 hiliColor="0.709800 0.835300 1.000000"  # set blue as default
91         fi
93         # Menu items color
94         if [[ aquaStyle -eq 1 ]]; then
95                 menuColor="#4a76cd"     # blue
96         else
97                 menuColor="#7c8da4"     # graphite
98         fi
99         # Format highlight color as a GTK rgb value
100         hiliColorFormated=`echo $hiliColor | awk -F " " '{print "\\\{"$1","$2","$3"\\\}"}'`
102         # echo $menuColor
103         # echo $hiliColorFormated
105         # Modify the gtkrc
106         #       - with the correct colors
107         #       - to point to the correct scrollbars folder
108         sed 's/OSX_HILI_COLOR_PLACEHOLDER/'$hiliColorFormated'/g' "$INKSCAPE_SHAREDIR/themes/Clearlooks-Quicksilver-OSX/gtk-2.0/pre_gtkrc" | sed 's/OSX_MENU_COLOR_PLACEHOLDER/\"'$menuColor'\"/g' | sed 's/AQUASTYLE_PLACEHOLDER/'$aquaStyle'/g' | sed 's|${THEMEDIR}|'"$ESCAPEDTOP/themes/Clearlooks-Quicksilver-OSX/gtk-2.0|g" > "${HOME}/.inkscape-etc/gtkrc"
110         export GTK2_RC_FILES="$HOME/.inkscape-etc/gtkrc"
111 fi
113 # If the AppleCollationOrder preference doesn't exist, we fall back to using
114 # the AppleLocale preference.
115 LANGSTR=`defaults read .GlobalPreferences AppleCollationOrder 2>/dev/null`
116 if [ "x$LANGSTR" == "x" ]
117 then
118     echo "Warning: AppleCollationOrder setting not found, using AppleLocale." 1>&2
119     LANGSTR=`defaults read .GlobalPreferences AppleLocale 2>/dev/null | \
120             sed 's/_.*//'`
121 fi
123 # NOTE: Have to add ".UTF-8" to the LANG since omitting causes Inkscape
124 #       to crash on startup in locale_from_utf8().
125 export LANG="`grep \"\`echo $LANGSTR\`_\" /usr/share/locale/locale.alias | \
126         tail -n1 | sed 's/\./ /' | awk '{print $2}'`.UTF-8"
127 echo "Setting Language: $LANG" 1>&2
129 sed 's|${HOME}|'"$HOME|g" "$TOP/etc/pango/pangorc" > "${HOME}/.inkscape-etc/pangorc"
130 sed 's|${CWD}|'"$ESCAPEDTOP|g" "$TOP/etc/pango/pango.modules" \
131     > "${HOME}/.inkscape-etc/pango.modules"
132 cp -f "$TOP/etc/pango/pangox.aliases" "${HOME}/.inkscape-etc/"
133 sed 's|${CWD}|'"$ESCAPEDTOP|g" "$TOP/etc/gtk-2.0/gtk.immodules" \
134     > "${HOME}/.inkscape-etc/gtk.immodules"
135 sed 's|${CWD}|'"$ESCAPEDTOP|g" "$TOP/etc/gtk-2.0/gdk-pixbuf.loaders" \
136     > "${HOME}/.inkscape-etc/gdk-pixbuf.loaders"
138 exec "$CWD/inkscape-bin" "$@"