functions.sh 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771
  1. # all exits after setting up $tmp should also tidy it up
  2. cleanup_tmpdir()
  3. {
  4. # remove session files from tmpdir
  5. rm -rf "$tmp"
  6. }
  7. help_message()
  8. {
  9. cat <<-EOF
  10. Usage:
  11. $CMD_NAME [-h | -help | --help] [-v | --version] [-c]
  12. [-text | -gui | -wxpython | -wx]
  13. [[[<GISDBASE>/]<LOCATION_NAME>/]<MAPSET>]
  14. Flags:
  15. -h or -help or --help print this help message
  16. -v or --version show version information and exit
  17. -c create given mapset if it doesn\'t exist
  18. -text use text based interface
  19. and set as default
  20. -gui use graphical user interface ($DEFAULT_GUI by default)
  21. and set as default
  22. -wxpython or -wx use wxPython based graphical user interface
  23. and set as default
  24. Parameters:
  25. GISDBASE initial database (path to GIS data)
  26. LOCATION_NAME initial location
  27. MAPSET initial mapset
  28. GISDBASE/LOCATION_NAME/MAPSET fully qualified initial mapset directory
  29. Environment variables relevant for startup:
  30. GRASS_GUI select GUI (text, gui, wxpython)
  31. GRASS_WISH set wish shell name to override 'wish'
  32. GRASS_HTML_BROWSER set html web browser for help pages
  33. GRASS_ADDON_PATH set additional path(s) to local GRASS modules
  34. GRASS_BATCH_JOB shell script to be processed as batch job
  35. GRASS_PYTHON set python shell name to override 'python'
  36. EOF
  37. }
  38. create_tmp()
  39. {
  40. ## use TMPDIR if it exists, otherwise /tmp
  41. tmp="${TMPDIR-/tmp}/grass7-$USER-$GIS_LOCK"
  42. (umask 077 && mkdir "$tmp") || (
  43. echo "Cannot create temporary directory! Exiting." 1>&2
  44. exit 1
  45. )
  46. }
  47. create_gisrc()
  48. {
  49. # Set the session grassrc file
  50. GISRC="$tmp/gisrc"
  51. export GISRC
  52. # remove invalid GISRC file to avoid disturbing error messages:
  53. cat "$GISRCRC" 2>/dev/null| grep UNKNOWN >/dev/null
  54. if [ $? -eq 0 ] ; then
  55. rm -f "$GISRCRC"
  56. fi
  57. # Copy the global grassrc file to the session grassrc file
  58. if [ -f "$GISRCRC" ] ; then
  59. cp "$GISRCRC" "$GISRC"
  60. if [ $? -eq 1 ] ; then
  61. echo "Cannot copy '$GISRCRC' to '$GISRC'"
  62. cleanup_tmpdir
  63. exit 1
  64. fi
  65. fi
  66. }
  67. read_gui()
  68. {
  69. # At this point the GRASS user interface variable has been set from the
  70. # command line, been set from an external environment variable, or is
  71. # not set. So we check if it is not set
  72. if [ ! "$GRASS_GUI" ] ; then
  73. # Check for a reference to the GRASS user interface in the grassrc file
  74. if [ -f "$GISRC" ] ; then
  75. GRASS_GUI=`awk '/GRASS_GUI/ {print $2}' "$GISRC"`
  76. fi
  77. # Set the GRASS user interface to the default if needed
  78. if [ ! "$GRASS_GUI" ] ; then
  79. GRASS_GUI="$DEFAULT_GUI"
  80. fi
  81. fi
  82. if [ "$GRASS_GUI" = "gui" ] ; then
  83. GRASS_GUI="$DEFAULT_GUI"
  84. fi
  85. # FIXME oldtcltk, gis.m, d.m no longer exist
  86. case "$GRASS_GUI" in
  87. d.m | oldtcltk | gis.m)
  88. GRASS_GUI="$DEFAULT_GUI"
  89. ;;
  90. esac
  91. }
  92. get_locale()
  93. {
  94. if [ "$LC_ALL" ] ; then
  95. LCL=`echo "$LC_ALL" | sed 's/\(..\)\(.*\)/\1/'`
  96. elif [ "$LC_MESSAGES" ] ; then
  97. LCL=`echo "$LC_MESSAGES" | sed 's/\(..\)\(.*\)/\1/'`
  98. else
  99. LCL=`echo "$LANG" | sed 's/\(..\)\(.*\)/\1/'`
  100. fi
  101. }
  102. set_paths()
  103. {
  104. if [ -n "$GRASS_ADDON_PATH" ] ; then
  105. PATH="$GISBASE/bin:$GISBASE/scripts:$GRASS_ADDON_PATH:$PATH"
  106. else
  107. PATH="$GISBASE/bin:$GISBASE/scripts:$PATH"
  108. fi
  109. export PATH
  110. # Set PYTHONPATH to find GRASS Python modules
  111. if [ ! "$PYTHONPATH" ] ; then
  112. PYTHONPATH="$GISBASE/etc/python"
  113. else
  114. PYTHONPATH="$GISBASE/etc/python:$PYTHONPATH"
  115. fi
  116. export PYTHONPATH
  117. }
  118. set_defaults()
  119. {
  120. # GRASS_PAGER
  121. if [ ! "$GRASS_PAGER" ] ; then
  122. if [ -x /bin/more ] || [ -x /usr/bin/more ] ; then
  123. GRASS_PAGER=more
  124. elif [ -x /bin/less ] || [ -x /usr/bin/less ] ; then
  125. GRASS_PAGER=less
  126. elif [ "$MINGW" ] ; then
  127. GRASS_PAGER=more
  128. else
  129. GRASS_PAGER=cat
  130. fi
  131. export GRASS_PAGER
  132. fi
  133. # GRASS_WISH
  134. if [ ! "$GRASS_WISH" ] ; then
  135. GRASS_WISH=wish
  136. export GRASS_WISH
  137. fi
  138. # GRASS_PYTHON
  139. if [ ! "$GRASS_PYTHON" ] ; then
  140. GRASS_PYTHON=python
  141. export GRASS_PYTHON
  142. fi
  143. # GRASS_GNUPLOT
  144. if [ ! "$GRASS_GNUPLOT" ] ; then
  145. GRASS_GNUPLOT="gnuplot -persist"
  146. export GRASS_GNUPLOT
  147. fi
  148. }
  149. set_browser()
  150. {
  151. # GRASS_HTML_BROWSER
  152. if [ ! "$GRASS_HTML_BROWSER" ] ; then
  153. if [ "$MACOSX" ] ; then
  154. # OSX doesn't execute browsers from the shell PATH - route thru a script
  155. GRASS_HTML_BROWSER="$ETC/html_browser_mac.sh"
  156. GRASS_HTML_BROWSER_MACOSX="-b com.apple.helpviewer"
  157. export GRASS_HTML_BROWSER_MACOSX
  158. elif [ "$MINGW" -o "$CYGWIN" ] ; then
  159. # MinGW startup moved to into init.bat
  160. iexplore="$SYSTEMDRIVE/Program Files/Internet Explorer/iexplore.exe"
  161. if [ -f "$iexplore" ] ; then
  162. GRASS_HTML_BROWSER=$iexplore
  163. else
  164. GRASS_HTML_BROWSER="iexplore"
  165. fi
  166. else
  167. # the usual suspects
  168. BROWSERS="htmlview konqueror mozilla mozilla-firefox firefox opera netscape dillo"
  169. for BROWSER in $BROWSERS ; do
  170. for i in `echo "$PATH" | sed 's/^:/.:/ ; s/::/:.:/g ; s/:$/:./ ; s/:/ /g'` ; do
  171. if [ -f "$i/$BROWSER" ] ; then
  172. GRASS_HTML_BROWSER="$BROWSER"
  173. break
  174. fi
  175. done
  176. if [ -n "$GRASS_HTML_BROWSER" ] ; then
  177. break
  178. fi
  179. done
  180. fi
  181. fi
  182. if [ "$MACOSX" -a "$GRASS_HTML_BROWSER" != "" ] ; then
  183. # OSX doesn't execute browsers from the shell PATH - route thru a script
  184. GRASS_HTML_BROWSER_MACOSX="-b $GRASS_HTML_BROWSER"
  185. export GRASS_HTML_BROWSER_MACOSX
  186. GRASS_HTML_BROWSER="$ETC/html_browser_mac.sh"
  187. fi
  188. if [ ! "$GRASS_HTML_BROWSER" ] ; then
  189. echo "WARNING: Searched for a web browser, but none found." 1>&2
  190. # even so we set konqueror to make lib/gis/parser.c happy:
  191. GRASS_HTML_BROWSER=konqueror
  192. fi
  193. export GRASS_HTML_BROWSER
  194. }
  195. grass_intro()
  196. {
  197. if [ ! -f "$GISBASE/locale/$LCL/etc/grass_intro" ] ; then
  198. cat "$ETC/grass_intro"
  199. else
  200. cat "$GISBASE/locale/$LCL/etc/grass_intro"
  201. fi
  202. echo
  203. echo "Hit RETURN to continue"
  204. read ans
  205. #for convenience, define pwd as GISDBASE:
  206. cat > "$GISRC" <<-EOF
  207. GISDBASE: $PWD
  208. LOCATION_NAME: <UNKNOWN>
  209. MAPSET: <UNKNOWN>
  210. EOF
  211. }
  212. check_gui()
  213. {
  214. # Check if we are running X windows by checking the DISPLAY variable
  215. if [ "$DISPLAY" -o "$MINGW" ] ; then
  216. # Check if python is working properly
  217. if [ "$GRASS_GUI" = "wxpython" ]; then
  218. echo 'variable=True' | "$GRASS_PYTHON" >/dev/null 2>&1
  219. fi
  220. # ok
  221. if [ "$?" = 0 ] ; then
  222. # Set the wxpython base directory
  223. WXPYTHONGRASSBASE="$ETC/wxpython"
  224. else
  225. # Python was not found - switch to text interface mode
  226. cat <<-EOF
  227. WARNING: The python command does not work as expected!
  228. Please check your GRASS_PYTHON environment variable.
  229. Use the -help option for details.
  230. Switching to text based interface mode.
  231. Hit RETURN to continue.
  232. EOF
  233. read ans
  234. GRASS_GUI="text"
  235. fi
  236. else
  237. # Display a message if a graphical interface was expected
  238. if [ "$GRASS_GUI" != "text" ] ; then
  239. # Set the interface mode to text
  240. cat <<-EOF
  241. WARNING: It appears that the X Windows system is not active.
  242. A graphical based user interface is not supported.
  243. Switching to text based interface mode.
  244. Hit RETURN to continue
  245. EOF
  246. read ans
  247. GRASS_GUI="text"
  248. fi
  249. fi
  250. # Save the user interface variable in the grassrc file - choose a temporary
  251. # file name that should not match another file
  252. if [ -f "$GISRC" ] ; then
  253. awk '$1 !~ /GRASS_GUI/ {print}' "$GISRC" > "$GISRC.$$"
  254. echo "GRASS_GUI: $GRASS_GUI" >> "$GISRC.$$"
  255. mv -f "$GISRC.$$" "$GISRC"
  256. fi
  257. }
  258. non_interactive()
  259. {
  260. # Try non-interactive startup
  261. L=
  262. if [ "$1" = "-" ] ; then
  263. if [ "$LOCATION" ] ; then
  264. L="$LOCATION"
  265. fi
  266. else
  267. L="$1"
  268. fi
  269. if [ "$L" ] ; then
  270. if [ "$L" = "." ] ; then
  271. L=$PWD
  272. elif [ `echo "$L" | cut -c 1` != "/" ] ; then
  273. L="$PWD/$L"
  274. fi
  275. MAPSET=`basename "$L"`
  276. L=`dirname "$L"`
  277. if [ "$L" != "." ] ; then
  278. LOCATION_NAME=`basename "$L"`
  279. L=`dirname "$L"`
  280. if [ "$L" != "." ] ; then
  281. GISDBASE="$L"
  282. fi
  283. fi
  284. fi
  285. #strip off white space from LOCATION_NAME and MAPSET: only supported for $GISDBASE
  286. MAPSET=`echo $MAPSET | sed 's+ ++g'`
  287. LOCATION_NAME=`echo $LOCATION_NAME | sed 's+ ++g'`
  288. if [ "$GISDBASE" -a "$LOCATION_NAME" -a "$MAPSET" ] ; then
  289. LOCATION="$GISDBASE/$LOCATION_NAME/$MAPSET"
  290. if [ ! -r "$LOCATION/WIND" ] ; then
  291. if [ "$LOCATION_NAME" = "PERMANENT" ] ; then
  292. echo "$LOCATION: Not a valid GRASS location"
  293. cleanup_tmpdir
  294. exit 1
  295. else
  296. # the user wants to create mapset on the fly
  297. if [ -n "$CREATE_NEW" ] && [ "$CREATE_NEW" -eq 1 ] ; then
  298. if [ ! -f "$GISDBASE/$LOCATION_NAME/PERMANENT/DEFAULT_WIND" ] ; then
  299. echo "The LOCATION \"$LOCATION_NAME\" does not exist. Please create it first"
  300. cleanup_tmpdir
  301. exit 1
  302. else
  303. mkdir -p "$LOCATION"
  304. cp "$GISDBASE/$LOCATION_NAME/PERMANENT/DEFAULT_WIND" "$LOCATION/WIND"
  305. echo "Missing WIND file fixed"
  306. fi
  307. else
  308. echo "$LOCATION: Not a valid GRASS location"
  309. cleanup_tmpdir
  310. exit 1
  311. fi
  312. fi
  313. fi
  314. if [ -s "$GISRC" ] ; then
  315. sed -e "s|^GISDBASE:.*$|GISDBASE: $GISDBASE|; \
  316. s|^LOCATION_NAME:.*$|LOCATION_NAME: $LOCATION_NAME|; \
  317. s|^MAPSET:.*$|MAPSET: $MAPSET|" "$GISRC" > "$GISRC.$$"
  318. if [ $? -eq 0 ] ; then
  319. mv -f "$GISRC.$$" "$GISRC"
  320. else
  321. rm -f "$GISRC.$$"
  322. echo "Failed to create new $GISRC"
  323. LOCATION=
  324. fi
  325. else
  326. cat > "$GISRC" <<-EOF
  327. GISDBASE: $GISDBASE
  328. LOCATION_NAME: $LOCATION_NAME
  329. MAPSET: $MAPSET
  330. EOF
  331. fi
  332. else
  333. echo "GISDBASE, LOCATION_NAME and MAPSET variables not set properly."
  334. echo "Interactive startup needed."
  335. cleanup_tmpdir
  336. exit 1
  337. fi
  338. }
  339. set_data()
  340. {
  341. # User selects LOCATION and MAPSET if not set
  342. if [ ! "$LOCATION" ] ; then
  343. case "$GRASS_GUI" in
  344. # Check for text interface
  345. text)
  346. ;;
  347. # Check for GUI
  348. wxpython)
  349. gui_startup
  350. ;;
  351. *)
  352. # Shouldn't need this but you never know
  353. echo "ERROR: Invalid user interface specified - <$GRASS_GUI>."
  354. echo "Use the --help option to see valid interface names."
  355. cleanup_tmpdir
  356. exit 1
  357. ;;
  358. esac
  359. fi
  360. }
  361. gui_startup()
  362. {
  363. if [ "$GRASS_GUI" = "wxpython" ] ; then
  364. # eval `foo` will return subshell return code and not app foo return code!!!
  365. eval '"$GRASS_PYTHON" "$WXPYTHONGRASSBASE/gis_set.py"'
  366. thetest=$?
  367. fi
  368. case $thetest in
  369. 1)
  370. # The startup script printed an error message so wait
  371. # for user to read it
  372. cat <<-EOF
  373. Error in GUI startup. If necessary, please
  374. report this error to the GRASS developers.
  375. Switching to text mode now.
  376. Hit RETURN to continue...
  377. EOF
  378. read ans
  379. exec "$CMD_NAME" -text
  380. cleanup_tmpdir
  381. exit 1
  382. ;;
  383. 0)
  384. # These checks should not be necessary with real init stuff
  385. if [ "$LOCATION_NAME" = "##NONE##" ] || [ "$LOCATION_NAME" = "##ERROR##" ] ; then
  386. echo "The selected location is not a valid GRASS location"
  387. cleanup_tmpdir
  388. exit 1
  389. fi
  390. ;;
  391. 2)
  392. # User wants to exit from GRASS
  393. echo "Received EXIT message from GUI."
  394. echo "GRASS is not started. Bye."
  395. cleanup_tmpdir
  396. exit 0
  397. ;;
  398. *)
  399. echo "ERROR: Invalid return code from GUI startup script."
  400. echo "Please advise GRASS developers of this error."
  401. cleanup_tmpdir
  402. exit 1
  403. ;;
  404. esac
  405. }
  406. read_gisrc()
  407. {
  408. GISDBASE=`g.gisenv GISDBASE`
  409. LOCATION_NAME=`g.gisenv LOCATION_NAME`
  410. MAPSET=`g.gisenv MAPSET`
  411. if [ -z "$GISDBASE" ] || [ -z "$LOCATION_NAME" ] || [ -z "$MAPSET" ] ; then
  412. cat <<-EOF
  413. ERROR: Reading data path information from g.gisenv.
  414. GISDBASE=[$GISDBASE]
  415. LOCATION_NAME=[$LOCATION_NAME]
  416. MAPSET=[$MAPSET]
  417. Check the <$GISRCRC> file.
  418. EOF
  419. cleanup_tmpdir
  420. exit 1
  421. fi
  422. LOCATION="${GISDBASE?}/${LOCATION_NAME?}/${MAPSET?}"
  423. }
  424. check_lock()
  425. {
  426. # Check for concurrent use
  427. lockfile="$LOCATION/.gislock"
  428. "$ETC/lock" "$lockfile" $$
  429. case $? in
  430. 0) ;;
  431. 1)
  432. echo "$USER is currently running GRASS in selected mapset (file $lockfile found). Concurrent use not allowed."
  433. cleanup_tmpdir
  434. exit 1 ;;
  435. *)
  436. echo Unable to properly access "$lockfile"
  437. echo Please notify system personel.
  438. cleanup_tmpdir
  439. exit 1 ;;
  440. esac
  441. }
  442. make_fontcap()
  443. {
  444. if [ "$GRASS_FONT_CAP" ] && [ ! -f "$GRASS_FONT_CAP" ] ; then
  445. echo "Building user fontcap ..."
  446. g.mkfontcap
  447. fi
  448. }
  449. check_shell()
  450. {
  451. # cygwin has many problems with the shell setup
  452. # below, so i hardcoded everything here.
  453. if [ "$CYGWIN" ] ; then
  454. sh="cygwin"
  455. shellname="GNU Bash (Cygwin)"
  456. export SHELL=/usr/bin/bash.exe
  457. export OSTYPE=cygwin
  458. else
  459. sh=`basename "$SHELL"`
  460. case "$sh" in
  461. ksh) shellname="Korn Shell";;
  462. csh) shellname="C Shell" ;;
  463. tcsh) shellname="TC Shell" ;;
  464. bash) shellname="Bash Shell" ;;
  465. sh) shellname="Bourne Shell";;
  466. *) shellname=shell;;
  467. esac
  468. fi
  469. # check for SHELL
  470. if [ ! -x "$SHELL" ] ; then
  471. echo "ERROR: The SHELL variable is not set" 1>&2
  472. rm -f "$lockfile"
  473. cleanup_tmpdir
  474. exit 1
  475. fi
  476. }
  477. check_batch_job()
  478. {
  479. # hack to process batch jobs:
  480. if [ -n "$GRASS_BATCH_JOB" ] ; then
  481. # defined, but ...
  482. if [ ! -f "$GRASS_BATCH_JOB" ] ; then
  483. # wrong file
  484. echo "Job file '$GRASS_BATCH_JOB' has been defined in"
  485. echo "the 'GRASS_BATCH_JOB' variable but not found. Exiting."
  486. echo
  487. echo "Use 'unset GRASS_BATCH_JOB' to disable batch job processing."
  488. cleanup_tmpdir
  489. exit 1
  490. else
  491. # right file, but ...
  492. if [ ! -x "$GRASS_BATCH_JOB" ] ; then
  493. echo "ERROR: change file permission to 'executable' for '$GRASS_BATCH_JOB'"
  494. cleanup_tmpdir
  495. exit 1
  496. else
  497. echo "Executing '$GRASS_BATCH_JOB' ..."
  498. GRASS_GUI="text"
  499. SHELL="$GRASS_BATCH_JOB"
  500. fi
  501. fi
  502. fi
  503. }
  504. start_gui()
  505. {
  506. # Start the chosen GUI but ignore text
  507. if [ "$GRASS_DEBUG" -ne 0 ] ; then
  508. echo "GRASS GUI should be $GRASS_GUI"
  509. fi
  510. case "$GRASS_GUI" in
  511. # Check for gui interface
  512. wxpython)
  513. "$GISBASE/etc/wxpython/scripts/wxgui"
  514. ;;
  515. # Ignore others
  516. *)
  517. ;;
  518. esac
  519. }
  520. clear_screen()
  521. {
  522. if [ "$MINGW" ] ; then
  523. :
  524. # TODO: uncomment when PDCurses works.
  525. # cls
  526. else
  527. if [ -z "$GRASS_BATCH_JOB" ] && [ "$GRASS_DEBUG" -eq 0 ] ; then
  528. tput clear
  529. fi
  530. fi
  531. }
  532. show_banner()
  533. {
  534. cat <<EOF
  535. __________ ___ __________ _______________
  536. / ____/ __ \/ | / ___/ ___/ / ____/ _/ ___/
  537. / / __/ /_/ / /| | \__ \\\\_ \\ / / __ / / \\__ \\
  538. / /_/ / _, _/ ___ |___/ /__/ / / /_/ // / ___/ /
  539. \____/_/ |_/_/ |_/____/____/ \____/___//____/
  540. EOF
  541. }
  542. say_hello()
  543. {
  544. if [ -f "$GISBASE/locale/$LCL/etc/welcome" ] ; then
  545. cat "$GISBASE/locale/$LCL/etc/welcome"
  546. else
  547. cat "$ETC/welcome"
  548. fi
  549. }
  550. show_info()
  551. {
  552. cat <<-EOF
  553. GRASS homepage: http://grass.osgeo.org/
  554. This version running through: $shellname ($SHELL)
  555. Help is available with the command: g.manual -i
  556. See the licence terms with: g.version -c
  557. EOF
  558. case "$GRASS_GUI" in
  559. wxpython)
  560. echo "If required, restart the GUI with: g.gui wxpython"
  561. ;;
  562. *)
  563. echo "Start the GUI with: g.gui $DEFAULT_GUI"
  564. ;;
  565. esac
  566. echo "When ready to quit enter: exit"
  567. echo
  568. }
  569. csh_startup()
  570. {
  571. USERHOME="$HOME" # save original home
  572. HOME="$LOCATION"
  573. export HOME
  574. cshrc="$HOME/.cshrc"
  575. tcshrc="$HOME/.tcshrc"
  576. rm -f "$cshrc" "$tcshrc"
  577. echo "set home = $USERHOME" > "$cshrc"
  578. echo "set history = 3000 savehist = 3000 noclobber ignoreeof" >> "$cshrc"
  579. echo "set histfile = $HOME/.history" >> "$cshrc"
  580. echo "set prompt = '\\" >> "$cshrc"
  581. echo "Mapset <${MAPSET}> in Location <${LOCATION_NAME}> \\" >> "$cshrc"
  582. echo "GRASS $GRASS_VERSION > '" >> "$cshrc"
  583. echo 'set BOGUS=``;unset BOGUS' >> "$cshrc"
  584. if [ -r "$USERHOME/.grass.cshrc" ]
  585. then
  586. cat "$USERHOME/.grass.cshrc" >> "$cshrc"
  587. fi
  588. if [ -r "$USERHOME/.cshrc" ]
  589. then
  590. grep '^ *set *mail *= *' "$USERHOME/.cshrc" >> "$cshrc"
  591. fi
  592. if [ -r "$USERHOME/.tcshrc" ]
  593. then
  594. grep '^ *set *mail *= *' "$USERHOME/.tcshrc" >> "$cshrc"
  595. fi
  596. if [ -r "$USERHOME/.login" ]
  597. then
  598. grep '^ *set *mail *= *' "$USERHOME/.login" >> "$cshrc"
  599. fi
  600. echo "set path = ( $PATH ) " | sed 's/:/ /g' >> "$cshrc"
  601. cp "$cshrc" "$tcshrc"
  602. "$ETC/run" "$SHELL"
  603. EXIT_VAL=$?
  604. HOME="$USERHOME"
  605. export HOME
  606. }
  607. bash_startup()
  608. {
  609. # save command history in mapset dir and remember more
  610. export HISTFILE="$LOCATION/.bash_history"
  611. if [ -z "$HISTSIZE" ] && [ -z "$HISTFILESIZE" ] ; then
  612. export HISTSIZE=3000
  613. fi
  614. # instead of changing $HOME, start bash with: --rcfile "$LOCATION/.bashrc" ?
  615. # if so, must care be taken to explicity call .grass.bashrc et al for
  616. # non-interactive bash batch jobs?
  617. USERHOME="$HOME" # save original home
  618. HOME="$LOCATION" # save .bashrc in $LOCATION
  619. export HOME
  620. bashrc="$HOME/.bashrc"
  621. rm -f "$bashrc"
  622. echo "test -r ~/.alias && . ~/.alias" >> "$bashrc"
  623. echo "PS1='GRASS $GRASS_VERSION ($LOCATION_NAME):\w > '" >> "$bashrc"
  624. echo "PROMPT_COMMAND=$GISBASE/etc/prompt.sh" >> "$bashrc"
  625. if [ -r "$USERHOME/.grass.bashrc" ]
  626. then
  627. cat "$USERHOME/.grass.bashrc" >> "$bashrc"
  628. fi
  629. echo "export PATH=\"$PATH\"" >> "$bashrc"
  630. echo "export HOME=\"$USERHOME\"" >> "$bashrc" # restore user home path
  631. "$ETC/run" "$SHELL"
  632. EXIT_VAL=$?
  633. HOME="$USERHOME"
  634. export HOME
  635. }
  636. default_startup()
  637. {
  638. PS1="GRASS $GRASS_VERSION ($LOCATION_NAME):\w > "
  639. export PS1
  640. if [ "$MINGW" ] ; then
  641. # "$ETC/run" doesn't work at all???
  642. "$SHELL"
  643. rm -rf "$LOCATION/.tmp"/* # remove GUI session files from .tmp
  644. else
  645. "$ETC/run" "$SHELL"
  646. EXIT_VAL=$?
  647. fi
  648. }
  649. done_message()
  650. {
  651. if [ -x "$GRASS_BATCH_JOB" ] ; then
  652. echo "Batch job '$GRASS_BATCH_JOB' (defined in GRASS_BATCH_JOB variable) was executed."
  653. echo "Goodbye from GRASS GIS"
  654. exit $EXIT_VAL
  655. else
  656. echo "Done."
  657. echo
  658. echo "Goodbye from GRASS GIS"
  659. echo
  660. fi
  661. }
  662. clean_temp()
  663. {
  664. echo "Cleaning up temporary files ..."
  665. "$ETC/clean_temp" > /dev/null
  666. }