]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
use 'type' built-in instead of external cmd 'which' in every Bash script
authorAmadeusz Żołnowski <aidecoe@aidecoe.name>
Wed, 18 Aug 2010 15:29:44 +0000 (17:29 +0200)
committerHarald Hoyer <harald@redhat.com>
Mon, 23 Aug 2010 09:54:09 +0000 (11:54 +0200)
28 files changed:
dracut
dracut.spec
modules.d/10rpmversion/install
modules.d/40network/check
modules.d/40network/install
modules.d/50plymouth/check
modules.d/60xen/check
modules.d/60xen/install
modules.d/90btrfs/check
modules.d/90crypt/check
modules.d/90dmraid/check
modules.d/90dmraid/install
modules.d/90dmsquash-live/install
modules.d/90lvm/check
modules.d/90lvm/install
modules.d/90mdraid/check
modules.d/90multipath/check
modules.d/90multipath/install
modules.d/95iscsi/check
modules.d/95nbd/check
modules.d/95nfs/check
modules.d/95nfs/install
modules.d/98syslog/install
modules.d/99base/install
test/TEST-20-NFS/test.sh
test/TEST-30-ISCSI/test.sh
test/TEST-40-NBD/test.sh
test/TEST-50-MULTINIC/test.sh

diff --git a/dracut b/dracut
index f70aa50045ed0d584d46783975695de56da829ca..4cf2ca3d25ccd0a21fb972278494c558d0cda17d 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -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
index 2cd570a6002f0c3481e8a172aa8565e5ed2e63b7..b0c248ce2f8b6cffca25462ebb982dfab1dc3f4e 100644 (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
index 2349674e2a961d363cb040e9815c59911a161d17..1fd0005f0e8334c117764530a09f8180a12fd032 100755 (executable)
@@ -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
index 48b7f123eddd88e548d47b0dc2a346b6523e9298..4e2a5fdcd90f01c388d4c94e5997c500a0ed574f 100755 (executable)
@@ -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
-
index 398d4e42f31eac0cfd10bd5d3309d4e5b3e33f95..d8e039987ce605e411ef6d4013b952ad25c53fff 100755 (executable)
@@ -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"
index ceb26a7ab74f1b62416f17102332e7c918603638..40f201646eedbb24b38d789c6cc7d4a85574c156 100755 (executable)
@@ -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 ]]
index f155582c37e82d16e995919a3b917c096b42b949..49d54352110211e2d01c5b45e6f2f4bc7c1d7015 100755 (executable)
@@ -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
 
index 89065b5d5c1ea8573c19986d62cb7c4000841826..22f53293d4e2740782b3c4cc6bd6370e802e0427 100755 (executable)
@@ -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"
index 99aa712547b8247137c7b897afb0a8a403468c73..c562cb8c7ba0a07a0ab651e73fe7903955deee8f 100755 (executable)
@@ -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
index 22a017ed01c899a2b1adb4102c73f22bdc895832..b89d9a0998cd9058d4187bb9cadbff884cd6ea69 100755 (executable)
@@ -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
 
index 147b7fa464e20686cfeef76a8ff485d3f3cd1883..b93de0991cb36ffd8a8ff42f9fb8734c73588edd 100755 (executable)
@@ -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
index a016e4d21f0a563cb522176587d2716d3e621f66..1a63ad7257bb1e107015f7f106b2f07270d993cf 100755 (executable)
@@ -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"
index ad1d29c764839f7690e5a2c92152111649776a2b..daa4c45fba133f93f491d69ac35e2d7147bd9fb1 100755 (executable)
@@ -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"
index 20f21e8f842d29269364a1be08b2072f9f7b39cb..26f39cb52aa7d80981b221478a2333ad467b0476 100755 (executable)
@@ -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
index 3e2086649686f26d12a956bf6a6cda020806c161..9eba6e8d1a8dfd981925250e70aa5e60a73a52f3 100755 (executable)
@@ -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"
index cad3d0b62a2eab0d7f504da631020b71bbf96d32..77aa1f59cc21cf95e3573856a2c4b88cb2bb44ab 100755 (executable)
@@ -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
index b1834b524a6c4bfce32ede9b0c136b6ebc61173a..511c5d59ab0136ca2d07487e38445095d5910f14 100755 (executable)
@@ -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
\ No newline at end of file
+exit 0
index ed2d698fad514a618c5c7d9e4c045290b1bdea80..7c78471c01d5b432c1fdd516498ff941c324f749 100755 (executable)
@@ -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"
index 5a47d97bdd89f6c68130eb4ba2038d90f87c5ca8..55cb53ba3fc4e1721b7bd7768142893971d05829 100755 (executable)
@@ -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.
index a84ed1dfa428a07eac0e1e46780ad5421cf18123..aa69a4119ef702cb624c181a51e68087ef8d4cd9 100755 (executable)
@@ -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.
index f72aaae4c4a5997507dbdee1941c1822dbc37e7a..adb53dd8575b1c8ccf796dc9d7b3957f7ec75976 100755 (executable)
@@ -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
index 5d3c5355aa5249fd10307fedbf38c881184cf3d0..0599ff120dd5af43ebb70043d321016e551721a4 100755 (executable)
@@ -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
index bf678d92d2a1ecd4256aeb8792d5c4e58d63301c..52e2fca22ee6fd0d4e73d7fa1a91ebf8af9c4046 100755 (executable)
@@ -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
\ No newline at end of file
+fi
index 9cdb08628fb8dcd1626eeb7417dfdcdc0ecbf7aa..1d554e58e0e838c6ec6b13b845e6a3638a100ee7 100755 (executable)
@@ -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" \
index 530a42c312125cdb491d1485b248803c8b74f897..24b909c614523f4aabd28ea3baef345661ea39b3 100755 (executable)
@@ -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"
index 637f264eebff3e8e4009ec2f5e9c754224e36ff9..a0b85c315527d5257adcf254540dff32d7ff9448 100755 (executable)
@@ -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
index 1a46ed14499e5e842d8280e4cc43f7f31659d25b..ba68b48fa61b57f1512588851be7040ded185012 100755 (executable)
@@ -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
index 9a3f6196358fcd916f1fd70b5c1e7e776e12d21f..e07ef3b698800ba56587b0e82d87023b85009e50 100755 (executable)
@@ -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"