BTS

Issue1279

Title check4progs() does not work correctly with more then one argument
Priority wish Status resolved
Superseder Nosy List Xk2c, ft
Assigned To ft Topics

Created on 2013-09-30.08:29:39 by Xk2c, last changed 2013-11-07.09:15:33 by mika.

Files
File name Uploaded Type Edit Remove
check4progs.mod Xk2c, 2013-09-30.10:11:18 audio/x-mod
check4progs.mod Xk2c, 2013-11-06.17:31:54 audio/x-mod
Messages
msg4668 (view) Author: mika Date: 2013-11-07.09:15:33
We believe that your issue has been closed by the upload of
Version 0.9.1 of grml-etc-core from Michael Prokop <mika@grml.org>.
The explanation is attached below

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Format: 1.8
Date: Thu, 07 Nov 2013 09:54:32 +0100
Source: grml-etc-core
Binary: grml-etc-core
Architecture: source all
Version: 0.9.1
Distribution: grml-testing
Urgency: low
Maintainer: Michael Prokop <mika@grml.org>
Changed-By: Michael Prokop <mika@grml.org>
Description: 
 grml-etc-core - core etcetera files for the grml system
Changes: 
 grml-etc-core (0.9.1) grml-testing; urgency=low
 .
   [ Michael Prokop ]
   * [931ce01] Use ISO8601 date in /etc/grml/screenrc [Closes: issue1283]
     Thanks to Andras Korn for the suggestion
 .
   [ Thilo Six ]
   * [3d5b16f] Rewrite check4progs from etc/grml/script-functions
     [Closes: issue1279]
Checksums-Sha1: 
 96028832f81c456b62342ed248110d9465821e9a 945 grml-etc-core_0.9.1.dsc
 ff77473c0ebeb5de9b60910b3a1fb2dc665aa9dd 150302 grml-etc-core_0.9.1.tar.gz
 578d0e4d3e65ee77b705437c14d75100495144ee 137926 grml-etc-core_0.9.1_all.deb
Checksums-Sha256: 
 ff39b9deb95338b1a1456897344bf9bec232f183223dba968817e6662ee75f1e 945 grml-etc-core_0.9.1.dsc
 4383cf60c4de7512967ffa45b52cc83aa0f6fb52ee4bb010923b406d92656dd8 150302 grml-etc-core_0.9.1.tar.gz
 45c3980e83b4b5b1842ce0f417310f3931eb895c6a268c0de5c351dbd487ba8b 137926 grml-etc-core_0.9.1_all.deb
Files: 
 9856a52b4c97d09071df656d8d29b890 945 grml optional grml-etc-core_0.9.1.dsc
 df96e5fa22706d81875b20c022a84bf4 150302 grml optional grml-etc-core_0.9.1.tar.gz
 52c58978caf99d95b8b459a2046e130a 137926 grml optional grml-etc-core_0.9.1_all.deb

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlJ7VtoACgkQ2N9T+zficujpWACePcWf9EtV81WUfZ4kGjvqi9Le
UrEAoIPsulgqJT5r58gIn6eFtoYysvjC
=LXZI
-----END PGP SIGNATURE-----
msg4666 (view) Author: ft Date: 2013-11-07.08:57:05
Thanks, I've committed that last version. It's certainly an improvement. ;)

The only thing you could have done better, was to send a patch with commit
message generated by "git format-patch". That way I could have applied this
using one command.

Yes, I'm lazy. ;)

Thanks again!
msg4665 (view) Author: Xk2c Date: 2013-11-06.17:31:54
Hello Frank,


Excerpt from Frank Terbeck:

-- <snip> --

> Attached is the bash version of check4progs() which i used now for quite some
> time. dash knows "shift", so i imagine zsh will do, too.

I just noticed this can even be more simplified. attached.

> 
> 
>> 
>> Regards, Frank



-- 
$ \grep -Thilo '[a-zA-Z0-9._-]\+()' ~/.bashrc
msg4664 (view) Author: Xk2c Date: 2013-11-06.17:20:34
Hello Frank,


Excerpt from Frank Terbeck:

-- <snip> --
>> +    \which "$arg" >/dev/null 2>&1 || RC="$arg"
> 
> I'm unsure about the portability of "\which". Maybe better
> 
>   builtin which "$arg" ...

It seems 'which' is only in zsh a builtin:

