[bug#33134,0/1] guix-install.sh: Add ability to run it non-interactively.

Message ID 20181024001542.16368-1-s@ricketyspace.net
Headers show
Series guix-install.sh: Add ability to run it non-interactively. | expand

Message

rsiddharth Oct. 24, 2018, 12:15 a.m. UTC
I want to be able to run the guix-install.sh non-interactively[1] like this:

   echo "yy" | guix-install.sh

   (One "y" for "Press return to continue..." prompt, the other "y" for
   "Permit downloading pre-built package binaries from the project's build
   farms? (yes/no)" prompt).

Currently, the `read` in welcome function reads both the "y". I updated it to
read just one character.

[1]: https://git.ricketyspace.net/propellor/tree/config.hs?id=0cddd47ef#n640

rsiddharth (1):
  guix-install.sh: Update welcome.

 etc/guix-install.sh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Efraim Flashner Oct. 24, 2018, 11:54 a.m. UTC | #1
On Tue, Oct 23, 2018 at 08:15:42PM -0400, rsiddharth wrote:
> I want to be able to run the guix-install.sh non-interactively[1] like this:
> 
>    echo "yy" | guix-install.sh
> 
>    (One "y" for "Press return to continue..." prompt, the other "y" for
>    "Permit downloading pre-built package binaries from the project's build
>    farms? (yes/no)" prompt).
> 
> Currently, the `read` in welcome function reads both the "y". I updated it to
> read just one character.
> 

would this work? echo "y\ny" | guix-install.sh
Tobias Geerinckx-Rice Oct. 24, 2018, 1:24 p.m. UTC | #2
rsiddharth, Efraim,

Efraim Flashner wrote:
> On Tue, Oct 23, 2018 at 08:15:42PM -0400, rsiddharth wrote:
>> I want to be able to run the guix-install.sh 
>> non-interactively[1] like this:
>> 
>>    echo "yy" | guix-install.sh
>> 
>>    (One "y" for "Press return to continue..." prompt, the other 
>>    "y" for
>>    "Permit downloading pre-built package binaries from the 
>>    project's build
>>    farms? (yes/no)" prompt).
>> 
>> Currently, the `read` in welcome function reads both the "y". I 
>> updated it to
>> read just one character.
>> 
>
> would this work? echo "y\ny" | guix-install.sh

Not quite, but

  $ echo -e "y\ny" | guix-install.sh

will. Or the more conventional

  $ yes | guix-install.sh # untested

providing guix-install.sh doesn't choke on that infinite stream of 
"y"s. Which it might, and even if it doesn't now, there's no 
guarantee that this dirty hack won't break the future.

If this is something we want to support, it could be done more 
better through a '--non-interactive' or '--force' flag that skips 
these and any future prompts at the source.

Non?

T G-R
Efraim Flashner Oct. 24, 2018, 1:27 p.m. UTC | #3
On Wed, Oct 24, 2018 at 03:24:03PM +0200, Tobias Geerinckx-Rice wrote:
> rsiddharth, Efraim,
> 
> Efraim Flashner wrote:
> > On Tue, Oct 23, 2018 at 08:15:42PM -0400, rsiddharth wrote:
> > > I want to be able to run the guix-install.sh non-interactively[1]
> > > like this:
> > > 
> > >    echo "yy" | guix-install.sh
> > > 
> > >    (One "y" for "Press return to continue..." prompt, the other
> > > "y" for
> > >    "Permit downloading pre-built package binaries from the
> > > project's build
> > >    farms? (yes/no)" prompt).
> > > 
> > > Currently, the `read` in welcome function reads both the "y". I
> > > updated it to
> > > read just one character.
> > > 
> > 
> > would this work? echo "y\ny" | guix-install.sh
> 
> Not quite, but
> 
>  $ echo -e "y\ny" | guix-install.sh
> 
> will. Or the more conventional
> 
>  $ yes | guix-install.sh # untested
> 
> providing guix-install.sh doesn't choke on that infinite stream of "y"s.
> Which it might, and even if it doesn't now, there's no guarantee that this
> dirty hack won't break the future.

This actually made me snort. "Alright! I get it! You really want it!"

> 
> If this is something we want to support, it could be done more better
> through a '--non-interactive' or '--force' flag that skips these and any
> future prompts at the source.
> 
> Non?
> 
> T G-R

This is actually something I was thinking of a while ago. I use github
as a mirror, and I definately wouldn't be against using their CI system
to install guix, 'guix pull', 'guix build -f guix.scm'.
rsiddharth Nov. 3, 2018, 1:10 a.m. UTC | #4
The following patch series adds "auto yes/no" switch to the guix-install.sh
script.

It works like this:

   guix-install.sh -y

   [ for non-interactively answering 'yes' to all y/n prompts ]

   guix-install.sh -n

   [ for non-interactively answering 'no' to all y/n prompts ]

   If either the -y or the -n switch is provided, the script will skip the
   "Press return to continue..." prompt.

I'm not a bash expert; if there is a better way to do this, let me know. I
would be happy to refactor and send a fresh patch series.

rsiddharth (5):
  guix-install.sh: Update welcome.
  guix-install.sh: Add parse_args.
  guix-install.sh: Update main.
  guix-install.sh: Update welcome.
  guix-install.sh: Update sys_authorize_build_farms.

 etc/guix-install.sh | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)
rsiddharth Nov. 9, 2018, 4:13 a.m. UTC | #5
Thanks Danny, I've refactored the patch based on your feedack.

Danny Milosavljevic wrote:

>> +    # process -y / -n arg.
>> +    export AUTO_YN=${1:1:1}
>> +    if [ -z $AUTO_YN ]; then
>> +        export AUTO_YN=""
>> +    fi

> Why "export" ? Now all the child processes get it, making their environment
> different from before.  This makes parse_args have system-wide side effects.

Remove the `export`.

>> ...
>>  
>>  main()
>>  {
>> +    parse_args $@
>> +

> Should be
>
>   "$@"
>
>with quotes

Done.

>> ...
>> ...
>>  https://www.gnu.org/software/guix/
>>  EOF
>>      echo -n "Press return to continue..."
>> -    read -r  ANSWER
>> +    read -N 1 -r  ANSWER

> While it's nice for the interactive user, doesn't this break
>
>  yes | ./guix-install.sh
>
> because now it doesn't wait for the newline?

Yes, it would break `yes | ./guix-install.sh`. I've removed `-N 1` from the `read` statement.


>> -            *) _msg "Please answer yes or no.";
>> +            *) _msg "Please answer yes or no."; yn=""

> Does this make it conditionally interactive?  Would it be better to "exit 1" here?

When the user is running the script interactively and answers, say "Oui", we
arrive at the:

                 *) _msg "Please answer yes or no.";

case. After this, we go to the beginning of the loop:

                 [[ -n $yn ]] || read -p "Permit downloading pre-built package binaries from the project's build farms? (yes/no) " yn

Since $yn is "Oui" `[[ -n $yn ]]` will evaluate to true, the user won't be
prompted again, we'll go back to:

                 *) _msg "Please answer yes or no."

and this will repeat infinitely.

The `yn=""` was added:

                 *) _msg "Please answer yes or no."; yn=""

to reset the value of yn, so that `[[ -n $yn ]]` will evaluate to false and
the user will be prompted again for answer.

rsiddharth (4):
  guix-install.sh: Add parse_args.
  guix-install.sh: Update main.
  guix-install.sh: Update welcome.
  guix-install.sh: Update sys_authorize_build_farms.

 etc/guix-install.sh | 26 +++++++++++++++++++++++---
 1 file changed, 23 insertions(+), 3 deletions(-)