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 # strip binaries
if [[ $do_strip = yes ]] ; then if [[ $do_strip = yes ]] ; then
for p in strip grep find; do 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'." derror "Could not find '$p'. You should run $0 with '--nostrip'."
do_strip=no do_strip=no
fi fi

View File

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


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

View File

@ -4,8 +4,8 @@ if [ -e "$moddir/dracut-version" ]; then
dracut_rpm_version=$(cat "$moddir/dracut-version") dracut_rpm_version=$(cat "$moddir/dracut-version")
inst "$moddir/dracut-version" /$dracut_rpm_version inst "$moddir/dracut-version" /$dracut_rpm_version
else else
if rpm -qf $(which $0) &>/dev/null; then if rpm -qf $(type -P $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;} ) 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 echo $dracut_rpm_version > $initdir/$dracut_rpm_version
fi fi
fi fi

View File

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


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




exit 255 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 cmdline 99 "$moddir/parse-ifname.sh"
inst_hook pre-pivot 10 "$moddir/kill-dhclient.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" LIBDIR="/lib64"
else else
LIBDIR="/lib" LIBDIR="/lib"

View File

@ -1,3 +1,3 @@
#!/bin/bash #!/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 ]] [[ -x /sbin/plymouthd && -x /bin/plymouth && -x /usr/sbin/plymouth-set-default-theme ]]

View File

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


# No Xen-detect? Boo!! # 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" ] && [ -d "/usr/lib/xen-default" ] && XENDETECT="/usr/lib/xen-default/bin/xen-detect"
[ -z "$XENDETECT" ] && exit 1 [ -z "$XENDETECT" ] && exit 1



View File

@ -1,5 +1,5 @@
#!/bin/bash #!/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" [ -z "$XENDETECT" ] && [ -d "/usr/lib/xen-default" ] && XENDETECT="/usr/lib/xen-default/bin/xen-detect"
inst $XENDETECT /sbin/xen-detect inst $XENDETECT /sbin/xen-detect
inst_hook pre-udev 40 "$moddir/xen-pre-udev.sh" 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, # if we don't have btrfs (btrfsctl) installed on the host system,
# no point in trying to support it in the initramfs. # 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 . $dracutfunctions
[[ $debug ]] && set -x [[ $debug ]] && set -x

View File

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


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


. $dracutfunctions . $dracutfunctions



View File

@ -5,7 +5,7 @@


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


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

View File

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


inst dmeventd inst dmeventd


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

View File

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


inst blockdev 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 cmdline 30 "$moddir/parse-dmsquash-live.sh"
inst_hook pre-udev 30 "$moddir/dmsquash-live-genrules.sh" inst_hook pre-udev 30 "$moddir/dmsquash-live-genrules.sh"
inst_hook pre-udev 30 "$moddir/dmsquash-liveiso-genrules.sh" inst_hook pre-udev 30 "$moddir/dmsquash-liveiso-genrules.sh"

View File

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


# No point trying to support lvm if the binaries are missing # 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 . $dracutfunctions
[[ $debug ]] && set -x [[ $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" 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" LIBDIR="/lib64"
else else
LIBDIR="/lib" LIBDIR="/lib"

View File

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


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


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

View File

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


# if there's no multipath binary, no go. # 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 [[ $1 = -d ]] && exit 0


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


exit 0 exit 0

View File

@ -1,6 +1,6 @@
#!/bin/bash #!/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" LIBDIR="/lib64"
else else
LIBDIR="/lib" LIBDIR="/lib"

View File

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


# If our prerequisites are not met, fail anyways. # 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 # If hostonly was requested, fail the check if we are not actually
# booting from root. # booting from root.

View File

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


# If our prerequisites are not met, fail. # 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, # if an nbd device is not somewhere in the chain of devices root is mounted on,
# fail the hostonly check. # fail the hostonly check.

View File

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


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

View File

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


dracut_install rpc.statd mount.nfs mount.nfs4 umount dracut_install rpc.statd mount.nfs mount.nfs4 umount
[ -f /etc/netconfig ] && dracut_install /etc/netconfig [ -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 rpc.idmapd /etc/idmapd.conf
dracut_install sed dracut_install sed


if ldd $(which rpc.idmapd) |grep -q lib64; then if ldd $(type -P rpc.idmapd) |grep -q lib64; then
LIBDIR="/lib64" LIBDIR="/lib64"
else else
LIBDIR="/lib" LIBDIR="/lib"
@ -40,7 +40,7 @@ egrep '^nobody:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^nfsnobody:' /etc/passwd >> "$initdir/etc/passwd" egrep '^nfsnobody:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^rpc:' /etc/passwd >> "$initdir/etc/passwd" egrep '^rpc:' /etc/passwd >> "$initdir/etc/passwd"
egrep '^rpcuser:' /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 # rpc user needs to be able to write to this directory to save the warmstart
# file # file

View File

@ -1,9 +1,9 @@
#!/bin/sh #!/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" 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" installs="syslogd"
elif which syslog-ng >/dev/null; then elif type -P syslog-ng >/dev/null; then
installs="syslog-ng" installs="syslog-ng"
else else
dwarn "Could not find any syslog binary although the syslogmodule is selected to be installed. Please check." 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 inst_simple "$moddir/rsyslogd-stop.sh" /sbin/rsyslogd-stop
mkdir -p ${initdir}/etc/templates mkdir -p ${initdir}/etc/templates
inst_simple "${moddir}/rsyslog.conf" /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}/initqueue-settled
mkdir -p ${initdir}/tmp mkdir -p ${initdir}/tmp
# Bail out if switch_root does not exist # 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 dracut_install switch_root
else else
inst "$moddir/switch_root" "/sbin/switch_root" \ inst "$moddir/switch_root" "/sbin/switch_root" \

View File

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

View File

@ -161,7 +161,7 @@ test_setup() {
instmods iscsi_tcp crc32c ipv6 instmods iscsi_tcp crc32c ipv6
inst ./targets /etc/iscsi/targets inst ./targets /etc/iscsi/targets
[ -f /etc/netconfig ] && dracut_install /etc/netconfig [ -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 [ -x /usr/sbin/dhcpd3 ] && inst /usr/sbin/dhcpd3 /usr/sbin/dhcpd
inst ./server-init /sbin/init inst ./server-init /sbin/init
inst ./hosts /etc/hosts inst ./hosts /etc/hosts

View File

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

View File

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