1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00
sortix--sortix/build-aux/iso-grub-cfg.sh

354 lines
6.7 KiB
Bash
Raw Normal View History

2015-07-27 19:46:01 -04:00
#!/bin/sh -e
this=$(which -- "$0")
thisdir=$(dirname -- "$this")
2015-07-27 19:46:01 -04:00
platform=
directory=
version=
dashdash=
previous_option=
for argument do
if test -n "$previous_option"; then
eval $previous_option=\$argument
previous_option=
continue
fi
case $argument in
*=?*) parameter=$(expr "X$argument" : '[^=]*=\(.*\)' || true) ;;
2015-07-27 19:46:01 -04:00
*=) parameter= ;;
*) parameter=yes ;;
esac
case $dashdash$argument in
--) dashdash=yes ;;
--platform=*) platform=$parameter ;;
--platform) previous_option=platform ;;
--version=*) version=$parameter ;;
--version) previous_option=version ;;
-*) echo "$0: unrecognized option $argument" >&2
exit 1 ;;
*) directory="$argument" ;;
esac
done
if test -n "$previous_option"; then
echo "$0: option '$argument' requires an argument" >&2
exit 1
fi
if test -z "$platform"; then
echo "$0: platform wasn't set with --platform" >&2
exit 1
fi
if test -z "$version"; then
echo "$0: version wasn't set with --version" >&2
2015-07-27 19:46:01 -04:00
exit 1
fi
if test -z "$directory"; then
echo "$0: no directory operand supplied" >&2
exit 1
fi
machine=$(expr x"$platform" : 'x\([^-]*\).*')
maybe_compressed() {
if [ -e "$1.xz" ]; then
echo "$1.xz"
elif [ -e "$1.gz" ]; then
echo "$1.gz"
elif [ -e "$1" ]; then
echo "$1"
fi
}
human_size() {
LC_ALL=C du -bh "$1" | grep -Eo '^[^[:space:]]+'
}
portvar() {
echo "$1" | sed -e 's/-/_/g' -e 's/+/x/g'
}
isinset() {
(for port in $2; do
if [ x"$1" = x"$port" ]; then
echo true
exit 0
fi
done
echo false
exit 0)
}
. "$thisdir/ports.conf"
2015-07-27 19:46:01 -04:00
cd "$directory"
kernel=$(maybe_compressed boot/sortix.bin)
live_initrd=$(maybe_compressed boot/live.initrd)
overlay_initrd=$(maybe_compressed boot/overlay.initrd)
src_initrd=$(maybe_compressed boot/src.initrd)
system_initrd=$(maybe_compressed boot/system.initrd)
ports=$(ls repository | sed 's/\.tix\.tar\.xz//')
2015-07-27 19:46:01 -04:00
mkdir -p boot/grub
exec > boot/grub/grub.cfg
cat << EOF
insmod part_msdos
insmod ext2
EOF
find . | grep -Eq '\.gz$' && echo "insmod gzio"
find . | grep -Eq '\.xz$' && echo "insmod xzio"
echo
cat << EOF
2016-07-29 20:47:47 -04:00
insmod all_video
if loadfont unicode; then
2015-07-27 19:46:01 -04:00
insmod gfxterm
2016-07-29 20:47:47 -04:00
terminal_output gfxterm
2015-07-27 19:46:01 -04:00
fi
set menu_title="Sortix $version for $machine"
set timeout=10
set default="0"
export menu_title
export timeout
export default
2015-07-27 19:46:01 -04:00
EOF
if [ -n "$ports" ]; then
echo
for port in $ports; do
printf 'port_%s=true\n' "$(portvar "$port")"
done
for port in $ports; do
printf 'tix_%s=false\n' "$(portvar "$port")"
done
echo
for port in $ports; do
printf 'export port_%s\n' "$(portvar "$port")"
done
for port in $ports; do
printf 'export tix_%s\n' "$(portvar "$port")"
done
fi
2015-07-27 19:46:01 -04:00
echo
cat << EOF
. /boot/grub/main.cfg
EOF
2015-07-27 19:46:01 -04:00
exec > boot/grub/main.cfg
printf "function load_base {\n"
case $platform in
x86_64-*)
cat << EOF
if ! cpuid -l; then
echo "Error: You cannot run this 64-bit operating system because this" \
"computer has no 64-bit mode."
read
exit
fi
2015-07-27 19:46:01 -04:00
EOF
;;
esac
cat << EOF
echo -n "Loading /$kernel ($(human_size $kernel)) ... "
Seed kernel entropy with randomness from the previous boot. The bootloader will now load the /boot/random.seed file if it exists, in which case the kernel will use it as the initial kernel entropy. The kernel warns if no random seed was loaded, unless the --no-random-seed option was given. This option is used for live environments that inherently have no prior secret state. The kernel initializes its entropy pool from the random seed as of the first things, so randomness is available very early on. init(8) will emit a fresh /boot/random.seed file on boot to avoid the same entropy being used twice. init(8) also writes out /boot/random.seed on system shutdown where the system has the most entropy. init(8) will warn if writing the file fails, except if /boot is a real-only filesystem, and keeping such state is impossible. The system administrator is then responsible for ensuring the bootloader somehow passes a fresh random seed on the next boot. /boot/random.seed must be owned by the root user and root group and must have file permissions 600 to avoid unprivileged users can read it. The file is passed to the kernel by the bootloader as a multiboot module with the command line --random-seed. If no random seed is loaded, the kernel attempts a poor quality fallback where it seeds the kernel arc4random(3) continuously with the current time. The timing variance may provide some effective entropy. There is no real kernel entropy gathering yet. The read of the CMOS real time clock is moved to an early point in the kernel boot, so the current time is available as fallback entropy. The kernel access of the random seed module is supposed to be infallible and happens before the kernel log is set up, but there is not yet a failsafe API for mapping single pages in the early kernel. sysupgrade(8) creates /boot/random.seed if it's absent as a temporary compatibility measure for people upgrading from the 1.0 release. The GRUB port will need to be upgraded with support for /boot/random.seed in the 10_sortix script. Installation with manual bootloader configuration will need to load the random seed with the --random-seed command line. With GRUB, this can be done with: module /boot/random.seed --random-seed
2016-08-19 20:27:33 -04:00
multiboot /$kernel --no-random-seed "\$@"
echo done
EOF
for initrd in $system_initrd $src_initrd $live_initrd $overlay_initrd; do
2015-07-27 19:46:01 -04:00
cat << EOF
echo -n "Loading /$initrd ($(human_size $initrd)) ... "
module /$initrd
echo done
2015-12-27 20:11:17 -05:00
EOF
done
printf "}\n"
echo
printf "function load_ports {\n"
if [ -z "$ports" ]; then
printf "\ttrue\n"
fi
for port in $ports; do
tix=repository/$port.tix.tar.xz
2015-12-27 20:11:17 -05:00
cat << EOF
if \$tix_$(portvar "$port"); then
echo -n "Loading /$tix ($(human_size $tix)) ... "
module --nounzip /$tix --to /$tix
echo done
fi
if \$port_$(portvar "$port"); then
echo -n "Loading /$tix ($(human_size $tix)) ... "
module /$tix --tix
echo done
fi
2015-07-27 19:46:01 -04:00
EOF
done
printf "}\n"
echo
cat << EOF
function load_sortix {
load_base "\$@"
load_ports
}
2015-12-27 20:11:17 -05:00
EOF
menuentry() {
echo
printf "menuentry \"Sortix (%s)\" {\n" "$1"
if [ -n "$2" ]; then
printf "\tload_sortix %s\n" "$2"
#printf "\tload_sortix '"
#printf '%s' "$2" | sed "s,','\\'',g"
#printf "'\n"
else
printf "\tload_sortix\n"
fi
2015-07-27 19:46:01 -04:00
printf "}\n"
}
2017-02-25 17:25:53 -05:00
menuentry "live environment" '-- /sbin/init'
menuentry "new installation" '-- /sbin/init --target=sysinstall'
menuentry "upgrade existing installation" '-- /sbin/init --target=sysupgrade'
echo
cat << EOF
menuentry "Select ports..." {
configfile /boot/grub/ports.cfg
}
menuentry "Advanced..." {
configfile /boot/grub/advanced.cfg
}
EOF
exec > boot/grub/advanced.cfg
cat << EOF
menuentry "Back..." {
menu=main
configfile /boot/grub/main.cfg
}
menuentry "Select binary packages..." {
configfile /boot/grub/tix.cfg
}
EOF
exec > boot/grub/ports.cfg
cat << EOF
menuentry "Back..." {
menu=main
configfile /boot/grub/main.cfg
}
EOF
echo
printf 'menuentry "Load all ports" {'
for port in $ports; do
printf " port_%s=true\n" "$(portvar "$port")"
done
printf ' configfile /boot/grub/ports.cfg\n'
printf '}\n'
for set in $sets; do
echo
set_content=$(eval echo \$set_$set)
printf 'menuentry "Load only '"$set"' ports" {'
for port in $ports; do
printf " port_%s=%s\n" "$(portvar "$port")" "$(isinset "$port" "$set_content")"
done
printf ' configfile /boot/grub/ports.cfg\n'
printf '}\n'
done
echo
printf 'menuentry "Load no ports" {'
for port in $ports; do
printf " port_%s=false\n" "$(portvar "$port")"
done
printf ' configfile /boot/grub/ports.cfg\n'
printf '}\n'
echo
for port in $ports; do
cat << EOF
if \$port_$(portvar "$port"); then
menuentry "$port = true" {
port_$(portvar "$port")=false
configfile /boot/grub/ports.cfg
}
else
menuentry "$port = false" {
port_$(portvar "$port")=true
configfile /boot/grub/ports.cfg
}
fi
EOF
done
exec > boot/grub/tix.cfg
cat << EOF
menuentry "Back..." {
menu=main
configfile /boot/grub/advanced.cfg
}
EOF
echo
printf 'menuentry "Load all binary packages" {'
for port in $ports; do
printf " tix_%s=true\n" "$(portvar "$port")"
done
printf ' configfile /boot/grub/tix.cfg\n'
printf '}\n'
for set in $sets; do
echo
set_content=$(eval echo \$set_$set)
printf 'menuentry "Load only '"$set"' binary packages" {'
for port in $ports; do
printf " tix_%s=%s\n" "$(portvar "$port")" "$(isinset "$port" "$set_content")"
done
printf ' configfile /boot/grub/tix.cfg\n'
printf '}\n'
done
echo
printf 'menuentry "Load no binary packages" {'
for port in $ports; do
printf " tix_%s=false\n" "$(portvar "$port")"
done
printf ' configfile /boot/grub/tix.cfg\n'
printf '}\n'
echo
for port in $ports; do
cat << EOF
if \$tix_$(portvar "$port"); then
menuentry "$port = true" {
tix_$(portvar "$port")=false
configfile /boot/grub/tix.cfg
}
else
menuentry "$port = false" {
tix_$(portvar "$port")=true
configfile /boot/grub/tix.cfg
}
fi
EOF
done