sortix-mirror/tix/tix-iso-bootconfig

171 lines
5.1 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# Copyright (c) 2017, 2018, 2022 Jonas 'Sortie' Termansen.
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
# tix-iso-bootconfig
# Generate hooks that configure the bootloader of releases iso images.
set -e
append_title="modified by $(id -un)@$(hostname)"
default=
directory=
enable_append_title=true
enable_dhclient=
Add networking stack. This change adds all the kernel parts of a network stack. The network stack is partial but implements many of the important parts. Add if(4) network interface abstraction. Network interfaces are registered in a global list that can be iterated and each assigned an unique integer identifier. Add reference counted packets with a cache that recycles recent packets. Add support for lo(4) loopback and ether(4) ethernet network interfaces. The /dev/lo0 loopback device is created automatically on boot. Add arp(4) address resolution protocol driver for translation of inet(4) network layer addresses into ether(4) link layer addresses. arp(4) entries are cached and evicted from the cache when needed or when the entry has not been used for a while. The cache is limited to 256 entries for now. Add ip(4) internet protocol version 4 support. IP fragmentation and options are not implemented yet. Add tcp(4) transmission control protocol sockets for a reliable transport layer protocol that provides a reliable byte stream connection between two hosts. The implementation is incomplete and does not yet implement out of band data, options, and high performance extensions. Add udp(4) user datagram protocol sockets for a connectionless transport layer that provides best-effort delivery of datagrams. Add ping(4) sockets for a best-effort delivery of echo datagrams. Change type of sa_family_t from unsigned short to uint16_t. Add --disable-network-drivers to the kernel(7) options and expose it with a bootloader menu. tix-iso-bootconfig can set this option by default. Import CRC32 code from libz for the Ethernet checksum. This is a compatible ABI change that adds features to socket(2) (AF_INET, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_PING), the ioctls for if(4), socket options, and the lo0 loopback interface. This commit is based on work by Meisaka Yukara contributed as the commit bbf7f1e8a5238a2bd1fe8eb1d2cc5c9c2421e2c4. Almost no lines of this work remains in this final commit as it has been rewritten or refactored away over the years, see the individual file headers for which files contain remnants of this work. Co-authored-by: Meisaka Yukara <Meisaka.Yukara@gmail.com>
2022-12-04 23:35:21 +00:00
enable_network_drivers=
enable_src=
2023-02-26 13:16:08 +00:00
enable_sshd=
init_target=
liveconfig=
operand=1
random_seed=false
timeout=
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) ;;
*=) parameter= ;;
*) parameter=yes ;;
esac
case $dashdash$argument in
--) dashdash=yes ;;
--append-title=*) append_title=$parameter ;;
--append-title) previous_option=append_title ;;
--default=*) default=$parameter ;;
--default) previous_option=default ;;
--disable-append-title) enable_append_title=false ;;
--disable-dhclient) enable_dhclient=false ;;
Add networking stack. This change adds all the kernel parts of a network stack. The network stack is partial but implements many of the important parts. Add if(4) network interface abstraction. Network interfaces are registered in a global list that can be iterated and each assigned an unique integer identifier. Add reference counted packets with a cache that recycles recent packets. Add support for lo(4) loopback and ether(4) ethernet network interfaces. The /dev/lo0 loopback device is created automatically on boot. Add arp(4) address resolution protocol driver for translation of inet(4) network layer addresses into ether(4) link layer addresses. arp(4) entries are cached and evicted from the cache when needed or when the entry has not been used for a while. The cache is limited to 256 entries for now. Add ip(4) internet protocol version 4 support. IP fragmentation and options are not implemented yet. Add tcp(4) transmission control protocol sockets for a reliable transport layer protocol that provides a reliable byte stream connection between two hosts. The implementation is incomplete and does not yet implement out of band data, options, and high performance extensions. Add udp(4) user datagram protocol sockets for a connectionless transport layer that provides best-effort delivery of datagrams. Add ping(4) sockets for a best-effort delivery of echo datagrams. Change type of sa_family_t from unsigned short to uint16_t. Add --disable-network-drivers to the kernel(7) options and expose it with a bootloader menu. tix-iso-bootconfig can set this option by default. Import CRC32 code from libz for the Ethernet checksum. This is a compatible ABI change that adds features to socket(2) (AF_INET, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_PING), the ioctls for if(4), socket options, and the lo0 loopback interface. This commit is based on work by Meisaka Yukara contributed as the commit bbf7f1e8a5238a2bd1fe8eb1d2cc5c9c2421e2c4. Almost no lines of this work remains in this final commit as it has been rewritten or refactored away over the years, see the individual file headers for which files contain remnants of this work. Co-authored-by: Meisaka Yukara <Meisaka.Yukara@gmail.com>
2022-12-04 23:35:21 +00:00
--disable-network-drivers) enable_network_drivers=false ;;
--disable-src) enable_src=false ;;
2023-02-26 13:16:08 +00:00
--disable-sshd) enable_sshd=false ;;
--enable-append-title) enable_append_title=true ;;
--enable-dhclient) enable_dhclient=true ;;
Add networking stack. This change adds all the kernel parts of a network stack. The network stack is partial but implements many of the important parts. Add if(4) network interface abstraction. Network interfaces are registered in a global list that can be iterated and each assigned an unique integer identifier. Add reference counted packets with a cache that recycles recent packets. Add support for lo(4) loopback and ether(4) ethernet network interfaces. The /dev/lo0 loopback device is created automatically on boot. Add arp(4) address resolution protocol driver for translation of inet(4) network layer addresses into ether(4) link layer addresses. arp(4) entries are cached and evicted from the cache when needed or when the entry has not been used for a while. The cache is limited to 256 entries for now. Add ip(4) internet protocol version 4 support. IP fragmentation and options are not implemented yet. Add tcp(4) transmission control protocol sockets for a reliable transport layer protocol that provides a reliable byte stream connection between two hosts. The implementation is incomplete and does not yet implement out of band data, options, and high performance extensions. Add udp(4) user datagram protocol sockets for a connectionless transport layer that provides best-effort delivery of datagrams. Add ping(4) sockets for a best-effort delivery of echo datagrams. Change type of sa_family_t from unsigned short to uint16_t. Add --disable-network-drivers to the kernel(7) options and expose it with a bootloader menu. tix-iso-bootconfig can set this option by default. Import CRC32 code from libz for the Ethernet checksum. This is a compatible ABI change that adds features to socket(2) (AF_INET, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_PING), the ioctls for if(4), socket options, and the lo0 loopback interface. This commit is based on work by Meisaka Yukara contributed as the commit bbf7f1e8a5238a2bd1fe8eb1d2cc5c9c2421e2c4. Almost no lines of this work remains in this final commit as it has been rewritten or refactored away over the years, see the individual file headers for which files contain remnants of this work. Co-authored-by: Meisaka Yukara <Meisaka.Yukara@gmail.com>
2022-12-04 23:35:21 +00:00
--enable-network-drivers) enable_network_drivers=true ;;
--enable-src) enable_src=true ;;
2023-02-26 13:16:08 +00:00
--enable-sshd) enable_sshd=true ;;
--init-target=*) init_target=$parameter ;;
--init-target) previous_option=init_target ;;
--liveconfig=*) liveconfig=$parameter ;;
--liveconfig) previous_option=liveconfig ;;
--random-seed) random_seed=true ;;
--timeout=*) timeout=$parameter ;;
--timeout) previous_option=timeout ;;
-*) echo "$0: unrecognized option $argument" >&2
exit 1 ;;
*)
if [ $operand = 1 ]; then
directory="$argument"
operand=2
else
echo "$0: unexpected extra operand $argument" >&2
exit 1
fi
;;
esac
done
if test -n "$previous_option"; then
echo "$0: option '$argument' requires an argument" >&2
exit 1
fi
if test -z "$directory"; then
echo "$0: No directory was specified" >&2
exit 1
fi
human_size() {
(export LC_ALL=C; du -bh -- "$1" 2>/dev/null || du -h -- "$1") |
sed -E 's/^([^[:space:]]+).*/\1/'
}
print_enable_default() {
if [ "$1" = true ]; then
printf " enable_%s=--enable-%s\n" "$2" "$3"
elif [ "$1" = false ]; then
printf " enable_%s=--disable-%s\n" "$2" "$3"
fi
}
print_enable_default_bool() {
if [ "$1" = true ]; then
printf " enable_%s=true\n" "$2"
elif [ "$1" = false ]; then
printf " enable_%s=false\n" "$2"
fi
}
if $random_seed; then
mkdir -p -- "$directory/boot"
if which dd >/dev/null 2>/dev/null; then
dd if=/dev/urandom of="$directory/boot/random.seed" bs=256 count=1 2>/dev/null
elif which rw >/dev/null 2>/dev/null; then
rw -i /dev/urandom -o "$directory/boot/random.seed" -c 256 -t
else
echo "$0: Neither dd(1) nor rw(1) are installed" >&2
exit 1
fi
fi
if [ -n "$liveconfig" ]; then
mkdir -p -- "$directory/boot"
(cd "$liveconfig" && tar -c -f- -- *) > "$directory/boot/liveconfig.tar"
rm -f -- "$directory/boot/liveconfig.tar.xz"
xz -- "$directory/boot/liveconfig.tar"
fi
mkdir -p -- "$directory/boot/grub"
(if [ -e "$directory/boot/liveconfig.tar.xz" ]; then
printf 'insmod xzio\n'
fi
if [ -n "$default" ]; then
printf 'default="%s"\n' "$default"
fi
if [ -n "$timeout" ]; then
printf 'timeout="%s"\n' "$timeout"
fi
print_enable_default_bool "$enable_dhclient" dhclient dhclient
Add networking stack. This change adds all the kernel parts of a network stack. The network stack is partial but implements many of the important parts. Add if(4) network interface abstraction. Network interfaces are registered in a global list that can be iterated and each assigned an unique integer identifier. Add reference counted packets with a cache that recycles recent packets. Add support for lo(4) loopback and ether(4) ethernet network interfaces. The /dev/lo0 loopback device is created automatically on boot. Add arp(4) address resolution protocol driver for translation of inet(4) network layer addresses into ether(4) link layer addresses. arp(4) entries are cached and evicted from the cache when needed or when the entry has not been used for a while. The cache is limited to 256 entries for now. Add ip(4) internet protocol version 4 support. IP fragmentation and options are not implemented yet. Add tcp(4) transmission control protocol sockets for a reliable transport layer protocol that provides a reliable byte stream connection between two hosts. The implementation is incomplete and does not yet implement out of band data, options, and high performance extensions. Add udp(4) user datagram protocol sockets for a connectionless transport layer that provides best-effort delivery of datagrams. Add ping(4) sockets for a best-effort delivery of echo datagrams. Change type of sa_family_t from unsigned short to uint16_t. Add --disable-network-drivers to the kernel(7) options and expose it with a bootloader menu. tix-iso-bootconfig can set this option by default. Import CRC32 code from libz for the Ethernet checksum. This is a compatible ABI change that adds features to socket(2) (AF_INET, IPPROTO_TCP, IPPROTO_UDP, IPPROTO_PING), the ioctls for if(4), socket options, and the lo0 loopback interface. This commit is based on work by Meisaka Yukara contributed as the commit bbf7f1e8a5238a2bd1fe8eb1d2cc5c9c2421e2c4. Almost no lines of this work remains in this final commit as it has been rewritten or refactored away over the years, see the individual file headers for which files contain remnants of this work. Co-authored-by: Meisaka Yukara <Meisaka.Yukara@gmail.com>
2022-12-04 23:35:21 +00:00
print_enable_default "$enable_network_drivers" network_drivers network-drivers
print_enable_default_bool "$enable_src" src src
2023-02-26 13:16:08 +00:00
print_enable_default_bool "$enable_sshd" sshd sshd
if $enable_append_title; then
printf "base_menu_title=\"\$base_menu_title - \"'%s'\n" \
"$(printf '%s\n' "$append_title" | sed "s/'/'\\\\''/g")"
fi
if [ -n "$init_target" ]; then
printf 'function hook_menu_pre {\n'
printf ' menuentry "Sortix (%s)" {\n' "$init_target"
printf ' load_sortix -- /sbin/init --target=%s\n' "$init_target"
printf ' }\n'
printf '}\n'
fi
if [ -e "$directory/boot/liveconfig.tar.xz" ]; then
printf 'function hook_initrd_post {\n'
printf ' echo -n "Loading /boot/liveconfig.tar.xz (%s) ... "\n' \
"$(human_size "$directory/boot/liveconfig.tar.xz")"
printf ' module /boot/liveconfig.tar.xz\n'
printf ' echo done\n'
printf '}\n'
fi
) > "$directory/boot/grub/hooks.cfg"