# 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() {
. $_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
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
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
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
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
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
# called by dracut
check() {
- [ -x /bin/bash ]
+ require_binaries /bin/bash
}
# called by dracut
# called by dracut
check() {
[[ "$mount_needs" ]] && return 1
- [ -x /sbin/bootchartd ] || return 1
+ require_binaries /sbin/bootchartd || return 1
return 255
}
# called by dracut
check() {
- [ -x /bin/dash ]
+ require_binaries /bin/dash
}
# called by dracut
# called by dracut
check() {
[[ "$mount_needs" ]] && return 1
- [ -x $systemdutildir/systemd-bootchart ] || return 1
+ require_binaries $systemdutildir/systemd-bootchart || return 1
return 255
}
# called by dracut
check() {
- type -P capsh >/dev/null 2>&1
+ require_binaries capsh
}
# called by dracut
# 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
}
# 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
# called by dracut
check() {
- type -P busybox >/dev/null || return 1
+ require_binaries busybox || return 1
return 255
}
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
}
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
}
# called by dracut
check() {
- command -v curl >/dev/null || return 1
+ require_binaries curl || return 1
return 255
}
# 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
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
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
# called by dracut
check() {
- type -P dmsetup >/dev/null || return 1
+ require_binaries dmsetup || return 1
return 255
}
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
# 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
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
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
# GPG support is optional
# called by dracut
check() {
- type -P gpg >/dev/null || return 1
+ require_binaries gpg || return 1
return 255
}
+#!/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
}
# 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
# 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
}
check() {
local _arch=$(uname -m)
[ "$_arch" = "s390" -o "$_arch" = "s390x" ] || return 1
+ require_binaries grep sed seq
return 0
}
# 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
}
# 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
}
# 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
}
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.
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.
# 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
# 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!"
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 \
# 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
}
# 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
}
# 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
}
# called by dracut
check() {
[[ "$mount_needs" ]] && return 1
- type -P biosdevname >/dev/null || return 1
+ require_binaries biosdevname || return 1
return 0
}
# called by dracut
check() {
[[ $hostonly ]] && {
- [ -x "/bin/keyctl" ] || return 1
+ require_binaries keyctl uname || return 1
}
return 255
# 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
# 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
}