use 'type' built-in instead of external cmd 'which' in every Bash script

master
Amadeusz Żołnowski 2010-08-18 17:29:44 +02:00 committed by Harald Hoyer
parent 5fce1ef0c9
commit f3af7bd66b
28 changed files with 45 additions and 50 deletions

2
dracut
View File

@ -332,7 +332,7 @@ ldconfig -r "$initdir" || [[ $UID != "0" ]] && dinfo "ldconfig might need uid=0
# strip binaries
if [[ $do_strip = yes ]] ; then
for p in strip grep find; do
if ! which $p >/dev/null 2>&1; then
if ! type -P $p >/dev/null; then
derror "Could not find '$p'. You should run $0 with '--nostrip'."
do_strip=no
fi

View File

@ -61,7 +61,6 @@ Requires: sed
Requires: tar
Requires: udev
Requires: util-linux-ng >= 2.16
Requires: which

%if ! 0%{?with_switch_root}
BuildArch: noarch

View File

@ -4,8 +4,8 @@ if [ -e "$moddir/dracut-version" ]; then
dracut_rpm_version=$(cat "$moddir/dracut-version")
inst "$moddir/dracut-version" /$dracut_rpm_version
else
if rpm -qf $(which $0) &>/dev/null; then
dracut_rpm_version=$(rpm -qf --qf '%{name}-%{version}-%{release}\n' $(which $0) | { ver="";while read line;do ver=$line;done;echo $ver;} )
if rpm -qf $(type -P $0) &>/dev/null; then
dracut_rpm_version=$(rpm -qf --qf '%{name}-%{version}-%{release}\n' $(type -P $0) | { ver="";while read line;do ver=$line;done;echo $ver;} )
echo $dracut_rpm_version > $initdir/$dracut_rpm_version
fi
fi

View File

@ -8,20 +8,15 @@ fi
. $dracutfunctions

for program in ip arping; do
which $program >/dev/null 2>&1
if [ $? -ne 0 ]; then
if ! type -P $program >/dev/null; then
dwarning "Could not find program \"$program\" required by network."
exit 1
fi
done
for program in dhclient brctl; do
which $program >/dev/null 2>&1
if [ $? -ne 0 ]; then
if ! type -P $program >/dev/null; then
dwarning "Could not find program \"$program\" it might be required by network."
fi
done



exit 255


View File

@ -12,7 +12,7 @@ inst_hook cmdline 98 "$moddir/parse-bridge.sh"
inst_hook cmdline 99 "$moddir/parse-ifname.sh"
inst_hook pre-pivot 10 "$moddir/kill-dhclient.sh"

if ldd $(which sh) | grep -q lib64; then
if ldd $(type -P sh) | grep -q lib64; then
LIBDIR="/lib64"
else
LIBDIR="/lib"

View File

@ -1,3 +1,3 @@
#!/bin/bash
[[ $1 = -d ]] && which cryptsetup &>/dev/null && echo crypt
[[ $1 = -d ]] && type -P cryptsetup >/dev/null && echo crypt
[[ -x /sbin/plymouthd && -x /bin/plymouth && -x /usr/sbin/plymouth-set-default-theme ]]

View File

@ -1,7 +1,7 @@
#!/bin/bash

# No Xen-detect? Boo!!
XENDETECT=$(which xen-detect 2>/dev/null)
XENDETECT=$(type -P xen-detect)
[ -z "$XENDETECT" ] && [ -d "/usr/lib/xen-default" ] && XENDETECT="/usr/lib/xen-default/bin/xen-detect"
[ -z "$XENDETECT" ] && exit 1


View File

@ -1,5 +1,5 @@
#!/bin/bash
XENDETECT=$(which xen-detect)
XENDETECT=$(type -P xen-detect)
[ -z "$XENDETECT" ] && [ -d "/usr/lib/xen-default" ] && XENDETECT="/usr/lib/xen-default/bin/xen-detect"
inst $XENDETECT /sbin/xen-detect
inst_hook pre-udev 40 "$moddir/xen-pre-udev.sh"

View File

@ -5,7 +5,7 @@

# if we don't have btrfs (btrfsctl) installed on the host system,
# no point in trying to support it in the initramfs.
which btrfsctl >/dev/null 2>&1 || exit 1
type -P btrfsctl >/dev/null || exit 1

. $dracutfunctions
[[ $debug ]] && set -x

View File

@ -1,8 +1,9 @@
#!/bin/bash

# if cryptsetup is not installed, then we cannot support encrypted devices.
which cryptsetup >/dev/null 2>&1 || exit 1
[[ $1 = -d ]] && echo dm
type -P cryptsetup >/dev/null || exit 1

[ "$1" = "-d" ] && echo dm

. $dracutfunctions


View File

@ -5,7 +5,7 @@

# if we don't have dmraid installed on the host system, no point
# in trying to support it in the initramfs.
which dmraid >/dev/null 2>&1 || exit 1
type -P dmraid >/dev/null || exit 1

