diff --git a/dracut-init.sh b/dracut-init.sh index 3d9afad7d1..ce4a3819cc 100755 --- a/dracut-init.sh +++ b/dracut-init.sh @@ -999,11 +999,13 @@ check_module() { [[ " $mods_to_load " == *\ $_mod\ * ]] && return 0 [[ " $mods_checked_as_dep " == *\ $_mod\ * ]] && return 1 - # This should never happen, but... - [[ -d $_moddir ]] || return 1 - [[ $2 ]] || mods_checked_as_dep+=" $_mod " + [[ -d $_moddir ]] || { + dwarn "Module '$_mod' cannot be installed without a source directory, '$_moddir'." + return 1 + } + if [[ " $omit_dracutmodules " == *\ $_mod\ * ]]; then ddebug "Module '$_mod' will not be installed, because it's in the list to be omitted!" return 1 diff --git a/modules.d/00_sh/module-setup.sh b/modules.d/00_sh/module-setup.sh new file mode 100644 index 0000000000..5dddf7bb01 --- /dev/null +++ b/modules.d/00_sh/module-setup.sh @@ -0,0 +1,33 @@ +#!/bin/bash +# This file is part of dracut. +# SPDX-License-Identifier: GPL-2.0-or-later + +# Prerequisite check(s) for module. +check() { + + local shells _shell _s + + # Assure a command shell. + [[ " $add_dracutmodules $force_add_dracutmodules " == @(*\ dash\ *|*\ bash\ *|*\ mksh\ *|*\ busybox\ *) ]] || { + shells='dash bash mksh busybox' + _shell=$(realpath -e /bin/sh) + _shell=${_shell##*/} + { [[ "$_shell" ]] && check_module "$_shell"; } || { + for _s in $_shell ${shells/$_shell/}; do + check_module "$_s" || continue + # We only want to return 255 since this is a meta module. + return 255 + done + dfatal "One of '$shells' must be made available." + exit 1 + } + } + return 1 +} + +# Module dependency requirements. +depends() { + + return 0 + +} diff --git a/modules.d/00bash/module-setup.sh b/modules.d/00bash/module-setup.sh index 89ef65414b..9d7038c8c6 100755 --- a/modules.d/00bash/module-setup.sh +++ b/modules.d/00bash/module-setup.sh @@ -24,8 +24,21 @@ depends() { # Install the required file(s) and directories for the module in the initramfs. install() { + local version ver0 ver1 + inst /bin/bash + # local - (available since bash-4.4 2016-09-15) automates the + # restoration of local xtrace & other set options. + IFS=' ' read -r -a version <<< "$(command "$initdir"/bin/bash --version)" + IFS=. read -r ver0 ver1 _ <<< "${version[3]}" + if ((${ver0}${ver1} < 44)); then + dfatal "Installed Bash ${version[3]} ${version[4]}. + At least Bash 4.4 is required for proper xtrace logging + when Bash is the initramfs command shell." + exit 1 + fi + # Prefer bash as default shell if no other shell is preferred. [[ -L $initdir/bin/sh ]] || ln -sf bash "${initdir}/bin/sh" diff --git a/modules.d/80test-root/module-setup.sh b/modules.d/80test-root/module-setup.sh index 24605c51f1..a91f936dc6 100755 --- a/modules.d/80test-root/module-setup.sh +++ b/modules.d/80test-root/module-setup.sh @@ -22,6 +22,7 @@ install() { inst_binary "${dracutbasedir}/dracut-util" "/usr/bin/dracut-util" ln -s dracut-util "${initdir}/usr/bin/dracut-getarg" ln -s dracut-util "${initdir}/usr/bin/dracut-getargs" + ln -s dash /bin/sh inst_multiple -o plymouth } diff --git a/modules.d/99base/module-setup.sh b/modules.d/99base/module-setup.sh index 54b0deb914..362d66d170 100755 --- a/modules.d/99base/module-setup.sh +++ b/modules.d/99base/module-setup.sh @@ -24,11 +24,6 @@ install() { ln -s dracut-util "${initdir}/usr/bin/dracut-getarg" ln -s dracut-util "${initdir}/usr/bin/dracut-getargs" - if [ ! -e "${initdir}/bin/sh" ]; then - inst_multiple bash - (ln -s bash "${initdir}/bin/sh" || :) - fi - # add common users in /etc/passwd, it will be used by nfs/ssh currently # use password for hostonly images to facilitate secure sulogin in emergency console [[ $hostonly ]] && pwshadow='x'