sortix-mirror/tix/tix-iso-bootconfig
Jonas 'Sortie' Termansen f2d50bbf9c Add daemon support to init(8).
This change implements a dependency tracking daemon(7) system in init with
overridable init(5) configuration, parallel startup, readiness signaling,
rotating logs, reliable stopping, and handling of leaked processes.

The /etc/init/target file is replaced by the new /etc/init/default per the
new init(5) format. The old configuration is migrated upon upgrade using an
upgrade hook.

extfs(8) now signals readiness using READYFD for fast mounting.

Filesystems that fail to be repaired are now mounted read-only.

The mounting and filesystem checking code is synchronized with sysinstall.

The duplicated array_add utility function now protects against overflows.

tix-iso-bootconfig(8) gains the --init-target option.

tix-iso-liveconfig(8) gains the --daemons option.
2022-10-20 23:26:03 +02:00

159 lines
4.5 KiB
Bash
Executable file

#!/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_src=
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-src) enable_src=false ;;
--enable-append-title) enable_append_title=true ;;
--enable-src) enable_src=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_src" src src
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"