From Jay Moran via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4697 :
[obnox/wireshark/wip.git] / packaging / macosx / Resources / bin / wireshark
1 #!/bin/sh
2 #
3 # $Id$
4 #
5 # Author: Aaron Voisine <aaron@voisine.org>
6 # Wireshark Modifications:
7 #       Michael Wybrow <mjwybrow@users.sourceforge.net>
8 #       Jean-Olivier Irisson <jo.irisson@gmail.com>
9 #
10
11 CWD="`(cd \"\`dirname \\\"$0\\\"\`\"; echo $PWD)`"
12 # e.g. /Applications/Wireshark.app/Contents/Resources/bin
13 TOP="`dirname \"$CWD\"`"
14 # e.g. /Applications/Wireshark.app/Contents/Resources
15
16 # We might be exec'ed from wireshark, tshark, dumpcap, or any other binary
17 # from the Wireshark distribution.
18 # XXX - Should we verify that we have a valid name?
19 APPNAME=`basename "$0"`
20
21 # Brutally add many things to the PATH. If the directories do not exist, they won't be used anyway.
22 # People should really use ~/.macosx/environment.plist to set environment variables as explained by Apple:
23 #       http://developer.apple.com/qa/qa2001/qa1067.html
24 # but since no one does, we correct this by making the 'classic' PATH additions here:
25 #       /usr/local/bin which, though standard, doesn't seem to be in the PATH
26 #       newer python as recommended by MacPython http://www.python.org/download/mac/
27 #       Fink
28 #       MacPorts (former DarwinPorts)
29 export PATH="/opt/local/bin:/sw/bin/:/Library/Frameworks/Python.framework/Versions/Current/bin:/usr/local/bin:$CWD:$PATH"
30
31 export DYLD_LIBRARY_PATH="$TOP/lib"
32
33 export WIRESHARK_DATA_DIR="$TOP/share/wireshark"
34 export WIRESHARK_PLUGIN_DIR="$TOP/lib/wireshark/plugins"
35 export WIRESHARK_PYTHON_DIR="$TOP/lib/wireshark/python"
36
37 if [ "$APPNAME" == "wireshark" ] ; then # Apply GUI settings
38         # For Panther and Tiger, override the default fontconfig configuration
39         # XXX - This apparently isn't needed?
40         #if [[ $VERSION -le 4 ]]; then
41                 export FONTCONFIG_PATH="$TOP/etc/fonts"
42         #fi
43         export PANGO_RC_FILE="$HOME/.wireshark-etc/pangorc"
44         export GTK_IM_MODULE_FILE="$HOME/.wireshark-etc/gtk.immodules"
45         export GDK_PIXBUF_MODULE_FILE="$HOME/.wireshark-etc/gdk-pixbuf.loaders"
46         export GTK_DATA_PREFIX="$TOP"
47         export GTK_EXE_PREFIX="$TOP"
48         export GNOME_VFS_MODULE_CONFIG_PATH="$TOP/etc/gnome-vfs-2.0/modules"
49         export GNOME_VFS_MODULE_PATH="$TOP/lib/gnome-vfs-2.0/modules"
50
51         # Set GTK theme (only if there is no .gtkrc-2.0 in the user's home)
52         if [[ ! -e "$HOME/.gtkrc-2.0" ]]; then
53                 # prepare the theme depending on OS X appearance settings
54                 (
55                         cd "$TOP/themes/Clearlooks-Quicksilver-OSX/gtk-2.0/"
56                         ./sync_osx_look.sh
57                         # TODO: make this more robust, probably by integrating this script directly inline here
58                 )
59                 export GTK2_RC_FILES="$TOP/themes/Clearlooks-Quicksilver-OSX/gtk-2.0/gtkrc"
60         fi
61
62         # TODO: Have to add ".UTF-8" to the LANG since ommiting causes Wireshark
63         #       to crash on startup in locale_from_utf8().
64         export LANG="`grep \"\`defaults read .GlobalPreferences AppleCollationOrder \
65                 2>&1\`_\" /usr/share/locale/locale.alias | tail -n1 | sed 's/\./ /' | \
66                 awk '{print $2}'`.UTF-8"
67
68         # Handle the case where the directory storing Wireshark has a '#' in the name.
69         # This '#' needs to be escaped in pango.modules for Pango to work properly.
70         ESCAPEDTOP=`echo $TOP | sed 's/#/\\\\\\\\#/'`
71
72         mkdir -p "${HOME}/.wireshark-etc"
73         sed 's|${HOME}|'"$HOME|g" "$TOP/etc/pango/pangorc" > "${HOME}/.wireshark-etc/pangorc"
74         sed 's|${CWD}|'"$ESCAPEDTOP|g" "$TOP/etc/pango/pango.modules" \
75                 > "${HOME}/.wireshark-etc/pango.modules"
76         cp -f "$TOP/etc/pango/pangox.aliases" "${HOME}/.wireshark-etc/"
77         sed 's|${CWD}|'"$TOP|g" "$TOP/etc/gtk-2.0/gtk.immodules" \
78                 > "${HOME}/.wireshark-etc/gtk.immodules"
79         sed 's|${CWD}|'"$TOP|g" "$TOP/etc/gtk-2.0/gdk-pixbuf.loaders" \
80                 > "${HOME}/.wireshark-etc/gdk-pixbuf.loaders"
81 fi
82
83 exec "$CWD/$APPNAME-bin" "$@"