init.sh 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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_nospam 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 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 global grassrc file
  59. if [ -n "$GRASS_BATCH_JOB" ] ; then
  60. GISRCRC="$HOME/.grassrc7.`uname -n`"
  61. if [ ! -f "$GISRCRC" ] ; then
  62. GISRCRC="$HOME/.grassrc7"
  63. fi
  64. else
  65. GISRCRC="$HOME/.grassrc7"
  66. fi
  67. # Set PATH to GRASS bin, ETC to GRASS etc
  68. ETC="$GISBASE/etc"
  69. # Set the username and working directory
  70. if [ "$MINGW" ] ; then
  71. PWD=`pwd -W`
  72. USER="$USERNAME"
  73. if [ ! "$USER" ] ; then
  74. USER="user_name"
  75. fi
  76. else
  77. PWD=`pwd`
  78. USER="`whoami`"
  79. fi
  80. # Parse the command-line options
  81. # This can't be put into a function as it modifies argv
  82. for i in "$@" ; do
  83. case "$i" in
  84. # Check if the user asked for the version
  85. -v|--version)
  86. cat "$GISBASE/etc/license"
  87. exit
  88. ;;
  89. # Check if the user asked for help
  90. help|-h|-help|--help)
  91. help_message
  92. exit
  93. ;;
  94. # Check if the -text flag was given
  95. -text)
  96. GRASS_GUI="text"
  97. shift
  98. ;;
  99. # Check if the -gui flag was given
  100. -gui)
  101. GRASS_GUI="$DEFAULT_GUI"
  102. shift
  103. ;;
  104. # Check if the -wxpython flag was given
  105. -wxpython | -wx)
  106. GRASS_GUI="wxpython"
  107. shift
  108. ;;
  109. # Check if the user wants to create a new mapset
  110. -c)
  111. CREATE_NEW=1
  112. shift
  113. ;;
  114. esac
  115. done
  116. # Create the temporary directory and session grassrc file
  117. create_tmp
  118. # Create the session grassrc file
  119. create_gisrc
  120. # Ensure GRASS_GUI is set
  121. read_gui
  122. # Get Locale name
  123. get_locale
  124. # Set PATH, @LD_LIBRARY_PATH_VAR@, PYTHONPATH
  125. GRASS_LD_LIBRARY_PATH="$@LD_LIBRARY_PATH_VAR@"
  126. set_paths
  127. @LD_LIBRARY_PATH_VAR@="$GRASS_LD_LIBRARY_PATH"
  128. export @LD_LIBRARY_PATH_VAR@
  129. # Set GRASS_PAGER, GRASS_WISH, GRASS_PYTHON, GRASS_GNUPLOT
  130. set_defaults
  131. # Set GRASS_HTML_BROWSER
  132. set_browser
  133. #predefine monitor size for certain architectures
  134. if [ "$HOSTTYPE" = "arm" ] ; then
  135. #small monitor on ARM (iPAQ, zaurus... etc)
  136. GRASS_HEIGHT=320
  137. GRASS_WIDTH=240
  138. export GRASS_HEIGHT GRASS_WIDTH
  139. fi
  140. if [ ! "$GRASS_PROJSHARE" ] ; then
  141. GRASS_PROJSHARE=@CONFIG_PROJSHARE@
  142. export GRASS_PROJSHARE
  143. fi
  144. # First time user - GISRC is defined in the GRASS script
  145. if [ ! -f "$GISRC" ] ; then
  146. grass_intro
  147. else
  148. clean_temp
  149. fi
  150. echo "Starting GRASS ..."
  151. # Check that the GUI works
  152. check_gui "$@"
  153. # Parsing argument to get LOCATION
  154. if [ ! "$1" ] ; then
  155. # Try interactive startup
  156. LOCATION=
  157. else
  158. non_interactive "$@"
  159. fi
  160. # User selects LOCATION and MAPSET if not set
  161. set_data
  162. # Set GISDBASE, LOCATION_NAME, MAPSET, LOCATION from $GISRC
  163. read_gisrc
  164. # Check .gislock file
  165. check_lock
  166. # build user fontcap if specified but not present
  167. make_fontcap
  168. # predefine default driver if DB connection not defined
  169. # is this really needed?? Modules should call this when/if required.
  170. if [ ! -e "$LOCATION/VAR" ] ; then
  171. db.connect -c --quiet
  172. fi
  173. trap "" 2 3 15
  174. check_shell
  175. check_batch_job
  176. start_gui
  177. clear_screen
  178. # Display the version and license info
  179. if [ -n "$GRASS_BATCH_JOB" ] ; then
  180. say_hello
  181. else
  182. show_banner
  183. say_hello
  184. show_info
  185. fi
  186. case "$sh" in
  187. csh|tcsh)
  188. csh_startup
  189. ;;
  190. bash|msh|cygwin)
  191. bash_startup
  192. ;;
  193. *)
  194. default_startup
  195. ;;
  196. esac
  197. trap 2 3 15
  198. clear_screen
  199. clean_temp
  200. rm -f "$lockfile"
  201. # Save GISRC
  202. cp "$GISRC" "$GISRCRC"
  203. cleanup_tmpdir
  204. #### after this point no more grass modules may be called ####
  205. done_message