Skip to content

Commit

Permalink
refind: rewrite kernel post-install hook
Browse files Browse the repository at this point in the history
- refind-install only supports installing into
{/boot,/boot/efi,/efi}/EFI/{BOOT,refind}/refind.conf, there're no point
trying to fiddling with anything else.

- That configuration file should always exist, simplify all logic behind
  that decision.
  • Loading branch information
sgn committed Aug 6, 2020
1 parent 4bd83bc commit 53bdcc8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
44 changes: 21 additions & 23 deletions srcpkgs/refind/files/kernel.post-install
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,39 @@ if [ "z$UPDATE_REFIND_CONF" != "z1" ]; then
fi

# Default refind.conf
: "${REFIND_CONF:=/boot/EFI/refind/refind.conf}"

zrefind_dir="${REFIND_CONF%/*}"
mkdir -p "$zrefind_dir"
touch "$REFIND_CONF"
: "${REFIND_CONF:=boot/EFI/refind/refind.conf}"
REFIND_CONF=${REFIND_CONF#/}
[ -n "${REFIND_CONF}" ] || exit 0

# refind-install only supports those two paths
refind_dir=
case "$REFIND_CONF" in
*/EFI/[Bb][Oo][Oo][Tt]/refind.conf)
refind_dir="/EFI/BOOT" ;;
*/EFI/refind/refind.conf)
refind_dir="/EFI/refind" ;;
*)
echo >&2 "unsupported \$REFIND_CONF: $REFIND_CONF"
exit 1 ;;
esac

tmpfile=$(mktemp /tmp/refind.XXXXXXX)

zefi_mountpoint=$(df -P "$REFIND_CONF" | awk 'NR==2{print $6}')
zicon="${zrefind_dir#$zefi_mountpoint}/icons/os_void.png"
zversion=$(echo "$VERSION" | sed 's/[.]/[.]/g')

zentry=$(cat <<EOF
(
cat <<EOF
menuentry "Void Linux $VERSION" {
icon $zicon
icon $refind_dir/icons/os_void.png
volume "Void Linux"
loader /vmlinuz-$VERSION
initrd /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"
# Clean itself if this is force reconfigure
sed "/^menuentry \"Void Linux $zversion\" [{]\$/,/[}]/d" <"$REFIND_CONF"
) >"$tmpfile"

mv "$tmpfile" "$REFIND_CONF"

Expand Down
2 changes: 1 addition & 1 deletion srcpkgs/refind/template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Template file for 'refind'
pkgname=refind
version=0.12.0
revision=1
revision=2
archs="x86_64* i686* aarch64*"
makedepends="gnu-efi-libs"
depends="bash dosfstools efibootmgr"
Expand Down

0 comments on commit 53bdcc8

Please sign in to comment.