void-packages/srcpkgs/u-boot-menu/files/kernel.d/extlinux
2025-06-08 19:51:29 +02:00

72 lines
1.7 KiB
Bash

#!/bin/sh
header() {
printf "TIMEOUT %s\n" "${TIMEOUT}" > "${OUTFILE}"
printf "DEFAULT entry0\n" >> "${OUTFILE}"
printf "MENU TITLE Boot menu\n" >> "${OUTFILE}"
}
get_bootpath() {
echo "${1}" | sed "s#${BOOTPART}/#/#"
}
add_kernel() {
ver="${1}"
suffix="${2}"
kernel=$(get_bootpath "/boot/vmlinu${suffix}-${ver}")
initrd=$(get_bootpath "/boot/initramfs-${ver}.img")
devicetreedir=$(get_bootpath "/boot/dtbs/dtbs-${ver}")
fdt=$(get_bootpath "/boot/dtbs/dtbs-${ver}/${DTBPATH}")
cmdline="${CMDLINE}"
printf "\nLABEL entry%s\n" "${ENTRY}" >> "${OUTFILE}"
printf "\tMENU LABEL Void Linux Version %s\n" "${ver}" >> "${OUTFILE}"
printf "\tLINUX %s\n" "${kernel}" >> "${OUTFILE}"
if [ -e "${BOOTPART}/${initrd}" ]; then
printf "\tINITRD %s\n" "${initrd}" >> "${OUTFILE}"
fi
if [ -n "${USE_DEVICETREEDIR}" ]; then
printf "\tDEVICETREEDIR %s\n" "${devicetreedir}" >> "${OUTFILE}"
elif [ -n "${DTBPATH}" ] && [ -e "${BOOTPART}/${fdt}" ]; then
printf "\tFDT %s\n" "${fdt}" >> "${OUTFILE}"
fi
if [ -n "${cmdline}" ]; then
printf "\tAPPEND %s\n" "${cmdline}" >> "${OUTFILE}"
fi
ENTRY=$((ENTRY + 1))
}
main() {
if [ ! -d /boot/extlinux ]; then
rm "${OUTFILE}"
exit 0
fi
if [ -e ${CONF} ]; then
. ${CONF}
fi
if [ -z "${CMDLINE}" ]; then
CMDLINE=$(cat /proc/cmdline)
fi
header
for kernel in $(ls /boot/vmlinu[xz]-* | sort -rV); do
ver=$(echo "${kernel}" | sed "s#/boot/vmlinu[xz]-\(.*\)#\\1#")
suffix=$(echo "${kernel}" | sed "s#/boot/vmlinu\([xz]\).*#\\1#")
echo "Add kernel ${ver}"
add_kernel "${ver}" "${suffix}"
done
mv "${OUTFILE}" /boot/extlinux/extlinux.conf
}
CONF=/etc/default/extlinux
OUTFILE=$(mktemp)
BOOTPART=$(df -P /boot | tail -1 | awk '{ print $6 }')
ENTRY=0
TIMEOUT=10
main