[GRASS-dev] [GRASS GIS] #2572: grass command welcomes batch job and requires user input

#2572: grass command welcomes batch job and requires user input
--------------------------------------------+-------------------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: minor | Milestone: 6.4.5
Component: Startup | Version: 6.4.4
Keywords: GRASS_BATCH_JOB, rc file, init | Platform: Linux
      Cpu: Unspecified |
--------------------------------------------+-------------------------------
When calling GRASS GIS to do a batch job without having rc file created,
one gets:

{{{
WELCOME TO GRASS Version 6.4.4 2014
...
       - Current catalog of available computer maps
...
Hit RETURN to continue
}}}

This warm welcome is intended for user but when a GRASS_BATCH_JOB is set,
this should not be executed because there is usually nobody to hit RETURN
since the process is executed from some program.

Test setup:

{{{
cat > test_script.sh <<EOF
echo "Hello from GRASS GIS" > test_file.txt
date >> test_file.txt
EOF
}}}

{{{
export GRASS_BATCH_JOB=$PWD/test_script.sh
}}}

Test:

{{{
rm ~/.grassrc6
grass64 ~/grassdata/nc_spm_08_grass7_tests/user1
}}}

Here is a patch which works for me for version 6.4:

{{{
#!diff
Index: lib/init/init.sh

--- lib/init/init.sh (revision 64329)
+++ lib/init/init.sh (working copy)
@@ -421,7 +421,7 @@
  fi

  # First time user - GISRC is defined in the GRASS script
-if [ ! -f "$GISRC" ] ; then
+if [ ! -f "$GISRC" -a ! -n "$GRASS_BATCH_JOB" ] ; then

      if [ ! -f "$GISBASE/locale/$LCL/etc/grass_intro" ] ; then
         cat "$ETC/grass_intro"
}}}

I'm not sure if it is correctly implemented because it causes that the rc
file (`~/.grassrc6`) is not created (using the `$HOME` and `<UNKNOWN>`).
It does not seem useful anyway but I guess that there is some reason for
it.

Basically the same patch can be applied to version 7. Check
`GRASS_BATCH_JOB` (`batch_job`) before calling `grass_intro()`. I'm just
don't have the full understanding of the code, for example I'm not sure
how rc file is supposed to be handled with `GRASS_BATCH_JOB`
(source:grass/trunk/lib/init/grass.py?rev=64377#L1339).

A workaround for version 6.4 is to create a `.grassrc6` file in directory
specified by `$HOME` with some reasonable content (e.g. a copy of existing
`.grassrc6` from different user).

Related:
  * https://hub.qgis.org/issues/5644
  * http://osgeo-org.1560.x6.nabble.com/grass-shell-td3901230.html

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2572&gt;
GRASS GIS <http://grass.osgeo.org>

#2572: grass command welcomes batch job and requires user input
-----------------------------------------------------+----------------------
Reporter: wenzeslaus | Owner: grass-dev@…
     Type: defect | Status: new
Priority: minor | Milestone: 6.4.5
Component: Startup | Version: 6.4.4
Keywords: GRASS_BATCH_JOB, rc file, init, startup | Platform: Linux
      Cpu: Unspecified |
-----------------------------------------------------+----------------------
Changes (by wenzeslaus):

  * keywords: GRASS_BATCH_JOB, rc file, init => GRASS_BATCH_JOB, rc file,
               init, startup

Comment:

Fixed in r64438 for 6.4 and in r64408 for trunk.

r64438 uses does not show the message and does not require the input when
`GRASS_BATCH_JOB` is defined but still
[source:grass/branches/releasebranch_6_4/lib/init/init.sh?rev=64438#L437
creates the rc file]. r64408 removes the message and the request of input
altogether and leaves just the
[source:grass/trunk/lib/init/grass.py?rev=64408#L502 creation of the rc
file].

r64438 can be tested and was tested using the steps described earlier (and
by standard start of GRASS after `rm ~/.grassrc6`). Note that to test
r64408 for version 7, you have to delete (or rename) file `~/.grass7/rc`.

r64408 should be safe enough to be backported any time to release branch
but the right time is after RC2 considering the freeze.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2572#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#2572: grass command welcomes batch job and requires user input
-------------------------+--------------------------------------------------
  Reporter: wenzeslaus | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: minor | Milestone: 6.4.5
Component: Startup | Version: 6.4.4
Resolution: fixed | Keywords: GRASS_BATCH_JOB, rc file, init, startup
  Platform: Linux | Cpu: Unspecified
-------------------------+--------------------------------------------------
Changes (by wenzeslaus):

  * status: new => closed
  * resolution: => fixed

Comment:

Replying to [comment:1 wenzeslaus]:

> r64408 should be safe enough to be backported any time to release branch
but the right time is after RC2 considering the freeze.

Backported to 7.0 in r64569 after RC2 and after test on MS Windows (with
removed `GRASS7` in the `AppData` `Roaming` directory). I got to startup
window so easily that I had to start beta3 too see what I'm actually
testing.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/2572#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>