diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-07-01 10:58:01 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2022-07-06 16:33:11 +0200 |
commit | 91199185b1449edb884dd2e85c6486027c440a34 (patch) | |
tree | bcdd22e0b9923b07d6d4d955902cad3c4ebbbee5 /src | |
parent | 035f8acdf737ee5e0c49feaa14dd8cfcea0ffa5f (diff) | |
download | systemd-91199185b1449edb884dd2e85c6486027c440a34.tar.gz |
kernel-install: allow overriding the path to config files
It's pretty hard to write tests without this. I started out by adding separate
variables for each of the files we read, but there's a bunch, and in practice
it's good enough to just override the directory.
Diffstat (limited to 'src')
-rw-r--r-- | src/kernel-install/90-loaderentry.install | 14 | ||||
-rwxr-xr-x | src/kernel-install/kernel-install.in | 14 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/kernel-install/90-loaderentry.install b/src/kernel-install/90-loaderentry.install index ee55965110..b700a7b2a6 100644 --- a/src/kernel-install/90-loaderentry.install +++ b/src/kernel-install/90-loaderentry.install @@ -65,7 +65,11 @@ fi SORT_KEY="$IMAGE_ID" [ -z "$SORT_KEY" ] && SORT_KEY="$ID" -if [ -f /etc/kernel/cmdline ]; then +if [ -n "$KERNEL_INSTALL_CONF_ROOT" ]; then + if [ -f "$KERNEL_INSTALL_CONF_ROOT/cmdline" ]; then + BOOT_OPTIONS="$(tr -s "$IFS" ' ' <"$KERNEL_INSTALL_CONF_ROOT/cmdline")" + fi +elif [ -f /etc/kernel/cmdline ]; then BOOT_OPTIONS="$(tr -s "$IFS" ' ' </etc/kernel/cmdline)" elif [ -f /usr/lib/kernel/cmdline ]; then BOOT_OPTIONS="$(tr -s "$IFS" ' ' </usr/lib/kernel/cmdline)" @@ -83,10 +87,12 @@ if [ "$ENTRY_TOKEN" = "$MACHINE_ID" ]; then BOOT_OPTIONS="$BOOT_OPTIONS systemd.machine_id=$MACHINE_ID" fi -if [ -f /etc/kernel/tries ]; then - read -r TRIES </etc/kernel/tries +TRIES_FILE="${KERNEL_INSTALL_CONF_ROOT:-/etc/kernel}/tries" + +if [ -f "$TRIES_FILE" ]; then + read -r TRIES <"$TRIES_FILE" if ! echo "$TRIES" | grep -q '^[0-9][0-9]*$'; then - echo "/etc/kernel/tries does not contain an integer." >&2 + echo "$TRIES_FILE does not contain an integer." >&2 exit 1 fi LOADER_ENTRY="$BOOT_ROOT/loader/entries/$ENTRY_TOKEN-$KERNEL_VERSION+$TRIES.conf" diff --git a/src/kernel-install/kernel-install.in b/src/kernel-install/kernel-install.in index 044ba9f6f2..96595fa295 100755 --- a/src/kernel-install/kernel-install.in +++ b/src/kernel-install/kernel-install.in @@ -108,7 +108,9 @@ initrd_generator= _MACHINE_ID_SAVED="$MACHINE_ID" _BOOT_ROOT_SAVED="$BOOT_ROOT" -if [ -f "/etc/kernel/install.conf" ]; then +if [ -n "$KERNEL_INSTALL_CONF_ROOT" ]; then + install_conf="$KERNEL_INSTALL_CONF_ROOT/install.conf" +elif [ -f "/etc/kernel/install.conf" ]; then install_conf="/etc/kernel/install.conf" elif [ -f "/usr/lib/kernel/install.conf" ]; then install_conf="/usr/lib/kernel/install.conf" @@ -116,7 +118,7 @@ else install_conf= fi -if [ -n "$install_conf" ]; then +if [ -f "$install_conf" ]; then [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && echo "Reading $install_conf…" # shellcheck source=/dev/null . "$install_conf" @@ -171,10 +173,12 @@ fi # $BOOT where we want to place the kernel/initrd and related resources, as well # for naming the .conf boot loader spec entry. Typically this is just the # machine ID, but it can be anything else, too, if we are told so. -if [ -z "$ENTRY_TOKEN" ] && [ -f /etc/kernel/entry-token ]; then - read -r ENTRY_TOKEN </etc/kernel/entry-token +ENTRY_TOKEN_FILE="${KERNEL_INSTALL_CONF_ROOT:-/etc/kernel}/entry-token" + +if [ -z "$ENTRY_TOKEN" ] && [ -f "$ENTRY_TOKEN_FILE" ]; then + read -r ENTRY_TOKEN <"$ENTRY_TOKEN_FILE" [ "$KERNEL_INSTALL_VERBOSE" -gt 0 ] && \ - echo "entry-token \"$ENTRY_TOKEN\" acquired from /etc/kernel/entry-token" + echo "entry-token \"$ENTRY_TOKEN\" acquired from $ENTRY_TOKEN_FILE" fi if [ -z "$ENTRY_TOKEN" ]; then # If not configured explicitly, then use a few candidates: the machine ID, |