#! /bin/sh ############################################################################# # # $Id$ # # MODULE: GRASS Initialization # AUTHOR(S): Justin Hickey - Thailand - jhickey@hpcc.nectec.or.th # William Kyngesburye - kyngchaos@kyngchaos.com # PURPOSE: The source file for this shell script is in # macosx/app/grass.sh.in and is the grass startup script for # the Mac OS X application build. # COPYRIGHT: (C) 2000-2005 by the GRASS Development Team # # This program is free software under the GNU General Public # License (>=v2). Read the file COPYING that comes with GRASS # for details. # ############################################################################# # Mac app only startup shell - complete rewrite for starting from a GRASS.app # in Mac OS X. Sets defaults for unset env, adds some Mac-only config. trap "echo 'User break!' ; exit" 2 3 9 15 # dummy for now - just saying we're starting GRASS.app on OSX GRASS_OS_STARTUP="Mac.app" export GRASS_OS_STARTUP GISBASE=`dirname "$0"` export GISBASE grass_ver=`cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER"` GISBASE_USER="$HOME/Library/GRASS/$grass_ver" GISBASE_SYSTEM="/Library/GRASS/$grass_ver" # for extra utils # hack - ideally user should have these in their PATH, but make sure here PATH="@GDAL_BIN_PATH@:@PROJ_BIN_PATH@:$PATH" export PATH # add some OS X style app support paths, and create user one if missing. mkdir -p "$GISBASE_USER/Modules/bin" if [ "$GRASS_ADDON_PATH" ] ; then GRASS_ADDON_PATH="$GRASS_ADDON_PATH:$GISBASE_USER/Modules/bin:$GISBASE_SYSTEM/Modules/bin" else GRASS_ADDON_PATH="$GISBASE_USER/Modules/bin:$GISBASE_SYSTEM/Modules/bin" fi export GRASS_ADDON_PATH mkdir -p "$GISBASE_USER/Modules/etc" if [ "$GRASS_ADDON_ETC" ] ; then GRASS_ADDON_ETC="$GRASS_ADDON_ETC:$GISBASE_USER/Modules/etc:$GISBASE_SYSTEM/Modules/etc" else GRASS_ADDON_ETC="$GISBASE_USER/Modules/etc:$GISBASE_SYSTEM/Modules/etc" fi export GRASS_ADDON_ETC mkdir -p "$GISBASE_USER/Modules/lib" if [ "$DYLD_LIBRARY_PATH" ] ; then DYLD_LIBRARY_PATH="$GISBASE_USER/Modules/lib:$GISBASE_SYSTEM/Modules/lib:$DYLD_LIBRARY_PATH" else DYLD_LIBRARY_PATH="$GISBASE_USER/Modules/lib:$GISBASE_SYSTEM/Modules/lib" fi export DYLD_LIBRARY_PATH mkdir -p "$GISBASE_USER/Modules/docs/html" # rebuild addon html index and gui menus "$GISBASE/etc/build_html_user_index.sh" "$GISBASE" "$GISBASE/etc/build_gui_user_menu.sh" # user fontcap files if [ ! "$GRASS_FONT_CAP" ] ; then GRASS_FONT_CAP="$GISBASE_USER/Modules/etc/fontcap" fi export GRASS_FONT_CAP # default xterm Terminal emulator # note: only app startup defaults this way, CLI build still defaults to xterm if [ ! "$GRASS_XTERM" ] ; then GRASS_XTERM="$GISBASE/etc/grass-xterm-mac" export GRASS_XTERM fi # determine current term application (when grass.sh is run directly by the user) # use osascript so we can get name of term app, not shell process USERTERM=`osascript -e 'tell application "System Events" to item 1 of (get name of processes whose frontmost is true)'` if [ ! "$USERTERM" ] ; then USERTERM="Terminal" fi ### X11 stuff # start X11 if not running # some users may be annoyed by this, but X11 required for some stuff for now if [ -d "/Applications/Utilities/X11.app" ] ; then # no need to start Leopard X11.app if [ ! -d "/usr/X11" ] ; then # check if running anyways, even though not necessary with "open" if [ ! "`ps -axc | grep 'X11$'`" ] ; then open /Applications/Utilities/X11.app fi fi fi # make sure X11 is in PATH pathX11=`echo "$PATH" | grep '/usr/X11\(R6\)\?/bin'` if [ ! "$pathX11" ] ; then if [ -d "/usr/X11" ] ; then PATH="$PATH:/usr/X11/bin" export PATH elif [ -d "/usr/X11R6" ] ; then PATH="$PATH:/usr/X11R6/bin" export PATH fi fi # default to internal X11 Tcl/Tk @TCLTK_INTERNAL@if [ ! "$GRASS_TCLSH" ] ; then GRASS_TCLSH="$GISBASE/bin/tclsh@TCLTKVER@" export GRASS_TCLSH GRASS_WISH="$GISBASE/bin/wish@TCLTKVER@" export GRASS_WISH # internal - force osxaqua off unset osxaqua # override TCL_LIBRARY to internal TCL_LIBRARY="$GISBASE/lib/tcl@TCLTKVER@" export TCL_LIBRARY TK_LIBRARY="$GISBASE/lib/tk@TCLTKVER@" export TK_LIBRARY @TCLTK_INTERNAL@fi # make sure there is a DISPLAY set if [ ! "$DISPLAY" ] ; then DISPLAY=:0.0 export DISPLAY fi ### end X11 block # if gisrc has text startup, switch back to Terminal (gotta duplicate some init.sh stuff) # eventually, when TclTk optional, can run appropriate apps per GUI here (ie X11) GISRCRC="$HOME/.grassrc6" if [ ! "$GRASS_GUI" ] ; then if [ -f "$GISRCRC" ] ; then GRASS_GUI=`awk '/GRASS_GUI/ {print $2}' "$GISRCRC"` fi if [ ! "$GRASS_GUI" ] ; then GRASS_GUI="tcltk" fi fi if [ "$GRASS_GUI" = "text" ] ; then osascript -e "tell application \"$USERTERM\" to activate" fi exec "$GISBASE/etc/Init.sh" "$@"