[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#952927: [live-build] inconsistency and unnecessary complexity in bin checking



On 2020-03-02 07:12, jnqnfe@gmail.com wrote:
Package: live-build
Version: 1:20191221
Owner: jnqnfe@gmail.com
Severity: minor

there are lots of checks being done that tools are available and
executable. this is done with a mixture of use of `which` and fixed
paths, redirection of output to /dev/null (`2>/dev/null`) and redundant
executability tetsing on top of `which` checks (which already does such
a check).

this can be tidied up and robustified.
  - we can move everything to `which` and drop fixed paths, thus
robustifying things should a bin every move (you never know).
  - we can drop performing pointless `-x` testig on top of `which` use,
since `which` already performs this and signals such in its exist code
(returns 1 if nonexistant or nonexecutable).
  - we can drop the `2>/dev/null` redirection which in my testing seemed
to make no difference.

proposal: switch to conditionals of the form:
```
if [ $(which dpkg) ]; then
     #whatever
fi
```

The use of 'which' is not universally regarded as robust: depending on the environment it can return true even if the executable does not exist, and may also output an error message, breaking the above test.

POSIX has 'command -v <command>' which should work under the #!/bin/sh shebang that live-build scripts use:
if command -v dpkg >/dev/null
then
    echo "we have dpkg"
fi

See: https://mywiki.wooledge.org/BashFAQ/081

--
John


Reply to: