]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Factor out all the "type -V" commands
authorHarald Hoyer <harald@redhat.com>
Thu, 6 Feb 2014 15:45:20 +0000 (16:45 +0100)
committerHarald Hoyer <harald@redhat.com>
Thu, 6 Feb 2014 15:45:20 +0000 (16:45 +0100)
Add new functions require_binaries() and require_any_binary() to be used
in the check() section of module-setup.sh.

These functions print a warning line telling the user, which binary is
missing for the specific dracut module.

This unifies the way of checking for binaries and makes the life of an
initramfs creator easier, if he wants to find out why a specific dracut
module is not included in the initramfs.

39 files changed:
dracut-functions.sh
modules.d/00bash/module-setup.sh
modules.d/00bootchart/module-setup.sh
modules.d/00dash/module-setup.sh
modules.d/00systemd-bootchart/module-setup.sh
modules.d/02caps/module-setup.sh
modules.d/03modsign/module-setup.sh
modules.d/05busybox/module-setup.sh
modules.d/10i18n/module-setup.sh
modules.d/40network/module-setup.sh
modules.d/45url-lib/module-setup.sh
modules.d/50plymouth/module-setup.sh
modules.d/90btrfs/module-setup.sh
modules.d/90crypt/module-setup.sh
modules.d/90dm/module-setup.sh
modules.d/90dmraid/module-setup.sh
modules.d/90lvm/module-setup.sh
modules.d/90mdraid/module-setup.sh
modules.d/90multipath/module-setup.sh
modules.d/91crypt-gpg/module-setup.sh
modules.d/91crypt-loop/module-setup.sh
modules.d/95cifs/module-setup.sh
modules.d/95dasd/module-setup.sh
modules.d/95dasd_mod/module-setup.sh
modules.d/95dasd_rules/module-setup.sh
modules.d/95fcoe-uefi/module-setup.sh
modules.d/95fcoe/module-setup.sh
modules.d/95iscsi/module-setup.sh
modules.d/95nbd/module-setup.sh
modules.d/95nfs/module-setup.sh
modules.d/95ssh-client/module-setup.sh
modules.d/95udev-rules/module-setup.sh
modules.d/95zfcp/module-setup.sh
modules.d/95zfcp_rules/module-setup.sh
modules.d/95znet/module-setup.sh
modules.d/97biosdevname/module-setup.sh
modules.d/97masterkey/module-setup.sh
modules.d/98systemd/module-setup.sh
modules.d/99img-lib/module-setup.sh

index c766ca3b7878cfa6d73b6e28d48da6c944173919..32f264b9549240fd401b2cd72277b5728ef1a382 100755 (executable)
@@ -35,6 +35,51 @@ fi
 # Generic substring function.  If $2 is in $1, return 0.
 strstr() { [[ $1 = *$2* ]]; }
 
