[PATCH 0/1] guix-install.sh: Add ability to run it non-interactively.

  • Done
  • quality assurance status badge
Details
5 participants
  • Danny Milosavljevic
  • Efraim Flashner
  • Maxim Cournoyer
  • Tobias Geerinckx-Rice
  • rsiddharth
Owner
unassigned
Submitted by
rsiddharth
Severity
normal
R
R
rsiddharth wrote on 24 Oct 2018 02:15
(address . guix-patches@gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181024001542.16368-1-s@ricketyspace.net
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.


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

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

--
2.19.1
R
R
rsiddharth wrote on 24 Oct 2018 02:21
[PATCH 1/1] guix-install.sh: Update welcome.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181024002114.46005-1-s@ricketyspace.net
* etc/guix-install.sh (welcome): Read exactly one character from input.
---
etc/guix-install.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Toggle diff (15 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index ca6874ba0..cf839c20e 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -398,7 +398,7 @@ This script installs GNU Guix on your system
https://www.gnu.org/software/guix/
EOF
echo -n "Press return to continue..."
- read -r ANSWER
+ read -N 1 -r ANSWER
}
main()
--
2.19.1
E
E
Efraim Flashner wrote on 24 Oct 2018 13:54
Re: [bug#33134] [PATCH 0/1] guix-install.sh: Add ability to run it non-interactively.
(name . rsiddharth)(address . s@ricketyspace.net)(address . 33134@debbugs.gnu.org)
20181024115443.GA1297@macbook41
On Tue, Oct 23, 2018 at 08:15:42PM -0400, rsiddharth wrote:
Toggle quote (12 lines)
> 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

--
Efraim Flashner <efraim@flashner.co.il> ????? ?????
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAlvQXYAACgkQQarn3Mo9
g1ERpQ/9F2wjf/L5rHYeLBqQi/nvnAM1tgDavb4zCtx4yMbiZ4yVrx9LLaBf+qaL
lsgG26Dx/DA5BXfTyYibLXpIEIVD71lb2E7H+ElUnhO/YQ+99qerjlZPCPZbkMpZ
kLzwfO4Ydf5e+5m2kltO/VZ2+AHh8VG2nU+57zNUPPqaiNk2KNzVx2g4NdX+U1k3
9Zf74EvkwwV6Nby7pXfTMbT57184gJ5QYOSlaA+WNn94FTYTNBlklJrBqclQugLE
Wir8uhw/OXaAFuIZAidRPVSByvHT6QxN0qLmpfon3d8CO+3wgHpRINRF3TltkC0/
H2NRy1lI2TGJ2ViPdKH2KKGo6q+FehXYHgNMMpAntyH3hWuIPn6aTy9j/wKONYPg
k8DqpLIIrOg7jBgHIs0nbLr/hpIDZhKGpdy4l3Fj5qVCHpPp+Xne9Z2IeY4H6fkn
V5vrUT1XELRsDRyyBadMypnOuWhtsw/Q9w2xCVjSOfg2iOoAU3YhGr4DsBARvoXd
AUEFPmnvwPmMUYfv0L5Vvc6uaQqRc+gmbmC8F+zZNyk6JSo4CVLa6KAYsNCeHs3b
ZH9DtytzgVBH3ZdZOBsHiGPSL3yxUVj/FX9yJA9XD4nqUWMhUvtUQTpnq8fEuXbm
3inHG9hyB2Vtp8fWNgk3vMMa2BGjS7mw8OaUAL7LMqaeQBaGMTs=
=5/YS
-----END PGP SIGNATURE-----


T
T
Tobias Geerinckx-Rice wrote on 24 Oct 2018 15:24
(name . Efraim Flashner)(address . efraim@flashner.co.il)
87k1m7scjw.fsf@tobias.gr
rsiddharth, Efraim,

Efraim Flashner wrote:
Toggle quote (19 lines)
> 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
E
E
Efraim Flashner wrote on 24 Oct 2018 15:27
(name . Tobias Geerinckx-Rice)(address . me@tobias.gr)
20181024132751.GC1297@macbook41
On Wed, Oct 24, 2018 at 03:24:03PM +0200, Tobias Geerinckx-Rice wrote:
Toggle quote (34 lines)
> 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!"

Toggle quote (9 lines)
>
> 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'.

--
Efraim Flashner <efraim@flashner.co.il> ????? ?????
GPG key = A28B F40C 3E55 1372 662D 14F7 41AA E7DC CA3D 8351
Confidentiality cannot be guaranteed on emails sent or received unencrypted
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEEoov0DD5VE3JmLRT3Qarn3Mo9g1EFAlvQc1MACgkQQarn3Mo9
g1EhyA//WETs1uCC/xD2OZT4UvT54r6VEVCQ6hoL49WJdyUHDOD1Euuy5ndUFATV
9NQGIpvDCF3+Bt7rYznaIeIdng9MjQKqzDEo4fNMGxsR5qSP3nPgvYDoCKgsfGGd
MGCdcECWtCs+i11sXTzE6u/Dl+h8h2tP+t7f3RyFTVR0/u/VhABTvKpYLwcnqeWs
C1qygFl0JcCUgK7roKGpT5/a8f8eZKSUOpDTjmgNOIHyYc+mw5fL5iE7OVJTncin
Z+RZ4mB+M/mnsZHUdkaVet/L6KlfBTXb8OvJXhyiryRArFJ1pyqC6edpBBDR13Pi
SlEkUQOa5ZV0Si80N4e1DKiP3Mx60SJjMWA9RfDxH1aKa9uQyvFmSUSwSS3ixkyT
5ZDTFqHNUqeDc07jwKulgeyuZmshN7WE0XPjVgm4PlhilGlpTsTc6jd0oJbE1abj
YgJe166LXOsYIuGIUrh+w1XqSp0PutX9zoFGHIXMi+ZeAd4SoOGmmx16zEvVwkUq
1gklV8PCHHzVnbrGTlL8IqwjekexlBbMkXaJ+ga3YqDQjGZxLodJTFyarmusicoI
prsWpHyRLa2h6iS4RKWJ91OyjWDRj+DAJshqUVX2lWs2HGNEycsAQDastXoxe1Rs
GwcHD2joaGcQVbkc3Ljt1fLLlX/tMpxQAk1pZQIb9Dzb+8fcRVo=
=60Fz
-----END PGP SIGNATURE-----


R
R
rsiddharth wrote on 3 Nov 2018 02:10
[PATCH 0/5] Add auto yes/no switch to guix-install.sh
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181103011019.87844-1-s@ricketyspace.net
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(-)

--
2.19.1
R
R
rsiddharth wrote on 3 Nov 2018 02:10
[PATCH 1/5] guix-install.sh: Update welcome.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181103011034.70086-1-s@ricketyspace.net
* etc/guix-install.sh (welcome): Read exactly one character from input.
---
etc/guix-install.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Toggle diff (15 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index ca6874ba0..cf839c20e 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -398,7 +398,7 @@ This script installs GNU Guix on your system
https://www.gnu.org/software/guix/
EOF
echo -n "Press return to continue..."
- read -r ANSWER
+ read -N 1 -r ANSWER
}
main()
--
2.19.1
R
R
rsiddharth wrote on 3 Nov 2018 02:10
[PATCH 2/5] guix-install.sh: Add parse_args.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181103011048.73864-1-s@ricketyspace.net
* etc/guix-install.sh (parse_args): New function.
---
etc/guix-install.sh | 15 +++++++++++++++
1 file changed, 15 insertions(+)

Toggle diff (28 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index cf839c20e..d16f8ac59 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -370,6 +370,21 @@ sys_authorize_build_farms()
done
}
+parse_args()
+{
+ local args_num=$#
+
+ if [ $args_num -lt 1 ]; then
+ return
+ fi
+
+ # process -y / -n arg.
+ export AUTO_YN=${1:1:1}
+ if [ -z $AUTO_YN ]; then
+ export AUTO_YN=""
+ fi
+}
+
welcome()
{
cat<<"EOF"
--
2.19.1
R
R
rsiddharth wrote on 3 Nov 2018 02:10
[PATCH 3/5] guix-install.sh: Update main.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181103011057.39591-1-s@ricketyspace.net
* etc/guix-install.sh (main): Call parse_args.
---
etc/guix-install.sh | 2 ++
1 file changed, 2 insertions(+)

Toggle diff (15 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index d16f8ac59..c817b6dd8 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -418,6 +418,8 @@ EOF
main()
{
+ parse_args $@
+
local tmp_path
welcome
--
2.19.1
R
R
rsiddharth wrote on 3 Nov 2018 02:11
[PATCH 4/5] guix-install.sh: Update welcome.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181103011120.27789-1-s@ricketyspace.net
* etc/guix-install.sh (welcome): Don't prompt if AUTO_YN is set.
---
etc/guix-install.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Toggle diff (15 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index c817b6dd8..9bf52db41 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -413,7 +413,7 @@ This script installs GNU Guix on your system
https://www.gnu.org/software/guix/
EOF
echo -n "Press return to continue..."
- read -N 1 -r ANSWER
+ [[ -n $AUTO_YN ]] || read -N 1 -r ANSWER
}
main()
--
2.19.1
R
R
rsiddharth wrote on 3 Nov 2018 02:11
[PATCH 5/5] guix-install.sh: Update sys_authorize_build_farms.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181103011138.66825-1-s@ricketyspace.net
* etc/guix-install.sh (sys_authorize_build_farms): Don't prompt
if AUTO_YN is set.
---
etc/guix-install.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

Toggle diff (28 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 9bf52db41..18adc17a2 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -355,8 +355,11 @@ sys_enable_guix_daemon()
sys_authorize_build_farms()
{ # authorize the public keys of the two build farms
+ local yn=$AUTO_YN
+
while true; do
- read -p "Permit downloading pre-built package binaries from the project's build farms? (yes/no) " yn
+ [[ -n $yn ]] || read -p "Permit downloading pre-built package binaries from the project's build farms? (yes/no) " yn
+
case $yn in
[Yy]*) guix archive --authorize < "${ROOT_HOME}/.guix-profile/share/guix/hydra.gnu.org.pub" &&
_msg "${PAS}Authorized public key for hydra.gnu.org";
@@ -365,7 +368,7 @@ sys_authorize_build_farms()
break;;
[Nn]*) _msg "${INF}Skipped authorizing build farm public keys"
break;;
- *) _msg "Please answer yes or no.";
+ *) _msg "Please answer yes or no."; yn=""
esac
done
}
--
2.19.1
D
D
Danny Milosavljevic wrote on 6 Nov 2018 12:27
Re: [bug#33134] [PATCH 2/5] guix-install.sh: Add parse_args.
(name . rsiddharth)(address . s@ricketyspace.net)(address . 33134@debbugs.gnu.org)
20181106122752.49e1b484@scratchpost.org
Hi,

Toggle quote (6 lines)
> + # 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.

If we wanted to export it, we could do it explicitly after parse_args has
been called.
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlvhergACgkQ5xo1VCww
uqUMDQgAid1V29fSxjaopH8+CyOwBheq0XEJzqk0HAhVMg7gvky7fCkeet0DX3BX
COHyxsbauEdoRNzsfW7omBBpEZw0gejrqYhMLlnfcxFZX+1WJQNfDh4PzFepbxpn
faBWF6mCz66cdwDivdE0zNmeJWjJ7bRP+B4NzjaD7cAaiilLKE9MJcHEajTEXxs2
8eKrC1LYUzO6e/QmM0K7UuS1oCzAgzkNcmQ0ZIOF0LDWZHwuDznbbvU+5tHaEwrN
WGFyZvockvzoSqAVOZeE0RqaPtgqJ4ztCw7gIc35PhuiLIHSTh8FZBnZ56IozkFj
9FEL4LVi709SQ3cDO9zklt7YECe2pA==
=7Yav
-----END PGP SIGNATURE-----


D
D
Danny Milosavljevic wrote on 6 Nov 2018 12:28
Re: [bug#33134] [PATCH 3/5] guix-install.sh: Update main.
(name . rsiddharth)(address . s@ricketyspace.net)(address . 33134@debbugs.gnu.org)
20181106122829.5caa1a77@scratchpost.org
On Fri, 2 Nov 2018 21:10:57 -0400
rsiddharth <s@ricketyspace.net> wrote:

Toggle quote (16 lines)
> * etc/guix-install.sh (main): Call parse_args.
> ---
> etc/guix-install.sh | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/etc/guix-install.sh b/etc/guix-install.sh
> index d16f8ac59..c817b6dd8 100755
> --- a/etc/guix-install.sh
> +++ b/etc/guix-install.sh
> @@ -418,6 +418,8 @@ EOF
>
> main()
> {
> + parse_args $@
> +

Should be

"$@"

with quotes
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlvhet0ACgkQ5xo1VCww
uqXu4ggAj74PEW6NtXCCy7qIlO4sR8zXtp9YuVIiXN3QyTccPK3huPerZX9xOYyR
h+GG8tM/lx6DhK6ov8WnLmW5NoovFP8Dh0CoK8ZsuZVNax/A/IwRN9lCijxQw+fL
3zSvJ691l6kr0QI3RykkmdSlrQ18YJK5E7qWpOi4s37pgkUVh2vYYqWikHh42JuV
6FgD6yibNXebT5g1DpBmzuWIHJ5blfyaPRjFdIsLfUC2ucXkgxDhjH5H0gk7Z2Vy
mcQx8d7JJeF5W52QA3k33jhmiSnvID1Sb8v0cUjtPEmUZDlX/YCjNxuiiYXUIgdU
Pf5v+crEHtaLVzhhepBW6EOiVVsc6Q==
=adxx
-----END PGP SIGNATURE-----


D
D
Danny Milosavljevic wrote on 6 Nov 2018 12:31
Re: [bug#33134] [PATCH 5/5] guix-install.sh: Update sys_authorize_build_farms.
(name . rsiddharth)(address . s@ricketyspace.net)(address . 33134@debbugs.gnu.org)
20181106123108.11c0c8ab@scratchpost.org
Hi,

On Fri, 2 Nov 2018 21:11:38 -0400
rsiddharth <s@ricketyspace.net> wrote:

Toggle quote (3 lines)
> - *) _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?
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlvhe3wACgkQ5xo1VCww
uqVrbwgAhtKSatqs5hgPH96KKUGTbiR/2qB4iD2RaBRMMDm23lxiCkiAHRBd2lne
UY+Px76FQdi4ivfx3kxSJcz0/rlbWCXLblgAVgMtAnygTUv9SxbpgJ/lqvqMLuS7
PJCE2JKcgV7mU8ClaYrhnRX1WHTvTsPjhP2Nl7A8Cg9ZBYAnwmZeVa864HVoeYuG
ATCy1kr90rg+xXQFerx4XUm6486jcCv1IgqhCS2YNh3M7V0ryockdvRD9WWf74Zl
UH8MmQeqYfOLS7CU6QlaeZqqJaMaXMCmPyMN9HRM5UY1m6jZiLEOl3gy5FkbNlzy
ndCMRxU+gkZPiUemyxcW3Yo6R5feng==
=wCP7
-----END PGP SIGNATURE-----


D
D
Danny Milosavljevic wrote on 6 Nov 2018 12:32
Re: [bug#33134] [PATCH 1/5] guix-install.sh: Update welcome.
(name . rsiddharth)(address . s@ricketyspace.net)(address . 33134@debbugs.gnu.org)
20181106123232.22408e9b@scratchpost.org
On Fri, 2 Nov 2018 21:10:34 -0400
rsiddharth <s@ricketyspace.net> wrote:

Toggle quote (16 lines)
> * etc/guix-install.sh (welcome): Read exactly one character from input.
> ---
> etc/guix-install.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/etc/guix-install.sh b/etc/guix-install.sh
> index ca6874ba0..cf839c20e 100755
> --- a/etc/guix-install.sh
> +++ b/etc/guix-install.sh
> @@ -398,7 +398,7 @@ This script installs GNU Guix on your system
> 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?
-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEEds7GsXJ0tGXALbPZ5xo1VCwwuqUFAlvhe9AACgkQ5xo1VCww
uqUlEwf7Bh3xH8CCksNYsisj/RijvmYVfm6WprbIuBUWctJzOYyW4cvHg+QBjKWQ
6a3NDhv9lanxVFnSmfOWF+mRfT0FQzNl1LaEhMSyu5aeQuLs6Ikl7uPvk5Mgr890
Q/5SSA7Io+4zZNt4KWs8Vdg69bkJAqt/mXRiW7oK+u3UefVeTHHvEZ8aOKh+UFh9
C0JDhQl+JbrwHCWujccM75gRl3NEH9FDqlCVlnmxDCJLf+utvga/K4DXLIsl2UE2
wvTco8Z0g2vRjKx/Eb5WioUIZTJsEEy/n53AOC8XXG3zUOb6VXzhctK6WEc27CAv
lb1jOYVpDLi9rWy4X60q+8BsA5UpsA==
=doGH
-----END PGP SIGNATURE-----


R
R
rsiddharth wrote on 9 Nov 2018 05:13
[PATCH 0/4] [Refactor 0] Add auto yes/no switch to guix-install.sh
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181109041301.39042-1-s@ricketyspace.net
Thanks Danny, I've refactored the patch based on your feedack.

Danny Milosavljevic wrote:

Toggle quote (9 lines)
>> + # 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`.

Toggle quote (13 lines)
>> ...
>>
>> main()
>> {
>> + parse_args $@
>> +

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

Done.

Toggle quote (14 lines)
>> ...
>> ...
>> 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.


Toggle quote (5 lines)
>> - *) _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(-)

--
2.19.1
R
R
rsiddharth wrote on 9 Nov 2018 05:14
[PATCH 1/4] guix-install.sh: Add parse_args.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181109041437.45557-1-s@ricketyspace.net
* etc/guix-install.sh (parse_args): New function.
---
etc/guix-install.sh | 15 +++++++++++++++
1 file changed, 15 insertions(+)

Toggle diff (28 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index ca6874ba0..3191d1be9 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -370,6 +370,21 @@ sys_authorize_build_farms()
done
}
+parse_args()
+{
+ local args_num=$#
+
+ if [ $args_num -lt 1 ]; then
+ return
+ fi
+
+ # process -y / -n arg.
+ AUTO_YN=${1:1:1}
+ if [ -z $AUTO_YN ]; then
+ AUTO_YN=""
+ fi
+}
+
welcome()
{
cat<<"EOF"
--
2.19.1
R
R
rsiddharth wrote on 9 Nov 2018 05:15
[PATCH 2/4] guix-install.sh: Update main.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181109041507.17846-1-s@ricketyspace.net
* etc/guix-install.sh (main): Call parse_args.
---
etc/guix-install.sh | 2 ++
1 file changed, 2 insertions(+)

Toggle diff (15 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 3191d1be9..23c5f5da2 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -418,6 +418,8 @@ EOF
main()
{
+ parse_args "$@"
+
local tmp_path
welcome
--
2.19.1
R
R
rsiddharth wrote on 9 Nov 2018 05:15
[PATCH 3/4] guix-install.sh: Update welcome.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181109041519.31283-1-s@ricketyspace.net
* etc/guix-install.sh (welcome): Don't prompt if AUTO_YN is set.
---
etc/guix-install.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Toggle diff (15 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 23c5f5da2..16686ff89 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -413,7 +413,7 @@ This script installs GNU Guix on your system
https://www.gnu.org/software/guix/
EOF
echo -n "Press return to continue..."
- read -r ANSWER
+ [[ -n $AUTO_YN ]] || read -r ANSWER
}
main()
--
2.19.1
R
R
rsiddharth wrote on 9 Nov 2018 05:15
[PATCH 4/4] guix-install.sh: Update sys_authorize_build_farms.
(address . 33134@debbugs.gnu.org)(name . rsiddharth)(address . s@ricketyspace.net)
20181109041534.4489-1-s@ricketyspace.net
* etc/guix-install.sh (sys_authorize_build_farms): Don't prompt
if AUTO_YN is set.
---
etc/guix-install.sh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

Toggle diff (28 lines)
diff --git a/etc/guix-install.sh b/etc/guix-install.sh
index 16686ff89..cbcf5316d 100755
--- a/etc/guix-install.sh
+++ b/etc/guix-install.sh
@@ -355,8 +355,11 @@ sys_enable_guix_daemon()
sys_authorize_build_farms()
{ # authorize the public keys of the two build farms
+ local yn=$AUTO_YN
+
while true; do
- read -p "Permit downloading pre-built package binaries from the project's build farms? (yes/no) " yn
+ [[ -n $yn ]] || read -p "Permit downloading pre-built package binaries from the project's build farms? (yes/no) " yn
+
case $yn in
[Yy]*) guix archive --authorize < "${ROOT_HOME}/.guix-profile/share/guix/hydra.gnu.org.pub" &&
_msg "${PAS}Authorized public key for hydra.gnu.org";
@@ -365,7 +368,7 @@ sys_authorize_build_farms()
break;;
[Nn]*) _msg "${INF}Skipped authorizing build farm public keys"
break;;
- *) _msg "Please answer yes or no.";
+ *) _msg "Please answer yes or no."; yn=""
esac
done
}
--
2.19.1
M
M
Maxim Cournoyer wrote on 13 Jul 2021 14:01
Re: bug#33134: [PATCH 0/1] guix-install.sh: Add ability to run it non-interactively.
(name . rsiddharth)(address . s@ricketyspace.net)(address . 33134-done@debbugs.gnu.org)
874kcytoax.fsf@gmail.com
Hello,

rsiddharth <s@ricketyspace.net> writes:

Toggle quote (19 lines)
> 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(-)

The guix-install.sh saw some imrovements in v1.3.0 that makes it support
the non-interactive 'yes | sudo ./guix-install.sh' use case. I think it
obsoletes this patch.

Closing, but feel free to send a new patch series if I missed anything.

Thank you,

Maxim
Closed
?