void-packages/srcpkgs/systemd-boot/files/kernel.d/systemd-boot.post-install

99 lines
1.9 KiB
Bash

#!/bin/sh
#
# Kernel hook for systemd-boot.
#
# Arguments passed to this script: $1 pkgname, $2 version.
#
PKGNAME="$1"
VERSION="$2"
. "$ROOTDIR/etc/default/systemd-boot"
if [ "$SYSTEMD_BOOT_DISABLE" ]; then
exit 0
fi
if ! bootctl is-installed >/dev/null; then
echo "systemd-boot is not installed to the ESP"
echo "run 'bootctl install' to install it"
exit 0
fi
BOOT="${BOOT:-/boot}"
ESP="${ESP:-"$BOOT"}"
BOOT="$ROOTDIR/$BOOT"
ESP="$ROOTDIR/$ESP"
[ -d "$ESP" ] || exit 0
ARCH="$(xbps-uhelper arch)"
# EFI_ARCH is the identifier from the UEFI specification
case "$ARCH" in
x86_64*) EFI_ARCH="x64";;
i686*) EFI_ARCH="ia32";;
aarch64*) EFI_ARCH="aa64";;
esac
entries="$ESP/loader/entries"
name="void-$ARCH-$VERSION"
entry="$entries/$name.conf"
LINUX="vmlinuz-${VERSION}"
if [ ! -f "$ESP/$LINUX" ]; then
LINUX="vmlinux-${VERSION}"
if [ ! -f "$ESP/$LINUX" ]; then
echo "Failed to find kernel at $ESP/vmlinuz-${VERSION} or $ESP/vmlinux-${VERSION}, aborting"
exit 1
fi
fi
INITRD="initramfs-${VERSION}.img"
if [ ! -f "$ESP/$INITRD" ]; then
echo "Failed to find initramfs at $ESP/$INITRD, aborting"
exit 1
fi
# check if user provided options in /etc/default/systemd-boot
if [ -z "$CMDLINE" ]; then
# get UUID from fstab
CMDLINE="$( awk ' /^[[:space:]]*[^[:space:]#]+/ {
DEVICE=$1
MOUNTPOINT=$2
FSTYPE=$3
if (MOUNTPOINT == "/")
{
print "rootfstype="FSTYPE, "root="DEVICE
exit
}
}' "$ROOTDIR/etc/fstab"
)"
if [ -z "$CMDLINE" ]; then
echo "Failed to determine root device, aborting"
exit 1
fi
CMDLINE="${CMDLINE} quiet rw"
fi
mkdir -p "$entries"
cat <<-EOF > "$entry"
title Void Linux $ARCH $VERSION
sort-key void
version $VERSION
options $CMDLINE
linux $LINUX
initrd $INITRD
EOF
if [ "$EFI_ARCH" ]; then
cat <<-EOF >> "$entry"
architecture $EFI_ARCH
EOF
fi
echo "Created systemd-boot entry $entry with options '$CMDLINE'"