+# helper function for check() in module-setup.sh
+# to check for required installed binaries
+# issues a standardized warning message
+require_binaries() {
+    local _module_name="${moddir##*/}"
+    local _ret=0
+
+    if [[ "$1" = "-m" ]]; then
+        _module_name="$2"
+        shift 2
+    fi
+
+    for cmd in "$@"; do
+        if ! find_binary "$cmd" &>/dev/null; then
+            dwarning "$_module_name: Could not find command '$cmd'!"
+            ((_ret++))
+        fi
+    done
+    return $_ret
+}
+
+require_any_binary() {
+    local _module_name="${moddir##*/}"
+    local _ret=1
+
+    if [[ "$1" = "-m" ]]; then
+        _module_name="$2"
+        shift 2
+    fi
+
+    for cmd in "$@"; do
+        if find_binary "$cmd" &>/dev/null; then
+            _ret=0
+            break
+        fi
+    done
+
+    if (( $_ret != 0 )); then
+        dwarning "$_module_name: Could not find any command of '$@'!"
+        return 1
+    fi
+
+    return 0
+}
+
 # find a binary.  If we were not passed the full path directly,
 # search in the usual places to find the binary.
 find_binary() {
@@ -1084,7 +1129,7 @@ module_check() {
         . $_moddir/module-setup.sh
         is_func check || return 0
         [ $_forced -ne 0 ] && unset hostonly
-        check $hostonly
+        moddir=$_moddir check $hostonly
         _ret=$?
         unset check depends cmdline install installkernel
     fi
@@ -1110,7 +1155,7 @@ module_check_mount() {
         unset check depends cmdline install installkernel
         check() { false; }
         . $_moddir/module-setup.sh
-        check 0
+        moddir=$_moddir check 0
         _ret=$?
         unset check depends cmdline install installkernel
     fi
@@ -1134,7 +1179,7 @@ module_depends() {
         unset check depends cmdline install installkernel
         depends() { true; }
         . $_moddir/module-setup.sh
-        depends
+        moddir=$_moddir depends
         _ret=$?
         unset check depends cmdline install installkernel
         return $_ret
@@ -1155,7 +1200,7 @@ module_cmdline() {
         unset check depends cmdline install installkernel
         cmdline() { true; }
         . $_moddir/module-setup.sh
-        cmdline
+        moddir=$_moddir cmdline
         _ret=$?
         unset check depends cmdline install installkernel
         return $_ret
@@ -1176,7 +1221,7 @@ module_install() {
         unset check depends cmdline install installkernel
         install() { true; }
         . $_moddir/module-setup.sh
-        install
+        moddir=$_moddir install
         _ret=$?
         unset check depends cmdline install installkernel
         return $_ret
@@ -1197,7 +1242,7 @@ module_installkernel() {
         unset check depends cmdline install installkernel
         installkernel() { true; }
         . $_moddir/module-setup.sh
-        installkernel
+        moddir=$_moddir installkernel
         _ret=$?
         unset check depends cmdline install installkernel
         return $_ret
index f599940158a3f5b5ae4b434e4198b55e376b48bf..e8fc11539c82c9152b09e6bcefb63d3896eefa78 100755 (executable)
@@ -4,7 +4,7 @@
 
 # called by dracut
 check() {
-    [ -x /bin/bash ]
+    require_binaries /bin/bash
 }
 
 # called by dracut
index 107ee5b84c99f039fdba93a7180d220e05d83926..95e5c4b336f68881275c76687de92d34b6202bca 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     [[ "$mount_needs" ]] && return 1
-    [ -x /sbin/bootchartd ] || return 1
+    require_binaries /sbin/bootchartd || return 1
     return 255
 }
 
index 47f7b03116d44e4ef75b77183ed58047d9cc9b76..8f7deec2570fafb53d72efa40ad17450e42b7f12 100755 (executable)
@@ -4,7 +4,7 @@
 
 # called by dracut
 check() {
-    [ -x /bin/dash ]
+    require_binaries /bin/dash
 }
 
 # called by dracut
index a897cef5144ec1ecad8e008c954e2f9c5fd678e2..5cca2543d096d75c8ec6c1c9b58d6dbd04052a7a 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     [[ "$mount_needs" ]] && return 1
-    [ -x $systemdutildir/systemd-bootchart ] || return 1
+    require_binaries $systemdutildir/systemd-bootchart || return 1
     return 255
 }
 
index 601918851eba73d1ab08a4d47d6512b89932ba70..46e35a00cae50acc566b9c4b2849ce4171b27fd9 100755 (executable)
@@ -4,7 +4,7 @@
 
 # called by dracut
 check() {
-    type -P capsh >/dev/null 2>&1
+    require_binaries capsh
 }
 
 # called by dracut
@@ -14,9 +14,13 @@ depends() {
 
 # called by dracut
 install() {
-    inst_hook pre-pivot 00 "$moddir/caps.sh"
-    inst $(type -P capsh 2>/dev/null) /usr/sbin/capsh
-    # capsh wants bash and we need bash also
-    inst /bin/bash
+    if ! dracut_module_included "systemd"; then
+        inst_hook pre-pivot 00 "$moddir/caps.sh"
+        inst $(type -P capsh 2>/dev/null) /usr/sbin/capsh
+        # capsh wants bash and we need bash also
+        inst /bin/bash
+    else
+        dwarning "caps: does not work with systemd in the initramfs"
+    fi
 }
 
index 5dfd90c95ebbf6a4f86aa2203c098f46f136a0eb..09285d3b07467d94782bc4a210be5fc54a0d72c3 100755 (executable)
@@ -9,7 +9,7 @@
 
 # called by dracut
 check() {
-    [[ -x /usr/bin/keyctl ]] || return 1
+    require_binaries keyctl || return 1
 
     # do not include module in hostonly mode,
     # if no keys are present
index 6e508a66ada66efe715718c17935ee044cc9dcad..228ff8c2386e3e469e2918c99881b7298d13052c 100755 (executable)
@@ -4,7 +4,7 @@
 
 # called by dracut
 check() {
-    type -P busybox >/dev/null || return 1
+    require_binaries busybox || return 1
 
     return 255
 }
index fcb18d17468d85b9a5d580b4d1d489a72f893501..a091f89f7313a3d510715cfc4ed1f8da5acd65c9 100755 (executable)
@@ -6,9 +6,7 @@
 check() {
     [[ "$mount_needs" ]] && return 1
 
-    for i in setfont loadkeys kbd_mode; do
-        type -P "$i" >/dev/null || return 1
-    done
+    require_binaries setfont loadkeys kbd_mode || return 1
 
     return 0
 }
index 48afc5a2d041b1e5e8afa38391e478dbdc709e02..1df4174ad94cd4b3f1269290196eec8d834c56fd 100755 (executable)
@@ -6,12 +6,7 @@
 check() {
     local _program
 
-    for _program in ip arping dhclient ; do
-        if ! type -P $_program >/dev/null; then
-            derror "Could not find program \"$_program\" required by network."
-            return 1
-        fi
-    done
+    require_binaries ip arping dhclient || return 1
 
     return 255
 }
index 1ed97acba3652363674d581f27ba58ef28d3b599..1b785c242a8eb6649c139f6e8a30c27bae5b029f 100755 (executable)
@@ -3,7 +3,7 @@
 
 # called by dracut
 check() {
-    command -v curl >/dev/null || return 1
+    require_binaries curl || return 1
     return 255
 }
 
index 136092469234c3ed7751b1f9b432d7e4b067b372..b818324f59817828443af728a7e8f32c01e98f85 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     [[ "$mount_needs" ]] && return 1
-    type -P plymouthd >/dev/null && type -P plymouth >/dev/null
+    require_binaries plymouthd plymouth
 }
 
 # called by dracut
index 80a538fd574469c2455861af9a8a473965dcc665..406fd6d4c91f43d61c06c07f52ec273dbc576de8 100755 (executable)
@@ -7,7 +7,7 @@ check() {
     local _rootdev
     # if we don't have btrfs installed on the host system,
     # no point in trying to support it in the initramfs.
-    type -P btrfs >/dev/null || return 1
+    require_binaries btrfs || return 1
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         for fs in ${host_fs_types[@]}; do
index 7d18e33e5d9971c940b31a3597d5dc3eb90b5994..21d49c4668695d4ce95525f84d60dec9765d1bb0 100755 (executable)
@@ -6,7 +6,7 @@
 check() {
     local _rootdev
     # if cryptsetup is not installed, then we cannot support encrypted devices.
-    type -P cryptsetup >/dev/null || return 1
+    require_binaries cryptsetup || return 1
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         for fs in "${host_fs_types[@]}"; do
index bafad67a9d4ae60bb034d7c4e8e2961a58f2f589..829c24bde6581bcd5dd52caa611da177c7cfb91a 100755 (executable)
@@ -4,7 +4,7 @@
 
 # called by dracut
 check() {
-    type -P dmsetup >/dev/null || return 1
+    require_binaries dmsetup || return 1
     return 255
 }
 
index a9e27a66a41e4fe1f34016bbdbcc98fe82610df6..d3888a4cbd467452243ec3f80a13f4cb0acb2ef8 100755 (executable)
@@ -7,7 +7,7 @@ check() {
     local _rootdev
     # if we don't have dmraid installed on the host system, no point
     # in trying to support it in the initramfs.
-    type -P dmraid >/dev/null || return 1
+    require_binaries dmraid || return 1
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         for dev in "${!host_fs_types[@]}"; do
index a64e5d6629e051fa8cbfbf0d5a12a8545762d49b..357797fe99a880ba0428637947f722573167137a 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     # No point trying to support lvm if the binaries are missing
-    type -P lvm >/dev/null || return 1
+    require_binaries lvm || return 1
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         for fs in "${host_fs_types[@]}"; do
index 61483f2500dc5ef9f249c972953add9cf40057bc..7d72098ff05a5e0466a338f38bee887c3d8ea000 100755 (executable)
@@ -6,7 +6,7 @@
 check() {
     local _rootdev
     # No mdadm?  No mdraid support.
-    type -P mdadm >/dev/null || return 1
+    require_binaries mdadm || return 1
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         for dev in "${!host_fs_types[@]}"; do
index 261a957e4f21e0104245dad7f0f559f3e4125bd1..b60cc6015d8202db49580035f6baee5b15a466cf 100755 (executable)
@@ -6,7 +6,7 @@
 check() {
     local _rootdev
     # if there's no multipath binary, no go.
-    type -P multipath >/dev/null || return 1
+    require_binaries multipath || return 1
 
     is_mpath() {
         local _dev=$1
index 90c7bc2e83631bb9d4fb2c37ffb21d3c6bed927d..b2154f0e7cf27682a312c3ba61fcd60825d90676 100755 (executable)
@@ -5,7 +5,7 @@
 # GPG support is optional
 # called by dracut
 check() {
-    type -P gpg >/dev/null || return 1
+    require_binaries gpg || return 1
 
     return 255
 }
index 00052d3b71bede9aa2588f45dc21125ab907ae92..93ae92e41cbcadf1019062a67c23f149096995c5 100644 (file)
@@ -1,23 +1,27 @@
+#!/bin/bash
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
+# ex: ts=8 sw=4 sts=4 et filetype=sh
+
 # called by dracut
 check() {
-       type -P losetup >/dev/null || return 1
-       
-       return 255
+    require_binaries losetup || return 1
+
+    return 255
 }
 
 # called by dracut
 depends() {
-       echo crypt
+    echo crypt
 }
 
 # called by dracut
 installkernel() {
-           instmods loop
+    instmods loop
 }
 
 # called by dracut
 install() {
-       inst_multiple losetup
-       inst "$moddir/crypt-loop-lib.sh" "/lib/dracut-crypt-loop-lib.sh"
-        dracut_need_initqueue
+    inst_multiple losetup
+    inst "$moddir/crypt-loop-lib.sh" "/lib/dracut-crypt-loop-lib.sh"
+    dracut_need_initqueue
 }
index 546d2ff00e2337c344d98c5e50e60ab1255adbb1..8f5a3bfd3dba30705f1c84e64d856a4d71e9b717 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     # If our prerequisites are not met, fail anyways.
-    type -P mount.cifs >/dev/null || return 1
+    require_binaries mount.cifs || return 1
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         for fs in ${host_fs_types[@]}; do
index 9c93d4033276322161af63a30ab201bc69641f04..da0f3c08897ad9c1f6119c8b4a9f96a5dbf34815 100755 (executable)
@@ -5,8 +5,8 @@
 # called by dracut
 check() {
     local _arch=$(uname -m)
-    [ -x /sbin/normalize_dasd_arg ] || return 1
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
+    require_binaries normalize_dasd_arg || return 1
     return 0
 }
 
index 8fde525abbf5678ba32af98c69ae2ee3d37ce429..bee4998f3316ad419a3d252bed47fe493b79f132 100755 (executable)
@@ -6,6 +6,7 @@
 check() {
     local _arch=$(uname -m)
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
+    require_binaries grep sed seq
 
     return 0
 }
index d313171776d4179595ccb1396398c5f5746a3f50..51c315df84b33ce7ba53cc8a677ccfa667f48295 100755 (executable)
@@ -5,8 +5,8 @@
 # called by dracut
 check() {
     local _arch=$(uname -m)
-    [ -x /sbin/dasd_configure ] || return 1
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
+    require_binaries dasd_configure /usr/lib/udev/collect || return 1
     return 0
 }
 
index c91f77540a3a3a1b4c6ac59e5aea554932d7447d..0fb06e23383035113afdf3d33b936821560cf017 100755 (executable)
@@ -4,9 +4,7 @@
 
 # called by dracut
 check() {
-    for i in dcbtool fipvlan lldpad ip readlink; do
-        type -P $i >/dev/null || return 1
-    done
+    require_binaries dcbtool fipvlan lldpad ip readlink || return 1
     return 0
 }
 
index 539c46458eb26a6049c9757a61cd52bdb3cdde5e..c502ba003c3f08abe93726c030c235e1f9e739b9 100755 (executable)
@@ -4,10 +4,7 @@
 
 # called by dracut
 check() {
-    for i in dcbtool fipvlan lldpad ip readlink; do
-        type -P $i >/dev/null || return 1
-    done
-
+    require_binaries dcbtool fipvlan lldpad ip readlink || return 1
     return 0
 }
 
index 8379f4b32bf7d5820c7ee0f576a108745b636ddd..1b0f292abd3bd7614a534c6a2299e7539ac71985 100755 (executable)
@@ -6,7 +6,7 @@
 check() {
     local _rootdev
     # If our prerequisites are not met, fail anyways.
-    type -P iscsistart hostname iscsi-iname >/dev/null || return 1
+    require_binaries iscsistart hostname iscsi-iname || return 1
 
     # If hostonly was requested, fail the check if we are not actually
     # booting from root.
index 37ace21fc2b8714687afdb84bd63a95bf71ec287..e62f290040cf90425055950a63b16eee23d1fa3e 100755 (executable)
@@ -6,7 +6,7 @@
 check() {
     local _rootdev
     # If our prerequisites are not met, fail.
-    type -P nbd-client >/dev/null || return 1
+    require_binaries nbd-client || return 1
 
     # if an nbd device is not somewhere in the chain of devices root is
     # mounted on, fail the hostonly check.
index 345810a3ebe0a165e07015696f8d580a23e6ca40..dabf3b01f65b2c7ba7d7a8119f5c25ba1752b3f1 100755 (executable)
@@ -5,8 +5,8 @@
 # called by dracut
 check() {
     # If our prerequisites are not met, fail anyways.
-    type -P rpcbind >/dev/null || type -P portmap >/dev/null || return 1
-    type -P rpc.statd mount.nfs mount.nfs4 umount >/dev/null || return 1
+    require_any_binary rpcbind portmap || return 1
+    require_binaries rpc.statd mount.nfs mount.nfs4 umount || return 1
 
     [[ $hostonly ]] || [[ $mount_needs ]] && {
         for fs in ${host_fs_types[@]}; do
index 1f2b73376edc7c9541f89db0d22116565d147850..2e3c505112b45d303e775f4703006066ef34ef88 100755 (executable)
@@ -6,11 +6,11 @@
 
 # called by dracut
 check() {
-    # If our prerequisites are not met, fail.
-    type -P ssh >/dev/null || return 1
-    type -P scp >/dev/null || return 1
     [[ $mount_needs ]] && return 1
 
+    # If our prerequisites are not met, fail.
+    require_binaries ssh scp  || return 1
+
     if [[ $sshkey ]]; then
         [ ! -f $sshkey ] && {
             derror "ssh key: $sshkey is not found!"
index ebc444777fee1a3ca2bcba715d5a616f4517a7a9..584d5c8ddfeefb4e6e41995db5d36715909cea09 100755 (executable)
@@ -6,7 +6,7 @@
 install() {
     local _i
 
-    # Fixme: would be nice if we didn't have to know which rules to grab....
+    # Fixme: would be nice if we didn't have to guess, which rules to grab....
     # ultimately, /lib/initramfs/rules.d or somesuch which includes links/copies
     # of the rules we want so that we just copy those in would be best
     inst_multiple udevadm cat uname blkid \
index dfbeed5b6be9b53d30de581baa63c02581fc2c7b..b96ccd2e61b72a3705f435ca0159c04841234b71 100755 (executable)
@@ -5,9 +5,10 @@
 # called by dracut
 check() {
     arch=$(uname -m)
-    [ -x /sbin/zfcp_cio_free ] || return 1
     [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
 
+    require_binaries zfcp_cio_free grep sed seq || return 1
+
     return 0
 }
 
index 9a1ab20a7418632375c025481c48ffb5d66b887b..d9879cb745db411ae334b3823efeefd6a07a85e5 100755 (executable)
@@ -5,8 +5,8 @@
 # called by dracut
 check() {
     local _arch=$(uname -m)
-    [ -x /sbin/zfcp_disk_configure ] || return 1
     [ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
+    require_binaries zfcp_disk_configure /usr/lib/udev/collect || return 1
     return 0
 }
 
index 5012b77695f6c9ea911a9f45c1cbe3811ff3e6cd..346f893e746812545a0341db91fc2d9c1436f61d 100755 (executable)
@@ -5,9 +5,10 @@
 # called by dracut
 check() {
     arch=$(uname -m)
-    [ -z /sbin/znet_cio_free ] || return 1
     [ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
 
+    require_binaries znet_cio_free grep sed seq readlink || return 1
+
     return 0
 }
 
index b51c4724ae1d5eb96bd1db1abd8ca521dfc927da..e285a7f322f837b1a6d63b394520b8ab2cff6620 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     [[ "$mount_needs" ]] && return 1
-    type -P biosdevname >/dev/null || return 1
+    require_binaries biosdevname || return 1
     return 0
 }
 
index e6e36907924291eaad2cb1bcdd20609d39373803..82a6515f89ee1b617aaf05db6e94e0075e3d2fac 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     [[ $hostonly ]] && {
-        [ -x "/bin/keyctl" ] || return 1
+        require_binaries keyctl uname || return 1
     }
 
     return 255
index 036f1c16b3910406a88174916b725ef8ac7282e7..badce3ce53a6a4f41d5c13bb9146c8e61b31fdc9 100755 (executable)
@@ -5,7 +5,7 @@
 # called by dracut
 check() {
     [[ $mount_needs ]] && return 1
-    if [[ -x $systemdutildir/systemd ]]; then
+    if require_binaries $systemdutildir/systemd; then
         SYSTEMD_VERSION=$($systemdutildir/systemd --version | { read a b a; echo $b; })
         (( $SYSTEMD_VERSION >= 198 )) && return 0
        return 255
index 2c3c9929be22fc679525256cc09b6629f5c58347..69346b2f1916baa1ffe91ddb7a84fcf0081caff5 100755 (executable)
@@ -3,9 +3,7 @@
 
 # called by dracut
 check() {
-    for cmd in tar gzip dd; do
-        command -v $cmd >/dev/null || return 1
-    done
+    require_binaries tar gzip dd bash || return 1
     return 255
 }