Add support for optional config file

This commit is contained in:
dalto 2023-01-28 12:10:56 -06:00
parent 149a83aa97
commit 0581b07aaa
4 changed files with 27 additions and 3 deletions

View File

@ -0,0 +1,7 @@
# This config file controls the automation provided by kernel-install-for-dracut
# When DRACUT_QUIET is set to true, dracut will operate with quiet flag set suppressing most output
#DRACUT_QUIET="false"
# When NO_FALLBACK is set to true, no fallback initrd will be generated
#NO_DRACUT_FALLBACK="false"

View File

@ -5,6 +5,9 @@ KERNEL_VERSION="$2"
BOOT_DIR_ABS="$3" BOOT_DIR_ABS="$3"
KERNEL_IMAGE="$4" KERNEL_IMAGE="$4"
# Read the optional config file for automation
[[ -f /etc/kernel-install-for-dracut.conf ]] && source /etc/kernel-install-for-dracut.conf
# If KERNEL_INSTALL_MACHINE_ID is defined but empty, BOOT_DIR_ABS is a fake directory. # If KERNEL_INSTALL_MACHINE_ID is defined but empty, BOOT_DIR_ABS is a fake directory.
# So, let's skip to create initrd. # So, let's skip to create initrd.
if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then
@ -54,7 +57,8 @@ case "$COMMAND" in
break break
fi fi
done done
dracut --hostonly --no-hostonly-cmdline -f ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION" [[ ${DRACUT_QUIET} == "true" ]] && DRACUT_EXTRA_PARAMS=" --quiet"
dracut --hostonly --no-hostonly-cmdline -f${DRACUT_EXTRA_PARAMS} ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION"
ret=$? ret=$?
;; ;;
remove) remove)

View File

@ -5,6 +5,12 @@ KERNEL_VERSION="$2"
BOOT_DIR_ABS="$3" BOOT_DIR_ABS="$3"
KERNEL_IMAGE="$4" KERNEL_IMAGE="$4"
# Read the optional config file for automation
[[ -f /etc/kernel-install-for-dracut.conf ]] && source /etc/kernel-install-for-dracut.conf
# Do nothing if the user has elected to omit the fallback initrd
[[ ${NO_DRACUT_FALLBACK} == "true" ]] && exit 0
# If KERNEL_INSTALL_MACHINE_ID is defined but empty, BOOT_DIR_ABS is a fake directory. # If KERNEL_INSTALL_MACHINE_ID is defined but empty, BOOT_DIR_ABS is a fake directory.
# So, let's skip to create initrd. # So, let's skip to create initrd.
if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then if ! [[ ${KERNEL_INSTALL_MACHINE_ID-x} ]]; then
@ -54,7 +60,8 @@ case "$COMMAND" in
break break
fi fi
done done
dracut -f ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION" [[ ${DRACUT_QUIET} == "true" ]] && DRACUT_EXTRA_PARAMS=" --quiet"
dracut --no-hostonly --force${DRACUT_EXTRA_PARAMS} ${noimageifnotneeded:+--noimageifnotneeded} "$BOOT_DIR_ABS/$INITRD" "$KERNEL_VERSION"
ret=$? ret=$?
;; ;;
remove) remove)

View File

@ -26,6 +26,9 @@ INITRD_OPTIONS_SHIFT=4
[ "$KERNEL_INSTALL_LAYOUT" = "bls" ] || exit 0 [ "$KERNEL_INSTALL_LAYOUT" = "bls" ] || exit 0
# Read the optional config file for automation
[[ -f /etc/kernel-install-for-dracut.conf ]] && source /etc/kernel-install-for-dracut.conf
MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID" MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
ENTRY_TOKEN="$KERNEL_INSTALL_ENTRY_TOKEN" ENTRY_TOKEN="$KERNEL_INSTALL_ENTRY_TOKEN"
BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT" BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT"
@ -43,7 +46,7 @@ case "$COMMAND" in
echo "Removing $BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION-fallback*.conf" echo "Removing $BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION-fallback*.conf"
exec rm -f \ exec rm -f \
"$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION-fallback.conf" \ "$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION-fallback.conf" \
"$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION-fallback+"*".conf" "$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION-fallback+"*".conf" 2> /dev/null || true
;; ;;
add) add)
;; ;;
@ -52,6 +55,9 @@ case "$COMMAND" in
;; ;;
esac esac
# Do nothing if the user has elected to omit the fallback initrd
[[ ${NO_DRACUT_FALLBACK} == "true" ]] && exit 0
if [ -r /etc/os-release ]; then if [ -r /etc/os-release ]; then
# shellcheck source=/dev/null # shellcheck source=/dev/null
. /etc/os-release . /etc/os-release