$ which which
which is aliased to `builtin type -all'
which is /usr/bin/which
which is /bin/which

Not sure if that is important for grml in regard to portability.

>> +    if [ -n "$RC" ] ; then
>> +      echo "$RC not installed"
>> +      RC=''
> 
> I think we can do completely without this pesky "$RC" variable. How about:

-- <snip> --

> I don't think using return values up to 255 is too portable.
> IIRC, bash, dash and zsh use values up to 127 and use the stuff above
> to signal return from program by fatal SIGNAL.
> 
> So, I'd just return "1".

-- <snip> --

> Explicit "return" is also something that I like! :)
> 
> I think my remarks should work and improve portability. Please take them into
> consideration.  Other than that, thanks for taking in interest into grml!

Attached is the bash version of check4progs() which i used now for quite some
time. dash knows "shift", so i imagine zsh will do, too.


> 
> Regards, Frank
> 
> ----------
> nosy: +ft
> 
> _____________________________________
> GRML issue tracker <bts@bts.grml.org>
> <http://bts.grml.org/grml/issue1279>
> _____________________________________
> 



-- 
$ \grep -Thilo '[a-zA-Z0-9._-]\+()' ~/.bashrc
msg4663 (view) Author: ft Date: 2013-11-06.09:54:49
Hi there!

Here are some thoughts:

> diff --git a/etc/grml/script-functions b/etc/grml/script-functions
> index a39e3d8..b1de8d4 100644
> --- a/etc/grml/script-functions
> +++ b/etc/grml/script-functions
> @@ -50,13 +50,19 @@ setdialog(){
>  # {{{ check for availability of program(s)
>  check4progs(){
>    local RC=''
> -  for arg in $* ; do
> -    which $arg >/dev/null 2>&1 || RC="$arg"
> +  local RTN=0
> +  local arg=''
> +  for arg in "$@" ; do

Using "$@" here is the first improvement, that really wants me to take this
patch. It's just the right thing to to[tm].

> +    \which "$arg" >/dev/null 2>&1 || RC="$arg"

I'm unsure about the portability of "\which". Maybe better

  builtin which "$arg" ...

> +    if [ -n "$RC" ] ; then
> +      echo "$RC not installed"
> +      RC=''

I think we can do completely without this pesky "$RC" variable. How about:

    builtin which "$arg" 2>&1 > /dev/null || {
        echo "$arg not installed"

...not quite done, wait for it...

> +      if [ ${RTN} -lt 255 ]; then
> +          RTN=$(( ${RTN}+1 ))
> +      fi
> +    fi

I don't think using return values up to 255 is too portable.
IIRC, bash, dash and zsh use values up to 127 and use the stuff above
to signal return from program by fatal SIGNAL.

So, I'd just return "1".

...to continue the snippet I broke off earlier:

        RTN=1; }

>    done
> -  if [ -n "$RC" ] ; then
> -     echo "$RC not installed"
> -     return 1
> -  fi
> +  return ${RTN}
>  }

Explicit "return" is also something that I like! :)

I think my remarks should work and improve portability. Please take them into
consideration.  Other than that, thanks for taking in interest into grml!

Regards, Frank
msg4641 (view) Author: Xk2c Date: 2013-09-30.10:11:18
i changed the patch a little, to not pollute environment with variable $arg.
msg4640 (view) Author: Xk2c Date: 2013-09-30.08:29:39
Hello

when given more then one arguments to check4progs()
it will echo only the last missing program instead of all. example follows:

$ . ~/temp/check4progs.orig 
$ check4progs foo cp ln mv bar wc tr tee
bar not installed

patched version:
$ . ~/temp/check4progs.mod 
$ check4progs foo cp ln mv bar wc tr tee
foo not installed
bar not installed

Extra points: Exitstatus is the sum of all missing programs from argument list.

Please note this patch has been tested with bash!
I *think* it should work without modification in zsh, too.

Regards,
Thilo
History
Date User Action Args
2013-11-07 09:15:33mikasetstatus: fixed-in-git -> resolved
messages: + msg4668
2013-11-07 08:57:05ftsetstatus: chatting -> fixed-in-git
messages: + msg4666
2013-11-06 17:35:51Xk2csetfiles: - check4progs.mod
2013-11-06 17:31:54Xk2csetfiles: + check4progs.mod
messages: + msg4665
2013-11-06 17:20:35Xk2csetfiles: + check4progs.mod
messages: + msg4664
2013-11-06 10:17:58ftsetassignedto: ft
2013-11-06 09:54:49ftsetnosy: + ft
messages: + msg4663
2013-09-30 10:11:39Xk2csetfiles: - check4progs.mod
2013-09-30 10:11:18Xk2csetfiles: + check4progs.mod
status: unread -> chatting
messages: + msg4641
2013-09-30 08:32:19Xk2csettitle: check4progs() does not work correctlx with more then one argument -> check4progs() does not work correctly with more then one argument
2013-09-30 08:29:39Xk2ccreate