mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
137 lines
3.9 KiB
Text
137 lines
3.9 KiB
Text
|
#!/bin/sh
|
||
|
# Copyright (c) 2017, 2018 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
|
||
|
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 ;;
|
||
|
--enable-append-title) enable_append_title=true ;;
|
||
|
--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
|
||
|
}
|
||
|
|
||
|
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
|
||
|
if $enable_append_title; then
|
||
|
printf "base_menu_title=\"\$base_menu_title - \"'%s'\n" \
|
||
|
"$(printf '%s\n' "$append_title" | sed "s/'/'\\\\''/g")"
|
||
|
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"
|