Files
vasilito f6ee40326b Fix grub-install BOOT_PATH, validate grub-mkconfig timeout, add fat_tool sync
Fix BOOT_PATH logic in grub-install: non-removable installs now use
EFI/${BOOTLOADER_ID} per UEFI spec instead of always EFI/BOOT.
Add timeout validation to grub-mkconfig (must be non-negative integer).
Add sync() method to fat_tool.py and call os.fsync after cp_in to
ensure data reaches disk. Fix misleading block-device error message.
2026-04-17 23:46:20 +01:00

120 lines
2.5 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
case "$TIMEOUT" in
''|*[!0-9]*) echo "$PROG: invalid timeout '$TIMEOUT' (must be a non-negative integer)" >&2; exit 1;;
esac
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