. $dracutfunctions
[[ $debug ]] && set -x

View File

@ -3,7 +3,7 @@ dracut_install dmraid partx kpartx

inst dmeventd

if ldd $(which dmraid) | grep -q lib64; then
if ldd $(type -P dmraid) | grep -q lib64; then
LIBDIR="/lib64"
else
LIBDIR="/lib"

View File

@ -14,7 +14,7 @@ else
fi

inst blockdev
which checkisomd5 >/dev/null 2>&1 && inst checkisomd5
type -P checkisomd5 >/dev/null && inst checkisomd5
inst_hook cmdline 30 "$moddir/parse-dmsquash-live.sh"
inst_hook pre-udev 30 "$moddir/dmsquash-live-genrules.sh"
inst_hook pre-udev 30 "$moddir/dmsquash-liveiso-genrules.sh"

View File

@ -4,7 +4,7 @@
[ "$1" = "-d" ] && echo dm

# No point trying to support lvm if the binaries are missing
which lvm >/dev/null 2>&1 || exit 1
type -P lvm >/dev/null || exit 1

. $dracutfunctions
[[ $debug ]] && set -x

View File

@ -18,7 +18,7 @@ inst "$moddir/lvm_scan.sh" /sbin/lvm_scan
inst_hook cmdline 30 "$moddir/parse-lvm.sh"


if ldd $(which lvm) | grep -q lib64; then
if ldd $(type -P lvm) | grep -q lib64; then
LIBDIR="/lib64"
else
LIBDIR="/lib"

View File

@ -1,7 +1,7 @@
#!/bin/bash

# No mdadm? No mdraid support.
which mdadm >/dev/null 2>&1 || exit 1
type -P mdadm >/dev/null || exit 1

. $dracutfunctions
[[ $debug ]] && set -x

View File

@ -1,7 +1,7 @@
#!/bin/bash

# if there's no multipath binary, no go.
which multipath >/dev/null 2>&1 || exit 1
type -P multipath >/dev/null || exit 1

[[ $1 = -d ]] && exit 0

@ -22,4 +22,4 @@ if [[ $1 = -h ]]; then
exit 1
fi

exit 0
exit 0

View File

@ -1,6 +1,6 @@
#!/bin/bash

if ldd $(which multipath) 2>/dev/null |grep -q lib64; then
if ldd $(type -P multipath) 2>/dev/null |grep -q lib64; then
LIBDIR="/lib64"
else
LIBDIR="/lib"

View File

@ -3,7 +3,7 @@
[ "$1" = "-d" ] && echo network

# If our prerequisites are not met, fail anyways.
which iscsistart hostname iscsi-iname >/dev/null 2>&1 || exit 1
type -P iscsistart hostname iscsi-iname >/dev/null || exit 1

# If hostonly was requested, fail the check if we are not actually
# booting from root.

View File

@ -3,7 +3,7 @@
[ "$1" = "-d" ] && echo network

# If our prerequisites are not met, fail.
which nbd-client >/dev/null 2>&1 || exit 1
type -P nbd-client >/dev/null || exit 1

# if an nbd device is not somewhere in the chain of devices root is mounted on,
# fail the hostonly check.

View File

@ -7,6 +7,6 @@
[ "$1" = "-h" ] && ! egrep -q '/ nfs[34 ]' /proc/mounts && exit 1

# If our prerequisites are not met, fail anyways.
which rpcbind >/dev/null 2>&1 || which portmap >/dev/null 2>&1 || exit 1
which rpc.statd mount.nfs mount.nfs4 umount >/dev/null 2>&1 || exit 1
type -P rpcbind >/dev/null || type -P portmap >/dev/null || exit 1
type -P rpc.statd mount.nfs mount.nfs4 umount >/dev/null || exit 1
exit 0

View File

@ -1,6 +1,6 @@
#!/bin/sh
which portmap >/dev/null 2>&1 && dracut_install portmap
which rpcbind >/dev/null 2>&1 && dracut_install rpcbind
type -P portmap >/dev/null && dracut_install portmap
type -P rpcbind >/dev/null && dracut_install rpcbind

dracut_install rpc.statd mount.nfs mount.nfs4 umount
[ -f /etc/netconfig ] && dracut_install /etc/netconfig
@ -9,7 +9,7 @@ dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols
dracut_install rpc.idmapd /etc/idmapd.conf
dracut_install sed

if ldd $(which rpc.idmapd) |grep -q lib64; then
if ldd $(type -P rpc.idmapd) |grep -q lib64; then
LIBDIR="/lib64"
else
LIBDIR="/lib"
@ -40,7 +40,7 @@ egrep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^nfsnobody:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^rpc:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^rpcuser:' /etc/passwd >> "$initdir/etc/passwd"
#which nologin >/dev/null 2>&1 && dracut_install nologin
#type -P nologin >/dev/null && dracut_install nologin

