Factor out all the "type -V" commands
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.
(cherry picked from commit 30e6e809ed
)
parent
e2b5b450e7
commit
da3dacfa5e
|
@ -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() {
|
||||
|
@ -1055,7 +1100,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
|
||||
|
@ -1081,7 +1126,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
|
||||
|
@ -1105,7 +1150,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
|
||||
|
@ -1126,7 +1171,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
|
||||
|
@ -1147,7 +1192,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
|
||||
|
@ -1168,7 +1213,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
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
check() {
|
||||
[ -x /bin/bash ]
|
||||
require_binaries /bin/bash
|
||||
}
|
||||
|
||||
depends() {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
check() {
|
||||
[[ "$mount_needs" ]] && return 1
|
||||
[ -x /sbin/bootchartd ] || return 1
|
||||
require_binaries /sbin/bootchartd || return 1
|
||||
return 255
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
check() {
|
||||
[ -x /bin/dash ]
|
||||
require_binaries /bin/dash
|
||||
}
|
||||
|
||||
depends() {
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
check() {
|
||||
[[ "$mount_needs" ]] && return 1
|
||||
[ -x $systemdutildir/systemd-bootchart ] || return 1
|
||||
require_binaries $systemdutildir/systemd-bootchart || return 1
|
||||
return 255
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
check() {
|
||||
type -P capsh >/dev/null 2>&1
|
||||
require_binaries capsh
|
||||
}
|
||||
|
||||
depends() {
|
||||
|
@ -11,9 +11,13 @@ depends() {
|
|||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
# Peter Jones <pjones@redhat.com>
|
||||
|
||||
check() {
|
||||
[[ -x /usr/bin/keyctl ]] || return 1
|
||||
require_binaries keyctl || return 1
|
||||
|
||||
# do not include module in hostonly mode,
|
||||
# if no keys are present
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
check() {
|
||||
type -P busybox >/dev/null || return 1
|
||||
require_binaries busybox || return 1
|
||||
|
||||
return 255
|
||||
}
|
||||
|
|
|
@ -5,9 +5,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
|
||||
}
|
||||
|
|
|
@ -5,12 +5,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
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
# module-setup for url-lib
|
||||
|
||||
check() {
|
||||
command -v curl >/dev/null || return 1
|
||||
require_binaries curl || return 1
|
||||
return 255
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
check() {
|
||||
[[ "$mount_needs" ]] && return 1
|
||||
type -P plymouthd >/dev/null && type -P plymouth >/dev/null
|
||||
require_binaries plymouthd plymouth
|
||||
}
|
||||
|
||||
depends() {
|
||||
|
|
|
@ -6,7 +6,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
|
||||
|
|
|
@ -5,7 +5,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
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
check() {
|
||||
type -P dmsetup >/dev/null || return 1
|
||||
require_binaries dmsetup || return 1
|
||||
return 255
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,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
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
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
|
||||
|
|
|
@ -5,7 +5,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
|
||||
|
|
|
@ -5,7 +5,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
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
# GPG support is optional
|
||||
check() {
|
||||
type -P gpg >/dev/null || return 1
|
||||
require_binaries gpg || return 1
|
||||
|
||||
return 255
|
||||
}
|
||||
|
|
|
@ -1,19 +1,24 @@
|
|||
#!/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
|
||||
}
|
||||
|
||||
depends() {
|
||||
echo crypt
|
||||
echo crypt
|
||||
}
|
||||
|
||||
installkernel() {
|
||||
instmods loop
|
||||
instmods loop
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
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
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
check() {
|
||||
local _arch=$(uname -m)
|
||||
[ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
|
||||
require_binaries normalize_dasd_arg || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
check() {
|
||||
local _arch=$(uname -m)
|
||||
[ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
|
||||
require_binaries grep sed seq
|
||||
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -3,10 +3,7 @@
|
|||
# ex: ts=8 sw=4 sts=4 et filetype=sh
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,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.
|
||||
|
|
|
@ -5,7 +5,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.
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
|
||||
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
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
# fixme: assume user is root
|
||||
|
||||
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!"
|
||||
|
|
|
@ -5,7 +5,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 \
|
||||
|
|
|
@ -6,6 +6,8 @@ check() {
|
|||
arch=$(uname -m)
|
||||
[ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
|
||||
|
||||
require_binaries zfcp_cio_free grep sed seq || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ check() {
|
|||
arch=$(uname -m)
|
||||
[ "$arch" = "s390" -o "$arch" = "s390x" ] || return 1
|
||||
|
||||
require_binaries znet_cio_free grep sed seq readlink || return 1
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
check() {
|
||||
[[ "$mount_needs" ]] && return 1
|
||||
type -P biosdevname >/dev/null || return 1
|
||||
require_binaries biosdevname || return 1
|
||||
return 0
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
check() {
|
||||
[[ $hostonly ]] && {
|
||||
[ -x "/bin/keyctl" ] || return 1
|
||||
require_binaries keyctl uname || return 1
|
||||
}
|
||||
|
||||
return 255
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
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
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
# module-setup for img-lib
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue