kernel-install: Add fallback to "Linux" if no machine-id is found

This allows kernel-install to be used by image builders such as mkosi
which don't have a machine-id available when they call kernel-install.
This commit is contained in:
Daan De Meyer 2020-08-06 21:56:36 +01:00
parent 31e57550b5
commit 6f77906ad3
2 changed files with 6 additions and 13 deletions

View File

@ -211,7 +211,9 @@
<filename>/etc/machine-id</filename>
</term>
<listitem>
<para>The content of the file specifies the machine identification <replaceable>MACHINE-ID</replaceable>.</para>
<para>The content of this file specifies the machine identification
<replaceable>MACHINE-ID</replaceable>. If it cannot read <filename>/etc/machine-id</filename>,
kernel-install will use "Linux" as the machine ID instead.</para>
</listitem>
</varlistentry>
<varlistentry>

View File

@ -87,6 +87,8 @@ KERNEL_IMAGE="$2"
if [[ -f /etc/machine-id ]]; then
read MACHINE_ID < /etc/machine-id
else
MACHINE_ID="Linux"
fi
if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
@ -94,10 +96,7 @@ if [[ ! $COMMAND ]] || [[ ! $KERNEL_VERSION ]]; then
exit 1
fi
if ! [[ $MACHINE_ID ]]; then
ENTRY_DIR_ABS=$(mktemp -d /tmp/kernel-install.XXXXX) || exit 1
trap "rm -rf '$ENTRY_DIR_ABS'" EXIT INT QUIT PIPE
elif [[ -d /efi/loader/entries ]] || [[ -d /efi/$MACHINE_ID ]]; then
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"
@ -146,14 +145,6 @@ case $COMMAND in
((ret+=$x))
fi
done
if ! [[ $MACHINE_ID ]] && ! rmdir "$ENTRY_DIR_ABS"; then
echo "Warning: In kernel-install plugins, requiring ENTRY_DIR_ABS to be preset is deprecated." >&2
echo " All plugins should not put anything in ENTRY_DIR_ABS if the environment" >&2
echo " variable KERNEL_INSTALL_MACHINE_ID is empty." >&2
rm -rf "$ENTRY_DIR_ABS"
((ret+=$?))
fi
;;
remove)