void-packages/srcpkgs/refind/files/kernel.post-install

54 lines
1.0 KiB
Bash
Executable File

#!/bin/sh
#
# Kernel hook for refind.
#
# Arguments passed to this script: $1 pkgname, $2 version.
#
PKGNAME="$1"
VERSION="$2"
. "${ROOTDIR}/etc/default/refind-kernel-hook.conf"
if [ "z$UPDATE_REFIND_CONF" != "z1" ]; then
exit 0;
fi
: "${REFIND_CONF:=boot/EFI/refind/refind.conf}"
REFIND_CONF="${REFIND_CONF#/}"
mkdir -p "${REFIND_CONF%/*}"
touch "$REFIND_CONF"
tmpfile=$(mktemp /tmp/refind.XXXXXXX)
: "${REFIND_LABEL:="Void Linux"}"
: "${REFIND_BOOT_PREFIX:=""}"
zversion=$(echo "$VERSION" | sed 's/[.]/[.]/g')
zentry=$(cat <<EOF
menuentry "Void Linux $VERSION" {
volume "$REFIND_LABEL"
loader $REFIND_BOOT_PREFIX/vmlinuz-$VERSION
initrd $REFIND_BOOT_PREFIX/initramfs-$VERSION.img
options "$OPTIONS"
}
EOF
)
<"$REFIND_CONF" \
sed "/^menuentry \"Void Linux $zversion\" [{]\$/,/[}]/d" |
awk -v "entry=$zentry" '
/^timeout / {t=1}
/^menuentry / && !x {print entry; x=1}
1
END {
if (!x) {print entry}
if (!t) {print "timeout 20"}
}
' \
>"$tmpfile"
mv "$tmpfile" "$REFIND_CONF"
exit 0