Files
RedBear-OS/local/scripts/grub-mkconfig
T
vasilito 3bed450071 Add Linux-compatible grub-install and grub-mkconfig wrappers
Create grub-install and grub-mkconfig scripts in local/scripts/ that
match GNU GRUB CLI conventions for users migrating from Linux. Support
standard switches: --target, --efi-directory, --bootloader-id,
--removable, -o/--output, --verbose, --help, --version. Unsupported
Linux options are accepted and ignored for script compatibility.

Also fix ESP FAT type: force FAT32 in both with_whole_disk and
with_whole_disk_ext4 (UEFI spec requires FAT32, fatfs auto-selects
FAT16 for partitions under 32 MiB). Fix --write-bootloader to export
GRUB EFI in GRUB mode. Fix CLI example in GRUB plan. Update AGENTS.md
and GRUB-INTEGRATION-PLAN.md with Linux-compatible CLI docs.
2026-04-17 22:47:01 +01:00

116 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# grub-mkconfig — Generate GRUB configuration file (Red Bear OS wrapper)
#
# Compatibility: Matches GNU GRUB grub-mkconfig CLI conventions.
# Generates a grub.cfg for chainloading the Redox bootloader.
#
# Usage:
# grub-mkconfig [-o FILE]
# grub-mkconfig --output=/boot/grub/grub.cfg
set -euo pipefail
PROG="$(basename "$0")"
OUTPUT=""
TIMEOUT=5
DEFAULT=0
usage() {
cat <<EOF
Usage: $PROG [OPTION...]
Generate a GRUB configuration file.
-o, --output=FILE Write generated config to FILE [default: stdout]
--timeout=SECS Menu timeout in seconds [default: 5]
--set-default=N Default menu entry index [default: 0]
-h, --help Display this help and exit
-V, --version Print program version and exit
Examples:
# Preview generated config
$PROG
# Write to standard GRUB location
$PROG -o /boot/grub/grub.cfg
# Write to Red Bear OS recipe directory
$PROG -o local/recipes/core/grub/grub.cfg
EOF
exit 0
}
version() {
echo "$PROG (Red Bear OS) 2.12"
echo "Compatible with GNU GRUB grub-mkconfig interface"
exit 0
}
while [ $# -gt 0 ]; do
case "$1" in
-o|--output)
OUTPUT="$2"
shift 2
;;
--output=*)
OUTPUT="${1#--output=}"
shift
;;
--timeout=*)
TIMEOUT="${1#--timeout=}"
shift
;;
--timeout)
TIMEOUT="$2"
shift 2
;;
--set-default=*)
DEFAULT="${1#--set-default=}"
shift
;;
--set-default)
DEFAULT="$2"
shift 2
;;
-h|--help)
usage
;;
-V|--version)
version
;;
*)
echo "$PROG: unrecognized option '$1'" >&2
echo "Try '$PROG --help' for more information." >&2
exit 1
;;
esac
done
generate_config() {
cat <<GRUBCFG
# Generated by $PROG — $(date -Iseconds 2>/dev/null || date)
# Red Bear OS GRUB configuration — chainloads the Redox bootloader
set timeout=$TIMEOUT
set default=$DEFAULT
menuentry "Red Bear OS" {
chainloader /EFI/REDBEAR/redbear.efi
boot
}
menuentry "Reboot" {
reboot
}
menuentry "Shutdown" {
halt
}
GRUBCFG
}
if [ -n "$OUTPUT" ]; then
generate_config > "$OUTPUT"
else
generate_config
fi