init.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #!/bin/sh
  2. #############################################################################
  3. #
  4. # MODULE: GRASS Initialization
  5. # AUTHOR(S): Original author unknown - probably CERL
  6. # Andreas Lange - Germany - andreas.lange@rhein-main.de
  7. # Huidae Cho - Korea - grass4u@gmail.com
  8. # Justin Hickey - Thailand - jhickey@hpcc.nectec.or.th
  9. # Markus Neteler - Germany/Italy - neteler@itc.it
  10. # Hamish Bowman - New Zealand - hamish_b at yahoo,com
  11. # PURPOSE: The source file for this shell script is in
  12. # src/general/init/init.sh. It sets up some environment
  13. # variables and the lock file. It also parses any remaining
  14. # command line options for setting the GISDBASE, LOCATION, and/or
  15. # MAPSET. Finally it starts GRASS with the appropriate user
  16. # interface and cleans up after it is finished.
  17. # COPYRIGHT: (C) 2000-2009 by the GRASS Development Team
  18. #
  19. # This program is free software under the GNU General Public
  20. # License (>=v2). Read the file COPYING that comes with GRASS
  21. # for details.
  22. #
  23. #############################################################################
  24. trap "echo 'User break!' ; exit" 2 3 15
  25. . "$GISBASE/etc/functions.sh"
  26. # Set default GUI
  27. DEFAULT_GUI="wxpython"
  28. # the following is only meant to be an internal variable for debugging this script.
  29. # use 'g.gisenv set="DEBUG=[0-5]"' to turn GRASS debug mode on properly.
  30. if [ -z "$GRASS_DEBUG" ] ; then
  31. GRASS_DEBUG=0
  32. fi
  33. # GRASS_SH is normally just for Windows when not started from a bourne
  34. # shell. But when starting from Init.sh is still needed for GRASS_GUI (still true for GRASS 7?)
  35. GRASS_SH=/bin/sh
  36. export GRASS_SH
  37. # Set GRASS version number for R interface etc (must be an env_var for MS-Windows)
  38. GRASS_VERSION="@GRASS_VERSION_NUMBER@"
  39. export GRASS_VERSION
  40. # Get the command name
  41. CMD_NAME=@START_UP@
  42. # Get the system name
  43. SYSTEM=`uname -s`
  44. case $SYSTEM in
  45. MINGW*)
  46. MINGW=1
  47. ;;
  48. CYGWIN*)
  49. CYGWIN=1
  50. ;;
  51. Darwin*)
  52. MACOSX=1
  53. ;;
  54. esac
  55. # Set the GIS_LOCK variable to current process id
  56. GIS_LOCK=$$
  57. export GIS_LOCK
  58. # Set the config subdir
  59. if [ ! "$GRASS_CONFIG_DIR" ] ; then
  60. GRASS_CONFIG_DIR=@GRASS_CONFIG_DIR@
  61. export $GRASS_CONFIG_DIR
  62. fi
  63. # Set the global grassrc file
  64. if [ -n "$GRASS_BATCH_JOB" ] ; then
  65. GISRCRC="$HOME/$GRASS_CONFIG_DIR/rc.`uname -n`"
  66. if [ ! -f "$GISRCRC" ] ; then
  67. GISRCRC="$HOME/$GRASS_CONGIG_DIR/rc"
  68. fi
  69. else
  70. GISRCRC="$HOME/$GRASS_CONFIG_DIR/rc"
  71. fi
  72. # Set PATH to GRASS bin, ETC to GRASS etc
  73. ETC="$GISBASE/etc"
  74. # Set the username and working directory
  75. if [ "$MINGW" ] ; then
  76. PWD=`pwd -W`
  77. USER="$USERNAME"
  78. if [ ! "$USER" ] ; then
  79. USER="user_name"
  80. fi
  81. else
  82. PWD=`pwd`
  83. USER="`whoami`"
  84. fi
  85. # Parse the command-line options
  86. # This can't be put into a function as it modifies argv
  87. for i in "$@" ; do
  88. case "$i" in
  89. # Check if the user asked for the version
  90. -v|--version)
  91. cat "$GISBASE/etc/license"
  92. exit
  93. ;;
  94. # Check if the user asked for help
  95. help|-h|-help|--help)
  96. help_message
  97. exit
  98. ;;
  99. # Check if the -text flag was given
  100. -text)
  101. GRASS_GUI="text"
  102. shift
  103. ;;
  104. # Check if the -gui flag was given
  105. -gui)
  106. GRASS_GUI="$DEFAULT_GUI"
  107. shift
  108. ;;
  109. # Check if the -wxpython flag was given
  110. -wxpython | -wx)
  111. GRASS_GUI="wxpython"
  112. shift
  113. ;;
  114. # Check if the user wants to create a new mapset
  115. -c)
  116. CREATE_NEW=1
  117. shift
  118. ;;
  119. esac
  120. done
  121. # Create the temporary directory and session grassrc file
  122. create_tmp
  123. # Create the session grassrc file
  124. create_gisrc
  125. # Ensure GRASS_GUI is set
  126. read_gui
  127. # Get Locale name
  128. get_locale
  129. # Set PATH, PYTHONPATH
  130. set_paths
  131. # Set LD_LIBRARY_PATH (etc) to find GRASS shared libraries
  132. if [ ! "$@LD_LIBRARY_PATH_VAR@" ] ; then
  133. @LD_LIBRARY_PATH_VAR@="$GISBASE/lib"
  134. else
  135. @LD_LIBRARY_PATH_VAR@="$GISBASE/lib:$@LD_LIBRARY_PATH_VAR@"
  136. fi
  137. export @LD_LIBRARY_PATH_VAR@
  138. # Set GRASS_PAGER, GRASS_WISH, GRASS_PYTHON, GRASS_GNUPLOT
  139. set_defaults
  140. # Set GRASS_HTML_BROWSER
  141. set_browser
  142. #predefine monitor size for certain architectures
  143. if [ "$HOSTTYPE" = "arm" ] ; then
  144. #small monitor on ARM (iPAQ, zaurus... etc)
  145. GRASS_HEIGHT=320
  146. GRASS_WIDTH=240
  147. export GRASS_HEIGHT GRASS_WIDTH
  148. fi
  149. if [ ! "$GRASS_PROJSHARE" ] ; then
  150. GRASS_PROJSHARE=@CONFIG_PROJSHARE@
  151. export GRASS_PROJSHARE
  152. fi
  153. # First time user - GISRC is defined in the GRASS script
  154. if [ ! -f "$GISRC" ] ; then
  155. grass_intro
  156. else
  157. clean_temp
  158. fi
  159. echo "Starting GRASS ..."
  160. # Check that the GUI works
  161. check_gui "$@"
  162. # Parsing argument to get LOCATION
  163. if [ ! "$1" ] ; then
  164. # Try interactive startup
  165. LOCATION=
  166. else
  167. non_interactive "$@"
  168. fi
  169. # User selects LOCATION and MAPSET if not set
  170. set_data
  171. # Set GISDBASE, LOCATION_NAME, MAPSET, LOCATION from $GISRC
  172. read_gisrc
  173. # Check .gislock file
  174. check_lock
  175. # build user fontcap if specified but not present
  176. make_fontcap
  177. # predefine default driver if DB connection not defined
  178. # is this really needed?? Modules should call this when/if required.
  179. if [ ! -e "$LOCATION/VAR" ] ; then
  180. db.connect -c --quiet
  181. fi
  182. trap "" 2 3 15
  183. check_shell
  184. check_batch_job
  185. start_gui
  186. clear_screen
  187. # Display the version and license info
  188. if [ -n "$GRASS_BATCH_JOB" ] ; then
  189. say_hello
  190. else
  191. show_banner
  192. say_hello
  193. show_info
  194. fi
  195. case "$sh" in
  196. csh|tcsh)
  197. csh_startup
  198. ;;
  199. bash|msh|cygwin)
  200. bash_startup
  201. ;;
  202. *)
  203. default_startup
  204. ;;
  205. esac
  206. trap 2 3 15
  207. clear_screen
  208. clean_temp
  209. rm -f "$lockfile"
  210. # Save GISRC
  211. cp "$GISRC" "$GISRCRC"
  212. cleanup_tmpdir
  213. #### after this point no more grass modules may be called ####
  214. done_message