grass.sh.in 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. #! /bin/sh
  2. #############################################################################
  3. #
  4. # MODULE: GRASS Initialization
  5. # AUTHOR(S): Justin Hickey - Thailand - jhickey@hpcc.nectec.or.th
  6. # William Kyngesburye - kyngchaos@kyngchaos.com
  7. # PURPOSE: The source file for this shell script is in
  8. # macosx/app/grass.sh.in and is the grass startup script for
  9. # the Mac OS X application build.
  10. # COPYRIGHT: (C) 2000-2008 by the GRASS Development Team
  11. #
  12. # This program is free software under the GNU General Public
  13. # License (>=v2). Read the file COPYING that comes with GRASS
  14. # for details.
  15. #
  16. #############################################################################
  17. # Mac app only startup shell - complete rewrite for starting from a GRASS.app
  18. # in Mac OS X. Sets defaults for unset env, adds some Mac-only config.
  19. trap "echo 'User break!' ; exit" 2 3 9 15
  20. # dummy for now - just saying we're starting GRASS.app on OSX
  21. GRASS_OS_STARTUP="Mac.app"
  22. export GRASS_OS_STARTUP
  23. SYSARCH=`uname -p`
  24. SYSVER=`uname -r | cut -d . -f 1`
  25. GISBASE=`dirname "$0"`
  26. export GISBASE
  27. grass_ver=`cut -d . -f 1-2 "$GISBASE/etc/VERSIONNUMBER"`
  28. #override config dir.
  29. GRASS_CONFIG_DIR="Library/Preferences/GRASS/$grass_Ver"
  30. GISBASE_USER="$HOME/Library/GRASS/$grass_ver"
  31. export GISBASE_USER
  32. GISBASE_SYSTEM="/Library/GRASS/$grass_ver"
  33. export GISBASE_SYSTEM
  34. # for extra utils
  35. # ideally user should have these in their PATH, but make sure here
  36. PATH="@GDAL_BIN_PATH@@PROJ_BIN_PATH@$PATH"
  37. export PATH
  38. # add some OS X style app support paths, and create user one if missing.
  39. mkdir -p "$GISBASE_USER/Modules/bin"
  40. mkdir -p "$GISBASE_USER/Modules/scripts"
  41. if [ ! "$GRASS_ADDON_BASE" ] ; then
  42. GRASS_ADDON_BASE="$GISBASE_USER/Modules"
  43. fi
  44. export GRASS_ADDON_BASE
  45. mkdir -p "$GISBASE_USER/Modules/etc"
  46. addpath="$GISBASE_USER/Modules/etc:$GISBASE_SYSTEM/Modules/etc"
  47. if [ "$GRASS_ADDON_ETC" ] ; then
  48. GRASS_ADDON_ETC="$GRASS_ADDON_ETC:$addpath"
  49. else
  50. GRASS_ADDON_ETC="$addpath"
  51. fi
  52. export GRASS_ADDON_ETC
  53. mkdir -p "$GISBASE_USER/Modules/lib"
  54. addpath="$GISBASE_USER/Modules/lib:$GISBASE_SYSTEM/Modules/lib"
  55. if [ "$DYLD_LIBRARY_PATH" ] ; then
  56. DYLD_LIBRARY_PATH="$addpath:$DYLD_LIBRARY_PATH"
  57. else
  58. DYLD_LIBRARY_PATH="$addpath"
  59. fi
  60. export DYLD_LIBRARY_PATH
  61. mkdir -p "$GISBASE_USER/Modules/docs/html"
  62. # rebuild addon html index and gui menus
  63. "$GISBASE/etc/build_html_user_index.sh" "$GISBASE"
  64. "$GISBASE/etc/build_gui_user_menu.sh"
  65. # user fontcap files
  66. if [ ! "$GRASS_FONT_CAP" ] ; then
  67. GRASS_FONT_CAP="$GISBASE_USER/Modules/etc/fontcap"
  68. fi
  69. export GRASS_FONT_CAP
  70. # default xterm Terminal emulator
  71. # note: only app startup defaults this way, CLI build still defaults to xterm
  72. if [ ! "$GRASS_XTERM" ] ; then
  73. GRASS_XTERM="$GISBASE/etc/grass-xterm-mac"
  74. export GRASS_XTERM
  75. fi
  76. # determine current term application (when grass.sh is run directly by the user)
  77. # use osascript so we can get name of term app, not shell process
  78. USERTERM=`osascript -e 'tell application "System Events" to item 1 of (get name of processes whose frontmost is true)'`
  79. if [ ! "$USERTERM" ] ; then
  80. USERTERM="Terminal"
  81. fi
  82. ### X11 stuff
  83. x11=""
  84. if [ "@X11@" ] ; then
  85. # start X11 if not running
  86. # some users may be annoyed by this, but X11 required for some stuff for now
  87. if [ -d "/Applications/Utilities/X11.app" ] ; then
  88. # no need to start Leopard X11.app
  89. if [ ! -d "/usr/X11" ] ; then
  90. # check if running anyways, even though not necessary with "open"
  91. if [ ! "`ps -axc | grep 'X11$'`" ] ; then
  92. open /Applications/Utilities/X11.app
  93. fi
  94. x11="tig"
  95. else
  96. x11="leo"
  97. fi
  98. fi
  99. # make sure X11 is in PATH
  100. pathX11=`echo "$PATH" | grep '/usr/X11\(R6\)\?/bin'`
  101. if [ ! "$pathX11" ] ; then
  102. if [ -d "/usr/X11" ] ; then
  103. PATH="$PATH:/usr/X11/bin"
  104. export PATH
  105. elif [ -d "/usr/X11R6" ] ; then
  106. PATH="$PATH:/usr/X11R6/bin"
  107. export PATH
  108. fi
  109. fi
  110. # make sure there is a DISPLAY set
  111. if [ ! "$DISPLAY" ] ; then
  112. DISPLAY=:0.0
  113. export DISPLAY
  114. fi
  115. fi # X11
  116. ### end X11 block
  117. # for bundling wxpython
  118. # change GRASS_WXBUNDLED and pyver_want here from bundle.make, or manually
  119. GRASS_WXBUNDLED=
  120. export GRASS_WXBUNDLED
  121. pyexe="pythonw"
  122. GRASS_PYTHONWX="$pyexe"
  123. pyver_want="@PYVER@"
  124. GRASS_WX64BIT="@WX64BIT@"
  125. export GRASS_WX64BIT
  126. # make sure python version used matches what wxpython wants
  127. py=""
  128. # did user set GRASS_PYTHON already? check it (must have pythonw)
  129. if [ "$GRASS_PYTHON" ] ; then
  130. py=`echo "$GRASS_PYTHON" | grep pythonw`
  131. if [ "$py" ] ; then
  132. case $GRASS_PYTHON in
  133. /*) py="$GRASS_PYTHON" ;;
  134. *) py=`type -p $GRASS_PYTHON`
  135. esac
  136. pyver=`$py -V 2>&1 | grep " $pyver_want"`
  137. if [ ! "$pyver" ] ; then
  138. py=""
  139. fi
  140. else
  141. py=""
  142. fi
  143. fi # GRASS_PYTHON
  144. # try in shell path
  145. if [ ! "$py" ] ; then
  146. py=`type -p pythonw$pyver_want`
  147. if [ "$py" ] ; then
  148. pyver=`$py -V 2>&1 | grep " $pyver_want"`
  149. if [ ! "$pyver" ] ; then
  150. py=""
  151. fi
  152. fi
  153. fi
  154. # try standard framework
  155. if [ ! "$py" ] ; then
  156. py="/Library/Frameworks/Python.framework/Versions/$pyver_want/bin/python"
  157. if [ ! -x "$py" ] ; then
  158. py=""
  159. fi
  160. fi
  161. # try system (may be the same as in shell path)
  162. if [ ! "$py" ] ; then
  163. py="/usr/bin/pythonw$pyver_want"
  164. pyver=`$py -V 2>&1 | grep " $pyver_want"`
  165. if [ ! "$pyver" ] ; then
  166. py=""
  167. fi
  168. fi
  169. if [ "$py" ] ; then
  170. echo "$pyver found."
  171. GRASS_PYTHONWX="$py"
  172. else
  173. echo "Warning: No Python $pyver_want found, needed by wxPython."
  174. echo " The wxPython GUI may not work properly."
  175. fi
  176. export GRASS_PYTHONWX
  177. # we will execute python scripts from the python wrapper script
  178. GRASS_PYTHON="python"
  179. export GRASS_PYTHON
  180. # if grassrc has text startup, switch back to Terminal (gotta duplicate some init.sh stuff)
  181. # only applies to Tiger - Leopard X11 opens automatically as needed
  182. GRASSRC="$HOME/$GRASS_CONFIG_DIR/rc"
  183. if [ ! "$GRASS_GUI" ] ; then
  184. if [ -f "$GRASSRC" ] ; then
  185. GRASS_GUI=`awk '/GRASS_GUI/ {print $2}' "$GRASSRC"`
  186. fi
  187. if [ ! "$GRASS_GUI" ] ; then
  188. GRASS_GUI="wxpython"
  189. fi
  190. fi
  191. if [ "$GRASS_GUI" = "text" ] && [ "$x11" = "tig" ] ; then
  192. osascript -e "tell application \"$USERTERM\" to activate"
  193. fi
  194. # use the python wrapper to start grass
  195. exec "$GISBASE/bin/python" "$GISBASE/@GRASS_NAME@" "$@"