functions.sh 19 KB

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