123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- #!/bin/sh
- #############################################################################
- #
- # MODULE: GRASS Initialization
- # AUTHOR(S): Original author unknown - probably CERL
- # Andreas Lange - Germany - andreas.lange@rhein-main.de
- # Huidae Cho - Korea - grass4u@gmail.com
- # Justin Hickey - Thailand - jhickey@hpcc.nectec.or.th
- # Markus Neteler - Germany/Italy - neteler@itc.it
- # Hamish Bowman - New Zealand - hamish_b at yahoo,com
- # PURPOSE: The source file for this shell script is in
- # src/general/init/init.sh. It sets up some environment
- # variables and the lock file. It also parses any remaining
- # command line options for setting the GISDBASE, LOCATION, and/or
- # MAPSET. Finally it starts GRASS with the appropriate user
- # interface and cleans up after it is finished.
- # COPYRIGHT: (C) 2000-2009 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.
- #
- #############################################################################
- trap "echo 'User break!' ; exit" 2 3 15
- . "$GISBASE/etc/functions.sh"
- # Set default GUI
- DEFAULT_GUI="wxpython"
- # the following is only meant to be an internal variable for debugging this script.
- # use 'g.gisenv set="DEBUG=[0-5]"' to turn GRASS debug mode on properly.
- if [ -z "$GRASS_DEBUG" ] ; then
- GRASS_DEBUG=0
- fi
- # GRASS_SH is normally just for Windows when not started from a bourne
- # shell. But when starting from Init.sh is still needed for GRASS_GUI (still true for GRASS 7?)
- GRASS_SH=/bin/sh
- export GRASS_SH
- # Set GRASS version number for R interface etc (must be an env_var for MS-Windows)
- GRASS_VERSION="@GRASS_VERSION_NUMBER@"
- export GRASS_VERSION
- # Get the command name
- CMD_NAME=@START_UP@
- # Get the system name
- SYSTEM=`uname -s`
- case $SYSTEM in
- MINGW*)
- MINGW=1
- ;;
- CYGWIN*)
- CYGWIN=1
- ;;
- Darwin*)
- MACOSX=1
- ;;
- esac
- # Set the GIS_LOCK variable to current process id
- GIS_LOCK=$$
- export GIS_LOCK
- # Set the config subdir
- if [ ! "$GRASS_CONFIG_DIR" ] ; then
- GRASS_CONFIG_DIR=@GRASS_CONFIG_DIR@
- export $GRASS_CONFIG_DIR
- fi
- # Set the global grassrc file
- if [ -n "$GRASS_BATCH_JOB" ] ; then
- GISRCRC="$HOME/$GRASS_CONFIG_DIR/rc.`uname -n`"
- if [ ! -f "$GISRCRC" ] ; then
- GISRCRC="$HOME/$GRASS_CONGIG_DIR/rc"
- fi
- else
- GISRCRC="$HOME/$GRASS_CONFIG_DIR/rc"
- fi
- # Set PATH to GRASS bin, ETC to GRASS etc
- ETC="$GISBASE/etc"
- # Set the username and working directory
- if [ "$MINGW" ] ; then
- PWD=`pwd -W`
- USER="$USERNAME"
- if [ ! "$USER" ] ; then
- USER="user_name"
- fi
- else
- PWD=`pwd`
- USER="`whoami`"
- fi
- # Parse the command-line options
- # This can't be put into a function as it modifies argv
- for i in "$@" ; do
- case "$i" in
- # Check if the user asked for the version
- -v|--version)
- cat "$GISBASE/etc/license"
- exit
- ;;
- # Check if the user asked for help
- help|-h|-help|--help)
- help_message
- exit
- ;;
- # Check if the -text flag was given
- -text)
- GRASS_GUI="text"
- shift
- ;;
- # Check if the -gui flag was given
- -gui)
- GRASS_GUI="$DEFAULT_GUI"
- shift
- ;;
- # Check if the -wxpython flag was given
- -wxpython | -wx)
- GRASS_GUI="wxpython"
- shift
- ;;
- # Check if the user wants to create a new mapset
- -c)
- CREATE_NEW=1
- shift
- ;;
- esac
- done
- # Create the temporary directory and session grassrc file
- create_tmp
- # Create the session grassrc file
- create_gisrc
- # Ensure GRASS_GUI is set
- read_gui
- # Get Locale name
- get_locale
- # Set PATH, PYTHONPATH
- set_paths
- # Set LD_LIBRARY_PATH (etc) to find GRASS shared libraries
- if [ ! "$@LD_LIBRARY_PATH_VAR@" ] ; then
- @LD_LIBRARY_PATH_VAR@="$GISBASE/lib"
- else
- @LD_LIBRARY_PATH_VAR@="$GISBASE/lib:$@LD_LIBRARY_PATH_VAR@"
- fi
- export @LD_LIBRARY_PATH_VAR@
- # Set GRASS_PAGER, GRASS_WISH, GRASS_PYTHON, GRASS_GNUPLOT
- set_defaults
- # Set GRASS_HTML_BROWSER
- set_browser
- #predefine monitor size for certain architectures
- if [ "$HOSTTYPE" = "arm" ] ; then
- #small monitor on ARM (iPAQ, zaurus... etc)
- GRASS_HEIGHT=320
- GRASS_WIDTH=240
- export GRASS_HEIGHT GRASS_WIDTH
- fi
- if [ ! "$GRASS_PROJSHARE" ] ; then
- GRASS_PROJSHARE=@CONFIG_PROJSHARE@
- export GRASS_PROJSHARE
- fi
- # First time user - GISRC is defined in the GRASS script
- if [ ! -f "$GISRC" ] ; then
- grass_intro
- else
- clean_temp
- fi
- echo "Starting GRASS ..."
- # Check that the GUI works
- check_gui "$@"
- # Parsing argument to get LOCATION
- if [ ! "$1" ] ; then
- # Try interactive startup
- LOCATION=
- else
- non_interactive "$@"
- fi
- # User selects LOCATION and MAPSET if not set
- set_data
- # Set GISDBASE, LOCATION_NAME, MAPSET, LOCATION from $GISRC
- read_gisrc
- # Check .gislock file
- check_lock
- # build user fontcap if specified but not present
- make_fontcap
- # predefine default driver if DB connection not defined
- # is this really needed?? Modules should call this when/if required.
- if [ ! -e "$LOCATION/VAR" ] ; then
- db.connect -c --quiet
- fi
- trap "" 2 3 15
- check_shell
- check_batch_job
- start_gui
- clear_screen
- # Display the version and license info
- if [ -n "$GRASS_BATCH_JOB" ] ; then
- say_hello
- else
- show_banner
- say_hello
- show_info
- fi
- case "$sh" in
- csh|tcsh)
- csh_startup
- ;;
- bash|msh|cygwin)
- bash_startup
- ;;
- *)
- default_startup
- ;;
- esac
- trap 2 3 15
- clear_screen
- clean_temp
- rm -f "$lockfile"
- # Save GISRC
- cp "$GISRC" "$GISRCRC"
- cleanup_tmpdir
- #### after this point no more grass modules may be called ####
- done_message
|