functions.sh 19 KB

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