2
#############################################################################
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
19
# This program is free software under the GNU General Public
20
# License (>=v2). Read the file COPYING that comes with GRASS
23
#############################################################################
25
trap "echo 'User break!' ; exit" 2 3 15
28
DEFAULT_GUI="wxpython"
30
# the following is only meant to be an internal variable for debugging this script.
31
# use 'g.gisenv set="DEBUG=[0-5]"' to turn GRASS debug mode on properly.
32
if [ -z "$GRASS_DEBUG" ] ; then
36
# Set the GRASS_PERL variable
37
GRASS_PERL=PERL_COMMAND
40
# GRASS_SH is normally just for Windows when not started from a bourne
41
# shell. But when starting from Init.sh is still needed for Tcl/Tk.
45
# Set GRASS version number for R interface etc (must be an env_var for MS-Windows)
46
GRASS_VERSION="GRASS_VERSION_NUMBER"
49
# Get the command name
67
# Go through the command line options
70
# Use a case to check the command line options
73
# Check if the user asked for the version
75
echo "GRASS GIS $GRASS_VERSION"
77
cat "$GISBASE/etc/license"
81
# Check if the user asked for help
84
echo " $CMD_NAME [-h | -help | --help] [-v | --version] [-c]"
85
echo " [-text | -gui | -tcltk | -oldtcltk | -wxpython | -wx]"
86
echo " [[[<GISDBASE>/]<LOCATION_NAME>/]<MAPSET>]"
89
echo " -h or -help or --help print this help message"
90
echo " -v or --version show version information and exit"
91
echo " -c create given mapset if it doesn't exist"
92
echo " -text use text based interface"
93
echo " and set as default"
94
echo " -gui use graphical user interface ($DEFAULT_GUI by default)"
95
echo " and set as default"
96
echo " -tcltk use Tcl/Tk based graphical user interface"
97
echo " and set as default"
98
echo " -oldtcltk use old Tcl/Tk based graphical user interface"
99
echo " and set as default"
100
echo " -wxpython or -wx use wxPython based graphical user interface"
101
echo " and set as default"
104
echo " GISDBASE initial database (path to GIS data)"
105
echo " LOCATION_NAME initial location"
106
echo " MAPSET initial mapset"
108
echo " GISDBASE/LOCATION_NAME/MAPSET fully qualified initial mapset directory"
110
echo "Environment variables relevant for startup:"
111
echo " GRASS_GUI select GUI (text, gui, tcltk, oldtcltk, wxpython)"
112
echo " GRASS_TCLSH set tclsh shell name to override 'tclsh'"
113
echo " GRASS_WISH set wish shell name to override 'wish'"
114
echo " GRASS_HTML_BROWSER set html web browser for help pages"
115
echo " GRASS_ADDON_PATH set additional path(s) to local GRASS modules"
116
echo " GRASS_BATCH_JOB shell script to be processed as batch job"
117
echo " GRASS_PYTHON set python shell name to override 'python'"
121
# Check if the -text flag was given
127
# Check if the -gui flag was given
129
GRASS_GUI="$DEFAULT_GUI"
133
# Check if the -tcltk flag was given
139
# Check if the -oldtcltk flag was given
145
# Check if the -wxpython flag was given
151
# Check if the user wants to create a new mapset
159
# Set the GIS_LOCK variable to current process id
163
# Set the global grassrc file
164
if [ -n "$GRASS_BATCH_JOB" ] ; then
165
GISRCRC="$HOME/.grassrc6.`uname -n`"
166
if [ ! -f "$GISRCRC" ] ; then
167
GISRCRC="$HOME/.grassrc6"
170
GISRCRC="$HOME/.grassrc6"
173
# Set the session grassrc file
174
if [ "$MINGW" ] ; then
177
if [ ! "$USER" ] ; then
180
if [ ! -f "$GISBASE/etc/monitorcap" ] ; then
181
# create an empty monitorcap
182
touch "$GISBASE/etc/monitorcap"
190
# all exits after setting up $tmp should also tidy it up
193
# remove session files from tmpdir
197
## use TMPDIR if it exists, otherwise /tmp
199
#tmp="$tmp/grass6-$USER-$GIS_LOCK"
200
tmp=/tmp/grass6-$USER-$GIS_LOCK
201
(umask 077 && mkdir "$tmp") || {
202
echo "Cannot create temporary directory! Exiting." 1>&2
208
# remove invalid GISRC file to avoid disturbing error messages:
209
cat "$GISRCRC" 2>/dev/null| grep UNKNOWN >/dev/null
210
if [ $? -eq 0 ] ; then
214
# Copy the global grassrc file to the session grassrc file
215
if [ -f "$GISRCRC" ] ; then
216
cp "$GISRCRC" "$GISRC"
217
if [ $? -eq 1 ] ; then
218
echo "Cannot copy '$GISRCRC' to '$GISRC'"
224
# Copy global grassrc file to session grassrc
226
# At this point the GRASS user interface variable has been set from the
227
# command line, been set from an external environment variable, or is
228
# not set. So we check if it is not set
229
if [ ! "$GRASS_GUI" ] ; then
231
# Check for a reference to the GRASS user interface in the grassrc file
232
if [ -f "$GISRC" ] ; then
233
GRASS_GUI=`awk '/GRASS_GUI/ {print $2}' "$GISRC"`
236
# Set the GRASS user interface to the default if needed
237
if [ ! "$GRASS_GUI" ] ; then
238
GRASS_GUI="$DEFAULT_GUI"
241
if [ "$GRASS_GUI" = "gui" ] ; then
242
GRASS_GUI="$DEFAULT_GUI"
243
elif [ "$GRASS_GUI" = "wx" ] ; then
248
# Set PATH to GRASS bin, ETC to GRASS etc
251
if [ "$LC_ALL" ] ; then
252
LCL=`echo "$LC_ALL" | sed 's/\(..\)\(.*\)/\1/'`
253
elif [ "$LC_MESSAGES" ] ; then
254
LCL=`echo "$LC_MESSAGES" | sed 's/\(..\)\(.*\)/\1/'`
256
LCL=`echo "$LANG" | sed 's/\(..\)\(.*\)/\1/'`
259
if [ -n "$GRASS_ADDON_PATH" ] ; then
260
PATH="$GISBASE/bin:$GISBASE/scripts:$GRASS_ADDON_PATH:$PATH"
262
PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"
266
# Set LD_LIBRARY_PATH to find GRASS shared libraries
267
if [ ! "$LD_LIBRARY_PATH_VAR" ] ; then
268
LD_LIBRARY_PATH_VAR="$GISBASE/lib"
270
LD_LIBRARY_PATH_VAR="$GISBASE/lib:$LD_LIBRARY_PATH_VAR"
272
export LD_LIBRARY_PATH_VAR
273
# Additional copy of variable to use with grass-run.sh
274
GRASS_LD_LIBRARY_PATH="$LD_LIBRARY_PATH_VAR"
275
export GRASS_LD_LIBRARY_PATH
277
# Set some environment variables if they are not set
278
if [ ! "$GRASS_PAGER" ] ; then
279
if [ -x /bin/more ] || [ -x /usr/bin/more ] ; then
281
elif [ -x /bin/less ] || [ -x /usr/bin/less ] ; then
283
elif [ "$MINGW" ] ; then
291
# Set up tcltk and wish environment
293
if [ ! "$GRASS_TCLSH" ] ; then
298
#WISH_OS=`echo 'puts $tcl_platform(platform) ; exit 0' | wish`
300
if [ ! "$GRASS_WISH" ] ; then
305
if [ ! "$GRASS_PYTHON" ] ; then
306
if [ "$MACOSX" ] ; then
314
# Set PYTHONPATH to find GRASS Python modules
315
if [ ! "$PYTHONPATH" ] ; then
316
PYTHONPATH="$GISBASE/etc/python"
318
PYTHONPATH="$GISBASE/etc/python:$PYTHONPATH"
321
if [ "$MINGW" ] ; then
322
PATHEXT="${PATHEXT};.PY"
326
# try and find a web browser if one isn't already specified
327
if [ ! "$GRASS_HTML_BROWSER" ] ; then
329
if [ "$MACOSX" ] ; then
330
# OSX doesn't execute browsers from the shell PATH - route thru a script
331
GRASS_HTML_BROWSER="$ETC/html_browser_mac.sh"
332
GRASS_HTML_BROWSER_MACOSX="-b com.apple.helpviewer"
333
export GRASS_HTML_BROWSER_MACOSX
335
elif [ "$MINGW" -o "$CYGWIN" ] ; then
336
# MinGW startup moved to into init.bat
337
iexplore="$SYSTEMDRIVE/Program Files/Internet Explorer/iexplore.exe"
338
if [ -f "$iexplore" ] ; then
339
GRASS_HTML_BROWSER=$iexplore
341
GRASS_HTML_BROWSER="iexplore"
346
BROWSERS="htmlview konqueror mozilla mozilla-firefox firefox opera netscape dillo"
347
for BROWSER in $BROWSERS ; do
348
for i in `echo "$PATH" | sed 's/^:/.:/
353
if [ -f "$i/$BROWSER" ] ; then
354
GRASS_HTML_BROWSER="$BROWSER"
358
if [ -n "$GRASS_HTML_BROWSER" ] ; then
364
elif [ "$MACOSX" ] ; then
365
# OSX doesn't execute browsers from the shell PATH - route thru a script
366
GRASS_HTML_BROWSER_MACOSX="-b $GRASS_HTML_BROWSER"
367
export GRASS_HTML_BROWSER_MACOSX
368
GRASS_HTML_BROWSER="$ETC/html_browser_mac.sh"
371
if [ ! "$GRASS_HTML_BROWSER" ] ; then
372
echo "WARNING: Searched for a web browser, but none found." 1>&2
373
# even so we set konqueror to make lib/gis/parser.c happy:
374
GRASS_HTML_BROWSER=konqueror
376
export GRASS_HTML_BROWSER
379
#predefine monitor size for certain architectures
380
if [ "$HOSTTYPE" = "arm" ] ; then
381
#small monitor on ARM (iPAQ, zaurus... etc)
384
export GRASS_HEIGHT GRASS_WIDTH
388
if [ ! "$GRASS_GNUPLOT" ] ; then
389
GRASS_GNUPLOT="gnuplot -persist"
393
if [ ! "$GRASS_PROJSHARE" ] ; then
394
GRASS_PROJSHARE=CONFIG_PROJSHARE
395
export GRASS_PROJSHARE
398
# First time user - GISRC is defined in the GRASS script
399
if [ ! -f "$GISRC" ] ; then
401
if [ ! -f "$GISBASE/locale/$LCL/etc/grass_intro" ] ; then
402
cat "$ETC/grass_intro"
404
cat "$GISBASE/locale/$LCL/etc/grass_intro"
408
echo "Hit RETURN to continue"
411
#for convenience, define pwd as GISDBASE:
412
echo "GISDBASE: $HOME" > "$GISRC"
413
echo 'LOCATION_NAME: <UNKNOWN>' >> "$GISRC"
414
echo 'MAPSET: <UNKNOWN>' >> "$GISRC"
416
# This is a hack for not having a good initial gui - should be removed
417
# with next version of initialization gui
421
echo "Cleaning up temporary files ..."
422
("$ETC/clean_temp" > /dev/null &)
426
echo "Starting GRASS ..."
428
# Check if we are running X windows by checking the DISPLAY variable
429
if [ "$DISPLAY" -o "$MINGW" ] ; then
431
# Check if python is working properly
432
if [ "$GRASS_GUI" = "wxpython" ]; then
433
echo 'variable=True' | "$GRASS_PYTHON" >/dev/null 2>&1
435
# Check if we need to find wish
436
if [ "$GRASS_GUI" = "tcltk" ] || \
437
[ "$GRASS_GUI" = "gis.m" ] || \
438
[ "$GRASS_GUI" = "oldtcltk" ] || \
439
[ "$GRASS_GUI" = "d.m" ] ; then
441
# Check if wish is working properly
442
echo 'exit 0' | "$GRASS_WISH" >/dev/null 2>&1
446
if [ "$?" = 0 ] ; then
447
# Set the tcltkgrass base directory
448
TCLTKGRASSBASE="$ETC"
449
# Set the wxpython base directory
450
WXPYTHONGRASSBASE="$ETC/wxpython"
453
# Wish was not found - switch to text interface mode
455
echo "WARNING: The wish command does not work as expected!"
456
echo "Please check your GRASS_WISH environment variable."
457
echo "Use the -help option for details."
458
echo "Switching to text based interface mode."
460
echo "Hit RETURN to continue."
467
# Display a message if a graphical interface was expected
468
if [ "$GRASS_GUI" != "text" ] ; then
469
# Set the interface mode to text
471
echo "WARNING: It appears that the X Windows system is not active."
472
echo "A graphical based user interface is not supported."
473
echo "Switching to text based interface mode."
475
echo "Hit RETURN to continue"
482
# Save the user interface variable in the grassrc file - choose a temporary
483
# file name that should not match another file
484
if [ -f "$GISRC" ] ; then
485
awk '$1 !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"
486
echo "GRASS_GUI: $GRASS_GUI" >> "$GISRC.$$"
487
mv -f "$GISRC.$$" "$GISRC"
490
# Parsing argument to get LOCATION
493
# Try interactive startup
497
# Try non-interactive startup
500
if [ "$1" = "-" ] ; then
502
if [ "$LOCATION" ] ; then
510
if [ "$L" = "." ] ; then
512
elif [ `echo "$L" | cut -c 1` != "/" ] ; then
516
MAPSET=`basename "$L"`
519
if [ "$L" != "." ] ; then
520
LOCATION_NAME=`basename "$L"`
523
if [ "$L" != "." ] ; then
529
#strip off white space from LOCATION_NAME and MAPSET: only supported for $GISDBASE
530
MAPSET=`echo $MAPSET | sed 's+ ++g'`
531
LOCATION_NAME=`echo $LOCATION_NAME | sed 's+ ++g'`
533
if [ "$GISDBASE" -a "$LOCATION_NAME" -a "$MAPSET" ] ; then
534
LOCATION="$GISDBASE/$LOCATION_NAME/$MAPSET"
536
if [ ! -r "$LOCATION/WIND" ] ; then
537
if [ "$LOCATION_NAME" = "PERMANENT" ] ; then
538
echo "$LOCATION: Not a valid GRASS location"
542
# the user wants to create mapset on the fly
543
if [ -n "$CREATE_NEW" ] && [ "$CREATE_NEW" -eq 1 ] ; then
544
if [ ! -f "$GISDBASE/$LOCATION_NAME/PERMANENT/DEFAULT_WIND" ] ; then
545
echo "The LOCATION \"$LOCATION_NAME\" does not exist. Please create it first"
550
cp "$GISDBASE/$LOCATION_NAME/PERMANENT/DEFAULT_WIND" "$LOCATION/WIND"
551
echo "Missing WIND file fixed"
554
echo "$LOCATION: Not a valid GRASS location"
561
if [ -s "$GISRC" ] ; then
562
sed -e "s|^GISDBASE:.*$|GISDBASE: $GISDBASE|; \
563
s|^LOCATION_NAME:.*$|LOCATION_NAME: $LOCATION_NAME|; \
564
s|^MAPSET:.*$|MAPSET: $MAPSET|" "$GISRC" > "$GISRC.$$"
566
if [ $? -eq 0 ] ; then
567
mv -f "$GISRC.$$" "$GISRC"
570
echo "Failed to create new $GISRC"
574
echo "GISDBASE: $GISDBASE" > "$GISRC"
575
echo "LOCATION_NAME: $LOCATION_NAME" >> "$GISRC"
576
echo "MAPSET: $MAPSET" >> "$GISRC"
579
echo "GISDBASE, LOCATION_NAME and MAPSET variables not set properly."
580
echo "Interactive startup needed."
586
# User selects LOCATION and MAPSET if not set
587
if [ ! "$LOCATION" ] ; then
591
# Check for text interface
598
# Check for an invalid GISRC file
599
if [ -f "$GISRC" ] ; then
600
VALUE=`grep "GISDBASE" "$GISRC"`
601
if [ "$VALUE" = "" ] ; then
602
echo "Invalid resource file, removing $GISRC"
613
# Check that GUI support software is functional
614
tcltk | gis.m | oldtcltk | d.m | wxpython)
616
if [ "$GRASS_GUI" = "tcltk" ] || \
617
[ "$GRASS_GUI" = "gis.m" ] || \
618
[ "$GRASS_GUI" = "oldtcltk" ] || \
619
[ "$GRASS_GUI" = "d.m" ] ; then
621
# eval `foo` will return subshell return code and not app foo return code!!!
622
eval '"$GRASS_WISH" -file "$TCLTKGRASSBASE/gis_set.tcl"'
625
eval '"$GRASS_PYTHON" "$WXPYTHONGRASSBASE/gis_set.py"'
633
# The gis_set script printed an error message so wait
634
# for user to read it
635
echo "Error in GUI startup. If necessary, please"
636
echo "report this error to the GRASS developers."
637
echo "Switching to text mode now."
638
echo "Hit RETURN to continue..."
643
if [ -f "$GISRC" ] ; then
644
awk '$1 !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"
645
echo "GRASS_GUI: $GRASS_GUI" >> "$GISRC.$$"
646
mv -f "$GISRC.$$" "$GISRC"
654
# Check for an invalid GISRC file
655
if [ -f "$GISRC" ] ; then
656
VALUE=`grep "GISDBASE" "$GISRC"`
657
if [ "$VALUE" = "" ] ; then
658
echo "Invalid resource file, removing $GISRC"
670
# These checks should not be necessary with real init stuff
671
if [ "$LOCATION_NAME" = "##NONE##" ] ; then
674
echo "GISDBASE: $OLD_DB" > "$GISRC"
675
echo "LOCATION_NAME: $OLD_LOC" >> "$GISRC"
676
echo "MAPSET: $OLD_MAP" >> "$GISRC"
682
if [ "$LOCATION_NAME" = "##ERROR##" ] ; then
683
echo "The selected location is not a valid GRASS location"
691
# User wants to exit from GRASS
692
echo "Received EXIT message from GUI."
693
echo "GRASS is not started. Bye."
698
echo "ERROR: Invalid return code from gis_set.tcl."
699
echo "Please advise GRASS developers of this error."
705
# Shouldn't need this but you never know
706
echo "ERROR: Invalid user interface specified - <$GRASS_GUI>."
707
echo "Use the --help option to see valid interface names."
714
GISDBASE=`g.gisenv GISDBASE`
715
LOCATION_NAME=`g.gisenv LOCATION_NAME`
716
MAPSET=`g.gisenv MAPSET`
718
if [ -z "$GISDBASE" ] || [ -z "$LOCATION_NAME" ] || [ -z "$MAPSET" ] ; then
719
echo "ERROR: Reading data path information from g.gisenv."
720
echo "GISDBASE=[$GISDBASE]"
721
echo "LOCATION_NAME=[$LOCATION_NAME]"
722
echo "MAPSET=[$MAPSET]"
724
echo "Check the <$GISRCRC> file."
729
LOCATION="${GISDBASE?}/${LOCATION_NAME?}/${MAPSET?}"
731
# Check for concurrent use
732
lockfile="$LOCATION/.gislock"
733
"$ETC/lock" "$lockfile" $$
737
echo "$USER is currently running GRASS in selected mapset (file $lockfile found). Concurrent use not allowed."
741
echo Unable to properly access "$lockfile"
742
echo Please notify system personel.
747
# build user fontcap if specified but not present
748
if [ "$GRASS_FONT_CAP" ] && [ ! -f "$GRASS_FONT_CAP" ] ; then
749
echo "Building user fontcap ..."
753
# predefine default driver if DB connection not defined
754
# is this really needed?? Modules should call this when/if required.
755
if [ ! -e "$LOCATION/VAR" ] ; then
756
db.connect -c --quiet
761
# cygwin has many problems with the shell setup
762
# below, so i hardcoded everything here.
763
if [ "$CYGWIN" ] ; then
765
shellname="GNU Bash (Cygwin)"
766
export SHELL=/usr/bin/bash.exe
769
sh=`basename "$SHELL"`
771
ksh) shellname="Korn Shell";;
772
csh) shellname="C Shell" ;;
773
tcsh) shellname="TC Shell" ;;
774
bash) shellname="Bash Shell" ;;
775
sh) shellname="Bourne Shell";;
781
if [ ! -x "$SHELL" ] ; then
782
echo "ERROR: The SHELL variable is not set" 1>&2
788
# hack to process batch jobs:
789
if [ -n "$GRASS_BATCH_JOB" ] ; then
791
if [ ! -f "$GRASS_BATCH_JOB" ] ; then
793
echo "Job file '$GRASS_BATCH_JOB' has been defined in"
794
echo "the 'GRASS_BATCH_JOB' variable but not found. Exiting."
796
echo "Use 'unset GRASS_BATCH_JOB' to disable batch job processing."
800
# right file, but ...
801
if [ ! -x "$GRASS_BATCH_JOB" ] ; then
802
echo "ERROR: change file permission to 'executable' for '$GRASS_BATCH_JOB'"
806
echo "Executing '$GRASS_BATCH_JOB' ..."
808
SHELL="$GRASS_BATCH_JOB"
813
# Start the chosen GUI but ignore text
814
if [ "$GRASS_DEBUG" -ne 0 ] ; then
815
echo "GRASS GUI should be $GRASS_GUI"
820
# Check for tcltk interface
822
if [ "$sh" != "bash" ] && [ "$sh" != "msh" ] && [ "$sh" != "cygwin" ]; then
823
# trap is not supported by csh/tcsh and rc
824
"$GISBASE/scripts/gis.m"
828
"$GISBASE/scripts/d.m"
831
"$GRASS_PYTHON" "$GISBASE/etc/wxpython/wxgui.py" &
839
# Display the version and license info
840
if [ "$MINGW" ] ; then
842
# TODO: uncomment when PDCurses works.
845
if [ -z "$GRASS_BATCH_JOB" ] && [ "$GRASS_DEBUG" -eq 0 ] ; then
853
if [ -f "$GISBASE/locale/$LCL/etc/welcome" ] ; then
854
cat "$GISBASE/locale/$LCL/etc/welcome"
861
if [ -n "$GRASS_BATCH_JOB" ] ; then
865
__________ ___ __________ _______________
866
/ ____/ __ \/ | / ___/ ___/ / ____/ _/ ___/
867
/ / __/ /_/ / /| | \__ \\\\_ \\ / / __ / / \\__ \\
868
/ /_/ / _, _/ ___ |___/ /__/ / / /_/ // / ___/ /
869
\____/_/ |_/_/ |_/____/____/ \____/___//____/
874
echo "GRASS homepage: http://grass.osgeo.org/"
875
echo "This version running thru: $shellname ($SHELL)"
876
echo "Help is available with the command: g.manual -i"
877
echo "See the licence terms with: g.version -c"
881
echo "If required, restart the GUI with: g.gui tcltk"
884
echo "If required, restart the GUI with: g.gui oldtcltk"
887
echo "If required, restart the GUI with: g.gui wxpython"
890
echo "Start the GUI with: g.gui $DEFAULT_GUI"
894
echo "When ready to quit enter: exit"
902
USERHOME="$HOME" # save original home
906
tcshrc="$HOME/.tcshrc"
907
rm -f "$cshrc" "$tcshrc"
908
echo "set home = $USERHOME" > "$cshrc"
909
echo "set history = 3000 savehist = 3000 noclobber ignoreeof" >> "$cshrc"
910
echo "set histfile = $HOME/.history" >> "$cshrc"
912
echo "set prompt = '\\" >> "$cshrc"
913
echo "Mapset <${MAPSET}> in Location <${LOCATION_NAME}> \\" >> "$cshrc"
914
echo "GRASS GRASS_VERSION_NUMBER > '" >> "$cshrc"
915
echo 'set BOGUS=``;unset BOGUS' >> "$cshrc"
917
if [ -r "$USERHOME/.grass.cshrc" ]
919
cat "$USERHOME/.grass.cshrc" >> "$cshrc"
922
if [ -r "$USERHOME/.cshrc" ]
924
grep '^ *set *mail *= *' "$USERHOME/.cshrc" >> "$cshrc"
927
if [ -r "$USERHOME/.tcshrc" ]
929
grep '^ *set *mail *= *' "$USERHOME/.tcshrc" >> "$cshrc"
932
if [ -r "$USERHOME/.login" ]
934
grep '^ *set *mail *= *' "$USERHOME/.login" >> "$cshrc"
937
echo "set path = ( $PATH ) " | sed 's/:/ /g' >> "$cshrc"
939
cp "$cshrc" "$tcshrc"
948
# save command history in mapset dir and remember more
949
export HISTFILE="$LOCATION/.bash_history"
950
if [ -z "$HISTSIZE" ] && [ -z "$HISTFILESIZE" ] ; then
954
# instead of changing $HOME, start bash with: --rcfile "$LOCATION/.bashrc" ?
955
# if so, must care be taken to explicity call .grass.bashrc et al for
956
# non-interactive bash batch jobs?
957
USERHOME="$HOME" # save original home
958
HOME="$LOCATION" # save .bashrc in $LOCATION
960
bashrc="$HOME/.bashrc"
962
echo "test -r ~/.alias && . ~/.alias" >> "$bashrc"
963
echo "PS1='GRASS GRASS_VERSION_NUMBER ($LOCATION_NAME):\w > '" >> "$bashrc"
964
# Use \"' to allow spaces in $GISBASE
965
echo "PROMPT_COMMAND=\"'$GISBASE/etc/prompt.sh'\"" >> "$bashrc"
967
if [ -r "$USERHOME/.grass.bashrc" ]
969
cat "$USERHOME/.grass.bashrc" >> "$bashrc"
972
echo "export PATH=\"$PATH\"" >> "$bashrc"
973
echo "export HOME=\"$USERHOME\"" >> "$bashrc" # restore user home path
974
echo 'export GRASS_SHELL_PID=$$' >> "$bashrc" # can be used to terminate GRASS session from GUI
975
if [ "$GRASS_GUI" = tcltk ] || [ "$GRASS_GUI" = gis.m ]; then
976
echo '$GISBASE/scripts/gis.m' >> "$bashrc" # Start gis.m
978
echo 'trap "echo \"GUI issued an exit\"; exit" SIGQUIT' >> "$bashrc"
988
if [ "$MINGW" ] ; then
989
GRASS_BASE_VERSION=`echo "$GRASS_VERSION" | cut -f1,2 -d.`
990
PS1="GRASS $GRASS_BASE_VERSION> "
993
# "$ETC/run" doesn't work at all???
995
rm -rf "$LOCATION/.tmp"/* # remove gis.m session files from .tmp
997
PS1="GRASS $GRASS_VERSION ($LOCATION_NAME):\w > "
1008
# GRASS session finished
1009
if [ "$MINGW" ] ; then
1011
# TODO: uncomment when PDCurses works.
1014
if [ -z "$GRASS_BATCH_JOB" ] && [ "$GRASS_DEBUG" -eq 0 ] ; then
1019
echo "Closing monitors ..."
1020
for MON in `d.mon -L | grep running | grep -v "not running" | sed 's/ .*//'`
1022
if [ "$GRASS_DEBUG" -ne 0 ] ; then
1023
echo "d.mon stop=$MON"
1028
# Attempt to close any open gis.m instances.
1029
if [ -n "$TCLTKGRASSBASE" ] && [ `ps -a | grep -c "$GRASS_WISH"` -ge 1 ] ; then
1030
echo "Closing open gis.m sessions....."
1031
echo 'foreach gwin [lsearch -all -inline [winfo interps] gm_tcl*] {
1032
catch {send -async $gwin Gm::remoteExit $env(GIS_LOCK)}
1034
exit' | "$GRASS_WISH" #>/dev/null 2>&1
1037
echo "Cleaning up temporary files ..."
1039
"$ETC/clean_temp" > /dev/null
1043
cp "$GISRC" "$GISRCRC"
1047
#### after this point no more grass modules may be called ####
1049
if [ -x "$GRASS_BATCH_JOB" ] ; then
1050
echo "Batch job '$GRASS_BATCH_JOB' (defined in GRASS_BATCH_JOB variable) was executed."
1051
echo "Goodbye from GRASS GIS"
1058
echo "Goodbye from GRASS GIS"