refind: add hook to update refind.conf on changing kernel

This commit is contained in:
Doan Tran Cong Danh 2019-11-09 16:02:49 +07:00 committed by Juan RP
parent 9f37d4514f
commit 0f7689906e
4 changed files with 112 additions and 2 deletions

View File

@ -0,0 +1,54 @@
#!/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
# Default refind.conf
REFIND_CONF="${REFIND_CONF:-/boot/EFI/refind/refind.conf}"
zrefind_dir="${REFIND_CONF%/*}"
mkdir -p "$zrefind_dir"
touch "$REFIND_CONF"
zefi_mountpoint=$(df -P "$REFIND_CONF" | awk 'NR==2{print $6}')
zicon="${zrefind_dir#$zefi_mountpoint}/icons/os_void.png"
mkedscript() {
zversion=$(echo $VERSION | sed 's/[.]/[.]/g')
zexpr='^menuentry "Void Linux '"$zversion"'" {$'
if grep -q "$zexpr" "$REFIND_CONF"; then
# Do not merge into /expr/,/}/d, it doesn't work
printf '%s\n' "/$zexpr/" '.,/}/d'
fi
cat <<EOF
1
/^menuentry /
i
menuentry "Void Linux $VERSION" {
icon $zicon
volume "Void Linux"
loader /vmlinuz-$VERSION
initrd /initramfs-$VERSION.img
options "$OPTIONS"
}
.
EOF
if ! grep -q '^timeout ' "$REFIND_CONF"; then
printf '%s\n' 1i "timeout 20" .
fi
echo wq
}
mkedscript | ed "$REFIND_CONF" >/dev/null
exit 0

View File

@ -0,0 +1,28 @@
#!/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
# Default refind.conf
REFIND_CONF="${REFIND_CONF:-/boot/EFI/refind/refind.conf}"
[ -f "$REFIND_CONF" ] || exit 0
tmpfile=$(mktemp /tmp/refind.XXXXXXX)
zversion=$(echo $VERSION | sed 's/[.]/[.]/g')
sed "/^menuentry \"Void Linux $zversion\" [{]\$/,/[}]/d" "$REFIND_CONF" >"$tmpfile"
if ! cmp -s "$REFIND_CONF" "$tmpfile"; then
mv "$tmpfile" "$REFIND_CONF"
else
rm -f "$tmpfile"
fi

View File

@ -0,0 +1,22 @@
#!/bin/sh
# Change this line to 1 to update refind conf whenever new kernel is installed
UPDATE_REFIND_CONF=0
# refind.conf location
# It usually stay in
#
# /boot/EFI/refind/refind.conf
# if you use all default configuration and EFI partition mounted to /boot
# /boot/efi/EFI/refind/refind.conf
# if using default configuration and EFI partition mounted to /boot/efi
# /boot/EFI/BOOT/refind.conf
# if you run refind-install ==usedefault and EFI partition mounted to /boot
# /boot/efi/EFI/BOOT/refind.conf
# likewise, EFI mounted to /boot/efi
# /efi/EFI/refind/refind.conf
# /eif/EFI/BOOT/refind.conf
REFIND_CONF=/boot/EFI/refind/refind.conf
# addition kernel cmdline
OPTIONS="quiet"

View File

@ -1,15 +1,16 @@
# Template file for 'refind'
pkgname=refind
version=0.11.4
revision=1
revision=2
makedepends="gnu-efi-libs git"
depends="bash dosfstools efibootmgr"
short_desc="An EFI boot manager utility"
short_desc="EFI boot manager utility"
maintainer="Julio Galvan <juliogalvan@protonmail.com>"
license="GPL-3.0-only, BSD-3-Clause"
homepage="https://sourceforge.net/projects/refind/"
distfiles="${SOURCEFORGE_SITE}/refind/refind-src-${version}.tar.gz"
checksum=39baf140603951da098238c1cbf4176fdd7d4a45fab0399e9985ad7368034dae
conf_files="/etc/default/refind-kernel-hook.conf"
case "$XBPS_TARGET_MACHINE" in
x86_64|i686|aarch64) ;;
@ -85,4 +86,9 @@ do_install() {
vmkdir etc/refind.d
vcopy keys /etc/refind.d/
vinstall "${FILESDIR}/refind-kernel-hook.conf" 644 etc/default
vinstall ${FILESDIR}/kernel.post-install 744 \
etc/kernel.d/post-install 50-refind
vinstall ${FILESDIR}/kernel.post-remove 744 \
etc/kernel.d/post-remove 50-refind
}