grub-cfg.sh (1497B)
- #!/bin/sh
- # /boot/grub/grub.cfg config manager
- # Copyright ⓒ 2024 Haelwenn (lanodan) Monnier <contact+grub-nomagic-scripts@hacktivis.me>
- # SPDX-License-Identifier: MIT
- die() {
- echo "$@"
- exit 1
- }
- load_cfg() {
- if [ -e "$1" ] ; then
- . "$1"
- else
- die "grub-bios-install: Error, couldn't load configuration, file not found: $1"
- fi
- }
- set -e
- load_cfg ~/.config/grub-nomagic/env
- cd /boot
- test -z "${CMDLINE}" && die '$CMDLINE needs to be set to the kernel cmdline, for example the root variable for the kernel'
- test -z "${MICROCODE}" && die '$MICROCODE needs to be set, for example: amc-uc.img'
- test -z "${GRUB_ROOT}" && die '$GRUB_ROOT needs to be set to the boottime grub root relative to the boot disk, for example: /ROOT/gentoo/@/boot'
- cp grub/grub.cfg.head grub/grub.cfg || die 'grub/grub.cfg.head is required for initial configuration (such as modules and variables)'
- if test ! -f "/boot/${MICROCODE}"
- then
- echo "/boot/${MICROCODE}: File not found (microcode)"
- exit 1
- fi
- : ${INITRD_EXT:=.img}
- for kernel in $(ls -t vmlinuz*)
- do
- version="${kernel#vmlinuz}"
- : ${INITRD:=initramfs${version}${INITRD_EXT}}
- if test -e "${INITRD}"
- then
- echo "${kernel} + ${MICROCODE} + ${INITRD}"
- else
- echo "${kernel} ignored"
- continue
- fi
- cat >>grub/grub.cfg <<EOF
- menuentry 'Linux${version:- Default}' {
- linux ${grub_root}/${kernel} ${CMDLINE}
- initrd ${grub_root}/${MICROCODE} ${grub_root}/${INITRD}
- }
- EOF
- done
- test -f grub/grub.cfg.tail && cat grub/grub.cfg.tail >> grub/grub.cfg