# rpc user needs to be able to write to this directory to save the warmstart
# file

View File

@ -1,9 +1,9 @@
#!/bin/sh
if which rsyslogd >/dev/null; then
if type -P rsyslogd >/dev/null; then
installs="rsyslogd /usr/lib/rsyslog/lmnet.so /usr/lib/rsyslog/imklog.so /usr/lib/rsyslog/imuxsock.so"
elif which syslogd >/dev/null; then
elif type -P syslogd >/dev/null; then
installs="syslogd"
elif which syslog-ng >/dev/null; then
elif type -P syslog-ng >/dev/null; then
installs="syslog-ng"
else
dwarn "Could not find any syslog binary although the syslogmodule is selected to be installed. Please check."
@ -18,4 +18,4 @@ if [ -n "$installs" ]; then
inst_simple "$moddir/rsyslogd-stop.sh" /sbin/rsyslogd-stop
mkdir -p ${initdir}/etc/templates
inst_simple "${moddir}/rsyslog.conf" /etc/templates
fi
fi

View File

@ -21,7 +21,7 @@ mkdir -p ${initdir}/initqueue-finished
mkdir -p ${initdir}/initqueue-settled
mkdir -p ${initdir}/tmp
# Bail out if switch_root does not exist
if which switch_root >/dev/null 2>&1; then
if type -P switch_root >/dev/null; then
dracut_install switch_root
else
inst "$moddir/switch_root" "/sbin/switch_root" \

View File

@ -206,10 +206,10 @@ test_setup() {
/lib/terminfo/l/linux dmesg mkdir cp ping exportfs \
modprobe rpc.nfsd rpc.mountd showmount tcpdump \
/etc/services sleep mount chmod
which portmap >/dev/null 2>&1 && dracut_install portmap
which rpcbind >/dev/null 2>&1 && dracut_install rpcbind
type -P portmap >/dev/null && dracut_install portmap
type -P rpcbind >/dev/null && dracut_install rpcbind
[ -f /etc/netconfig ] && dracut_install /etc/netconfig
which dhcpd >/dev/null 2>&1 && dracut_install dhcpd
type -P dhcpd >/dev/null && dracut_install dhcpd
[ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
instmods nfsd sunrpc ipv6
inst ./server-init /sbin/init
@ -218,7 +218,7 @@ test_setup() {
inst ./dhcpd.conf /etc/dhcpd.conf
dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols
dracut_install rpc.idmapd /etc/idmapd.conf
if ldd $(which rpc.idmapd) |grep -q lib64; then
if ldd $(type -P rpc.idmapd) |grep -q lib64; then
LIBDIR="/lib64"
else
LIBDIR="/lib"

View File

@ -161,7 +161,7 @@ test_setup() {
instmods iscsi_tcp crc32c ipv6
inst ./targets /etc/iscsi/targets
[ -f /etc/netconfig ] && dracut_install /etc/netconfig
which dhcpd >/dev/null 2>&1 && dracut_install dhcpd
type -P dhcpd >/dev/null && dracut_install dhcpd
[ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
inst ./server-init /sbin/init
inst ./hosts /etc/hosts

View File

@ -263,7 +263,7 @@ make_server_root() {
dracut_install sh ls shutdown poweroff stty cat ps ln ip \
/lib/terminfo/l/linux dmesg mkdir cp ping grep \
sleep nbd-server chmod
which dhcpd >/dev/null 2>&1 && dracut_install dhcpd
type -P dhcpd >/dev/null && dracut_install dhcpd
[ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
inst ./server-init /sbin/init
inst ./hosts /etc/hosts

View File

@ -135,10 +135,10 @@ test_setup() {
/lib/terminfo/l/linux dmesg mkdir cp ping exportfs \
modprobe rpc.nfsd rpc.mountd showmount tcpdump \
/etc/services sleep mount chmod
which portmap >/dev/null 2>&1 && dracut_install portmap
which rpcbind >/dev/null 2>&1 && dracut_install rpcbind
type -P portmap >/dev/null && dracut_install portmap
type -P rpcbind >/dev/null && dracut_install rpcbind
[ -f /etc/netconfig ] && dracut_install /etc/netconfig
which dhcpd >/dev/null 2>&1 && dracut_install dhcpd
type -P dhcpd >/dev/null && dracut_install dhcpd
[ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
instmods nfsd sunrpc ipv6
inst ./server-init /sbin/init
@ -147,7 +147,7 @@ test_setup() {
inst ./dhcpd.conf /etc/dhcpd.conf
dracut_install /etc/nsswitch.conf /etc/rpc /etc/protocols
dracut_install rpc.idmapd /etc/idmapd.conf
if ldd $(which rpc.idmapd) |grep -q lib64; then
if ldd $(type -P rpc.idmapd) |grep -q lib64; then
LIBDIR="/lib64"
else
LIBDIR="/lib"