Replace 'which' with 'command -v' to test for the existance of an executable

This is considered to be more robust.

Two instances remain:

scripts/build/chroot_archives, line 257:
if [ "${LB_APT}" = "aptitude" ] && [ ! $(Chroot chroot "which aptitude") ]
The command is run inside a chroot where the environment might be special,
and would need further testing.

manpages/Makefile, line 42:
@if [ ! -x "$$(which po4a 2>/dev/null)" ]; \
I am insufficiently familiar with makefile syntax to edit this.
This commit is contained in:
johnraff 2020-05-01 11:23:39 +09:00 committed by Raphaël Hertzog
parent fd18d46e0e
commit 0e5d0483e5
13 changed files with 15 additions and 15 deletions

View File

@ -23,7 +23,7 @@
set -e
if [ $(which man) ]
if command -v man >/dev/null
then
man live-build
else

View File

@ -53,7 +53,7 @@ Check_architectures ()
Check_crossarchitectures ()
{
local HOST
if [ $(which dpkg) ]
if command -v dpkg >/dev/null
then
HOST="$(dpkg --print-architecture)"
else

View File

@ -36,7 +36,7 @@ Prepare_config ()
LB_SYSTEM="${LB_SYSTEM:-live}"
if [ $(which lsb_release) ]
if command -v lsb_release >/dev/null
then
local _DISTRIBUTOR
_DISTRIBUTOR="$(lsb_release -is | tr "[A-Z]" "[a-z]")"
@ -66,7 +66,7 @@ Prepare_config ()
LIVE_IMAGE_TYPE="${LB_IMAGE_TYPE}"
if [ -z "${LB_ARCHITECTURE}" ]; then
if [ $(which dpkg) ]; then
if command -v dpkg >/dev/null; then
LB_ARCHITECTURE="$(dpkg --print-architecture)"
else
case "$(uname -m)" in
@ -688,7 +688,7 @@ Validate_config_permitted_values ()
# Check option combinations and other extra stuff
Validate_config_dependencies ()
{
if [ "${LB_BINARY_FILESYSTEM}" = "ntfs" ] && [ ! $(which ntfs-3g) ]; then
if [ "${LB_BINARY_FILESYSTEM}" = "ntfs" ] && ! command -v ntfs-3g >/dev/null; then
Echo_error "Using ntfs as the binary filesystem is currently only supported if ntfs-3g is installed on the host system."
exit 1
fi

View File

@ -22,7 +22,7 @@ Lodetach ()
# Changes to block devices result in uevents which trigger rules which in
# turn access the loop device (ex. udisks-part-id, blkid) which can cause
# a race condition. We call 'udevadm settle' to help avoid this.
if [ $(which udevadm) ]
if command -v udevadm >/dev/null
then
udevadm settle
fi

View File

@ -13,7 +13,7 @@ Man ()
{
local BASENAME
BASENAME=$(basename ${0})
if [ $(which man) ]
if command -v man >/dev/null
then
case $BASENAME in
$PROGRAM)

View File

@ -82,7 +82,7 @@ Check_installed ()
INSTALL_STATUS=1
fi
else
if [ $(which dpkg-query) ]
if command -v dpkg-query >/dev/null
then
if dpkg-query -s "${PACKAGE}" 2> /dev/null | grep -qs "Status: install"
then

View File

@ -21,7 +21,7 @@ USAGE="${PROGRAM} [--force]"
# Processing arguments and configuration files
Init_config_data "${@}"
if [ ! $(which debootstrap) ]
if ! command -v debootstrap >/dev/null
then
Echo_error "debootstrap - command not found"
Echo_verbose "debootstrap can be obtained from http://ftp.debian.org/debian/pool/main/d/debootstrap/"

View File

@ -236,7 +236,7 @@ case "${_ACTION}" in
cp -f cache/indices.bootstrap/*Release* chroot/var/lib/apt/lists
fi
if [ "${LB_APT}" = "aptitude" ] && [ ! $(which aptitude) ]
if [ "${LB_APT}" = "aptitude" ] && ! command -v aptitude >/dev/null
then
Chroot chroot "apt-get ${APT_OPTIONS} update"
Chroot chroot "apt-get ${APT_OPTIONS} install aptitude"

View File

@ -212,7 +212,7 @@ Local_arguments ()
--dump)
# Dump version
Echo "This is live-build version %s" "${VERSION}"
if [ $(which dpkg-query) ]; then
if command -v dpkg-query >/dev/null; then
Echo "Installed version reported by dpkg is %s" "$(dpkg-query -f='${Version}' --show live-build)"
fi

View File

@ -11,7 +11,7 @@
set -e
if [ ! $(which grep-aptavail) ]
if ! command -v grep-aptavail >/dev/null
then
echo "E: program grep-aptavail not found!"

View File

@ -8,7 +8,7 @@ set -e
. /live-build/config/binary
if [ $(which apt-file) ] && [ "${LB_APT_INDICES}" = "true" ]
if command -v apt-file >/dev/null && [ "${LB_APT_INDICES}" = "true" ]
then
apt-file update
fi

View File

@ -8,7 +8,7 @@ set -e
# is not allowed to, and (b) it wants to build the index in the background which
# will be racy in the context of live-build.
if [ $(which update-apt-xapian-index) ]
if command -v update-apt-xapian-index >/dev/null
then
PYTHONDONTWRITEBYTECODE=1 update-apt-xapian-index --force --quiet
fi

View File

@ -8,7 +8,7 @@ set -e
# means that if the live system is later installed to a hard disk then less
# work will be required after installation.
if [ $(which updatedb.mlocate) ]
if command -v updatedb.mlocate >/dev/null
then
updatedb.mlocate
fi