functions.sh 19 KB

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