summaryrefslogtreecommitdiff
path: root/src/kernel-install
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2021-03-16 17:02:59 +0100
committerнаб <nabijaczleweli@nabijaczleweli.xyz>2021-12-08 13:43:19 +0100
commit9e82a74cb0f08a288f9db228a0b5bec8a7188cdb (patch)
tree6401cc25fcd294e7f98da116a77851c37c3eae35 /src/kernel-install
parentefea45f19c506dd562ca1192ae7c1478f6063929 (diff)
downloadsystemd-9e82a74cb0f08a288f9db228a0b5bec8a7188cdb.tar.gz
kernel-install: export $BOOT_ROOT and use it in downstreams
The previous approach, to strip "$MACHINE_ID/$KERNEL_VERSION" from the end, is pretty bad and encourages this for users, which makes them inflexible to this being modified locally
Diffstat (limited to 'src/kernel-install')
-rw-r--r--src/kernel-install/00-entry-directory.install7
-rw-r--r--src/kernel-install/90-loaderentry.install12
-rwxr-xr-xsrc/kernel-install/kernel-install33
3 files changed, 29 insertions, 23 deletions
diff --git a/src/kernel-install/00-entry-directory.install b/src/kernel-install/00-entry-directory.install
index ab616b2823..5576179d52 100644
--- a/src/kernel-install/00-entry-directory.install
+++ b/src/kernel-install/00-entry-directory.install
@@ -32,10 +32,9 @@ if [[ $COMMAND != add ]]; then
exit 0
fi
-# If the boot dir exists (e.g. $ESP/<machine-id>),
-# create the entry directory ($ESP/<machine-id>/<kernel-version>).
-# This is the only function of this plugin.
-MACHINE_ID_DIR="${ENTRY_DIR_ABS%/*}"
+# Create the entry directory if its parent exists ‒
+# this is an administrative decision and the only function of this plugin.
+MACHINE_ID_DIR="$KERNEL_INSTALL_BOOT_ROOT/$KERNEL_INSTALL_MACHINE_ID"
if ! [ -d "$MACHINE_ID_DIR" ]; then
exit 0
fi
diff --git a/src/kernel-install/90-loaderentry.install b/src/kernel-install/90-loaderentry.install
index 9f0d61cb77..a4dba1396d 100644
--- a/src/kernel-install/90-loaderentry.install
+++ b/src/kernel-install/90-loaderentry.install
@@ -32,14 +32,14 @@ if ! [[ -d "$ENTRY_DIR_ABS" ]]; then
exit 0
fi
-MACHINE_ID=$KERNEL_INSTALL_MACHINE_ID
+MACHINE_ID="$KERNEL_INSTALL_MACHINE_ID"
+BOOT_ROOT="$KERNEL_INSTALL_BOOT_ROOT"
-BOOT_ROOT=${ENTRY_DIR_ABS%/$MACHINE_ID/$KERNEL_VERSION}
-BOOT_MNT=$(stat -c %m $BOOT_ROOT)
-if [[ $BOOT_MNT == '/' ]]; then
- ENTRY_DIR=$ENTRY_DIR_ABS
+BOOT_MNT="$(stat -c %m "$BOOT_ROOT")"
+if [[ "$BOOT_MNT" == '/' ]]; then
+ ENTRY_DIR="$ENTRY_DIR_ABS"
else
- ENTRY_DIR=${ENTRY_DIR_ABS#$BOOT_MNT}
+ ENTRY_DIR="${ENTRY_DIR_ABS#$BOOT_MNT}"
fi
if [[ $COMMAND == remove ]]; then
diff --git a/src/kernel-install/kernel-install b/src/kernel-install/kernel-install
index 89f0074417..9999b86ed8 100755
--- a/src/kernel-install/kernel-install
+++ b/src/kernel-install/kernel-install
@@ -93,21 +93,28 @@ fi
[ -z "$MACHINE_ID" ] && [ -f /etc/machine-id ] && [ "$(stat -fc %T /etc/machine-id)" != "tmpfs" ] && read -r MACHINE_ID < /etc/machine-id
[ -z "$MACHINE_ID" ] && MACHINE_ID="Default"
-if [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
- ENTRY_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
-elif [[ -d /boot/loader/entries ]] || [[ -d /boot/$MACHINE_ID ]]; then
- ENTRY_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
-elif [[ -d /boot/efi/loader/entries ]] || [[ -d /boot/efi/$MACHINE_ID ]]; then
- ENTRY_DIR_ABS="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
-elif mountpoint -q /efi; then
- ENTRY_DIR_ABS="/efi/$MACHINE_ID/$KERNEL_VERSION"
-elif mountpoint -q /boot/efi; then
- ENTRY_DIR_ABS="/boot/efi/$MACHINE_ID/$KERNEL_VERSION"
-else
- ENTRY_DIR_ABS="/boot/$MACHINE_ID/$KERNEL_VERSION"
-fi
+[ -z "$BOOT_ROOT" ] && for suff in "$MACHINE_ID" "Default" "loader/entries"; do
+ for pref in "/efi" "/boot/efi" "/boot"; do
+ if [ -d "$pref/$suff" ]; then
+ BOOT_ROOT="$pref"
+ break 2
+ fi
+ done
+done
+
+[ -z "$BOOT_ROOT" ] && for pref in "/efi" "/boot/efi"; do
+ if mountpoint -q "$pref"; then
+ BOOT_ROOT="$pref"
+ break
+ fi
+done
+[ -z "$BOOT_ROOT" ] && BOOT_ROOT="/boot"
+
+
+ENTRY_DIR_ABS="$BOOT_ROOT/$MACHINE_ID/$KERNEL_VERSION"
export KERNEL_INSTALL_MACHINE_ID="$MACHINE_ID"
+export KERNEL_INSTALL_BOOT_ROOT="$BOOT_ROOT"
ret=0