Commit 397bac98 authored by Jonas Termansen's avatar Jonas Termansen

Add support for modifying release iso images.

parent d1c34333
......@@ -408,6 +408,24 @@ release-iso: $(SORTIX_RELEASE_DIR)/$(VERSION)/builds/$(BUILD_NAME).iso
.PHONY: release-builds
release-builds: release-iso
$(SORTIX_RELEASE_DIR)/$(VERSION)/scripts: $(SORTIX_RELEASE_DIR)/$(VERSION)
mkdir -p $@
$(SORTIX_RELEASE_DIR)/$(VERSION)/scripts/tix-iso-add: tix/tix-iso-add $(SORTIX_RELEASE_DIR)/$(VERSION)/scripts
cp $< $@
$(SORTIX_RELEASE_DIR)/$(VERSION)/scripts/tix-iso-bootconfig: tix/tix-iso-bootconfig $(SORTIX_RELEASE_DIR)/$(VERSION)/scripts
cp $< $@
$(SORTIX_RELEASE_DIR)/$(VERSION)/scripts/tix-iso-liveconfig: tix/tix-iso-liveconfig $(SORTIX_RELEASE_DIR)/$(VERSION)/scripts
cp $< $@
.PHONY: release-scripts
release-scripts: \
$(SORTIX_RELEASE_DIR)/$(VERSION)/scripts/tix-iso-add \
$(SORTIX_RELEASE_DIR)/$(VERSION)/scripts/tix-iso-bootconfig \
$(SORTIX_RELEASE_DIR)/$(VERSION)/scripts/tix-iso-liveconfig \
$(SORTIX_RELEASE_DIR)/$(VERSION)/README: README $(SORTIX_RELEASE_DIR)/$(VERSION)
cp $< $@
......@@ -418,7 +436,7 @@ release-readme: $(SORTIX_RELEASE_DIR)/$(VERSION)/README
release-arch: release-builds release-readme
.PHONY: release-shared
release-shared: release-readme
release-shared: release-readme release-scripts
.PHONY: release
release: release-arch release-shared
......
#!/bin/sh -e
#!/bin/sh
# Copyright (c) 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.
#
# iso-grub-cfg.sh
# Generate GRUB bootloader configuration for release .iso filesystems.
# Note: This file has detailed documentation in release-iso-bootconfig(7).
set -e
this=$(which -- "$0")
thisdir=$(dirname -- "$this")
......@@ -67,7 +87,8 @@ maybe_compressed() {
}
human_size() {
LC_ALL=C du -bh "$1" | grep -Eo '^[^[:space:]]+'
(export LC_ALL=C; du -bh "$1" 2>/dev/null || du -h "$1") |
sed -E 's/^([^[:space:]]+).*/\1/'
}
portvar() {
......@@ -99,6 +120,43 @@ ports=$(ls repository | sed 's/\.tix\.tar\.xz//')
mkdir -p boot/grub
exec > boot/grub/grub.cfg
for hook in \
advanced_menu_post \
advanced_menu_pre \
initrd_post \
kernel_post \
kernel_pre \
menu_post \
menu_pre \
ports_menu \
ports_menu_post \
ports_menu_pre \
ports_menu_sets \
ports_post \
ports_pre \
tix_menu \
tix_menu_post \
tix_menu_pre \
tix_menu_sets \
; do
cat << EOF
function hook_$hook {
true
}
EOF
done
for set in all $sets no; do
cat << EOF
function hook_ports_set_$set {
true
}
function hook_tix_set_$set {
true
}
EOF
done
echo
cat << EOF
insmod part_msdos
insmod ext2
......@@ -106,7 +164,6 @@ EOF
find . | grep -Eq '\.gz$' && echo "insmod gzio"
find . | grep -Eq '\.xz$' && echo "insmod xzio"
echo
cat << EOF
insmod all_video
if loadfont unicode; then
......@@ -114,13 +171,25 @@ if loadfont unicode; then
terminal_output gfxterm
fi
set menu_title="Sortix $version for $machine"
set version="$version"
set machine="$machine"
set base_menu_title="Sortix \$version for \$machine"
set menu_title="\$base_menu_title"
set timeout=10
set default="0"
if [ -e /boot/random.seed ]; then
no_random_seed=
else
no_random_seed=--no-random-seed
fi
export version
export machine
export base_menu_title
export menu_title
export timeout
export default
export no_random_seed
EOF
if [ -n "$ports" ]; then
......@@ -141,11 +210,55 @@ if [ -n "$ports" ]; then
fi
echo
cat << EOF
. /boot/grub/main.cfg
EOF
echo 'function select_ports_set_no {'
for port in $ports; do
printf " port_%s=false\n" "$(portvar "$port")"
done
printf " hook_port_set_no\n"
echo "}"
for set in $sets; do
echo
set_content=$(eval echo \$set_$set)
echo "function select_ports_set_$set {"
for port in $ports; do
printf " port_%s=%s\n" "$(portvar "$port")" "$(isinset "$port" "$set_content")"
done
printf " hook_port_set_%s\n" "$set"
echo "}"
done
echo
echo 'function select_ports_set_all {'
for port in $ports; do
printf " port_%s=true\n" "$(portvar "$port")"
done
printf " hook_port_set_all\n"
echo "}"
exec > boot/grub/main.cfg
echo
echo 'function select_tix_set_no {'
for port in $ports; do
printf " tix_%s=false\n" "$(portvar "$port")"
done
printf " hook_tix_set_no\n"
echo "}"
for set in $sets; do
echo
set_content=$(eval echo \$set_$set)
echo "function select_tix_set_$set {"
for port in $ports; do
printf " tix_%s=%s\n" "$(portvar "$port")" "$(isinset "$port" "$set_content")"
done
printf " hook_tix_set_%s\n" "$set"
echo "}"
done
echo
echo 'function select_tix_set_all {'
for port in $ports; do
printf " tix_%s=true\n" "$(portvar "$port")"
done
printf " hook_tix_set_all\n"
echo "}"
echo
printf "function load_base {\n"
case $platform in
......@@ -161,10 +274,18 @@ EOF
;;
esac
cat << EOF
hook_kernel_pre
echo -n "Loading /$kernel ($(human_size $kernel)) ... "
multiboot /$kernel --no-random-seed "\$@"
multiboot /$kernel \$no_random_seed "\$@"
echo done
hook_kernel_post
if [ \$no_random_seed != --no-random-seed ]; then
echo -n "Loading /boot/random.seed (256) ... "
module /boot/random.seed --random-seed
echo done
fi
EOF
# TODO: Make loading of the /src initrd optional.
for initrd in $system_initrd $src_initrd $live_initrd $overlay_initrd; do
cat << EOF
echo -n "Loading /$initrd ($(human_size $initrd)) ... "
......@@ -172,12 +293,18 @@ for initrd in $system_initrd $src_initrd $live_initrd $overlay_initrd; do
echo done
EOF
done
printf "}\n"
cat << EOF
hook_initrd_post
}
EOF
echo
printf "function load_ports {\n"
cat << EOF
function load_ports {
hook_ports_pre
EOF
if [ -z "$ports" ]; then
printf "\ttrue\n"
printf " true\n"
fi
for port in $ports; do
tix=repository/$port.tix.tar.xz
......@@ -194,7 +321,10 @@ for port in $ports; do
fi
EOF
done
printf "}\n"
cat << EOF
hook_ports_post
}
EOF
echo
cat << EOF
......@@ -204,85 +334,111 @@ function load_sortix {
}
EOF
cat << EOF
if [ -e /boot/grub/hooks.cfg ]; then
. /boot/grub/hooks.cfg
fi
. /boot/grub/main.cfg
EOF
exec > boot/grub/main.cfg
menuentry() {
echo
printf "menuentry \"Sortix (%s)\" {\n" "$1"
if [ -n "$2" ]; then
printf "\tload_sortix %s\n" "$2"
#printf "\tload_sortix '"
printf " load_sortix %s\n" "$2"
#printf " load_sortix '"
#printf '%s' "$2" | sed "s,','\\'',g"
#printf "'\n"
else
printf "\tload_sortix\n"
printf " load_sortix\n"
fi
printf "}\n"
}
cat << EOF
menu_title="\$base_menu_title"
hook_menu_pre
EOF
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
configfile /boot/grub/ports.cfg
}
menuentry "Advanced..." {
configfile /boot/grub/advanced.cfg
configfile /boot/grub/advanced.cfg
}
hook_menu_post
EOF
exec > boot/grub/advanced.cfg
cat << EOF
menuentry "Back..." {
menu=main
configfile /boot/grub/main.cfg
}
menu_title="\$base_menu_title - Advanced Options"
hook_advanced_menu_pre
menuentry "Select binary packages..." {
configfile /boot/grub/tix.cfg
configfile /boot/grub/tix.cfg
}
hook_advanced_menu_post
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'
menu_title="\$base_menu_title - Ports"
hook_ports_menu_pre
menuentry "Load all ports" {
select_ports_set_all
configfile /boot/grub/ports.cfg
}
hook_ports_menu_sets
EOF
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 'menuentry "Load only '"$set"' ports" {\n'
printf " select_ports_set_%s\n" "$set"
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'
cat << EOF
menuentry "Load no ports" {
select_ports_set_no
configfile /boot/grub/ports.cfg
}
hook_ports_menu
EOF
echo
for port in $ports; do
cat << EOF
if \$port_$(portvar "$port"); then
......@@ -299,43 +455,50 @@ fi
EOF
done
cat << EOF
hook_ports_menu_post
EOF
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'
menu_title="\$base_menu_title - Binary Packages"
hook_tix_menu_pre
menuentry "Load all binary packages" {
select_tix_set_all
configfile /boot/grub/tix.cfg
}
hook_tix_menu_sets
EOF
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 'menuentry "Load only '"$set"' binary packages" {\n'
printf " select_tix_set_%s\n" "$set"
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'
cat << EOF
menuentry "Load no binary packages" {
select_tix_set_no
configfile /boot/grub/tix.cfg
}
hook_tix_menu
EOF
echo
for port in $ports; do
cat << EOF
if \$tix_$(portvar "$port"); then
......@@ -351,3 +514,8 @@ else
fi
EOF
done
cat << EOF
hook_tix_menu_post
EOF
......@@ -72,6 +72,23 @@ medium over any existing operating system installations.
After the installation is complete, remove the installation medium and restore
the firmware boot order to prioritize the local harddisk.
Then power the computer on normally to run the new operating system.
.Ss Release .iso Modification
Optionally, you might want to modification a release .iso to meet your custom
needs per the instructions in
.Xr release-iso-modification 7 .
.Pp
The release modification procedure lets you customize aspects such as the
default bootloader menu option and timeout, the default hostname, the default
keyboard layout, the default graphics resolution, adding files of your choice to
the live environment, and so on.
.Pp
Warning: The live environment does not come with any random entropy and entropy
gathering is not yet implemented.
To keep your system secure, it is recommended to use the release modification
procedure to add a
.Pa /boot/random.seed
file to the release .iso in order to securely seed the cryptographically secure
pseudorandom number generator.
.Ss Qemu
Virtual machines are a well-supported installation target.
For instance, to prepare a 1 GiB harddisk and install the operating system onto
......@@ -371,6 +388,7 @@ Congratulations on your new Sortix system.
.Xr initrd 7 ,
.Xr kernel 7 ,
.Xr mbr 7 ,
.Xr release-iso-modification 7 ,
.Xr upgrade 7 ,
.Xr user-guide 7 ,
.Xr disked 8 ,
......
This diff is collapsed.
This diff is collapsed.
......@@ -21,6 +21,23 @@ before that one.
If the existing installation is a development snapshot, you must either upgrade
to a newer development snapshot of that version, or a the final release of that
version.
.Ss Release .iso Modification
Optionally, you might want to modification a release .iso to meet your custom
needs per the instructions in
.Xr release-iso-modification 7 .
.Pp
The release modification procedure lets you customize aspects such as the
default bootloader menu option and timeout, the default hostname, the default
keyboard layout, the default graphics resolution, adding files of your choice to
the live environment, and so on.
.Pp
Warning: The live environment does not come with any random entropy and entropy
gathering is not yet implemented.
To keep your system secure, it is recommended to use the release modification
procedure to add a
.Pa /boot/random.seed
file to the release .iso in order to securely seed the cryptographically secure
pseudorandom number generator.
.Ss Bootloader Menu
Pick the
.Li upgrade existing installation
......
......@@ -27,6 +27,14 @@ tix-rmpatch \
PROGRAMS:=\
$(BINARIES) \
tix-eradicate-libtool-la \
tix-iso-add \
tix-iso-bootconfig \
tix-iso-liveconfig \
MANPAGES8=\
tix-iso-add.8 \
tix-iso-bootconfig.8 \
tix-iso-liveconfig.8 \
all: $(PROGRAMS)
......@@ -40,6 +48,9 @@ $(DESTDIR)$(SBINDIR):
install: all $(DESTDIR)$(SBINDIR)
install $(PROGRAMS) $(DESTDIR)$(SBINDIR)
mkdir -p $(DESTDIR)$(MANDIR)/man8
mkdir -p $(DESTDIR)$(MANDIR)/man8
cp $(MANPAGES8) $(DESTDIR)$(MANDIR)/man8
clean:
rm -f $(BINARIES)
#!/bin/sh
# Copyright (c) 2017 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-add
# Add directory to iso filesystem.
set -e
directory=
input=
operand=1
output=
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 ;;
-o) previous_option=output ;;
--output=*) output=$parameter ;;
--output) previous_option=output ;;
-*) echo "$0: unrecognized option $argument" >&2
exit 1 ;;
*)
if [ $operand = 1 ]; then
input="$argument"
operand=2
elif [ $operand = 2 ]; then
directory="$argument"
operand=3
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 "$input"; then
echo "$0: No input file was specified" >&2
exit 1
fi
if test -z "$output"; then
output="$input"
fi
tmpdir=
tmpdest=
cleanup() {
if [ -n "$tmpdir" ]; then rm -rf "$tmpdir"; fi
if [ -n "$tmpdest" ]; then rm -rf "$tmpdest"; fi
}
trap cleanup EXIT HUP INT QUIT TERM
if [ -z "$directory" ]; then
tmpdir=$(mktemp -d)
directory=$tmpdir
fi
# Use different -indev and -outdev as just xorriso -dev doesn't rewrite the .iso
# in the same manner.
if [ "$input" = "$output" ]; then
tmpdest=$(mktemp -d)
dest=$tmpdest/iso
else
dest=$output
rm -f -- "$dest"
fi
xorriso \
-indev "$input" \
-outdev "$dest" \
-boot_image grub keep \
-pathspecs on \
-add \
="$directory"
# xorriso doesn't write out the destination file if the directory is empty.
if [ ! -e "$dest" ]; then
cp -- "$input" "$dest"
fi
if [ "$dest" != "$output" ]; then
cp -- "$dest" "$output"
fi
.Dd February 4, 2018
.Dt TIX-ISO-ADD 8
.Os
.Sh NAME
.Nm tix-iso-add
.Nd add directory to .iso filesystem
.Sh SYNOPSIS
.Nm
.Op Fl o Ar output-file
.Ar input-file
.Ar input-directory
.Sh DESCRIPTION
.Nm
adds the contents of the
.Ar input-directory
directory to the .iso filesystem at
.Ar input-file ,
while keeping the .iso bootable after the modification.
.Pp
.Xr xorriso 1
must be installed in order to use this script.
.Pp
This script is designed to be convenient when modifying a Sortix release .iso as
part of the
.Xr release-iso-modification 7
procedure.
The user is free to take all its actions themselves if it doesn't meet their
needs.
.Pp
The options are as follows:
.Bl -tag -width "12345678"
.It Fl o Ar output-file , Fl \-output Ar output-file
Write the modified
.Ar input-file
to
.Ar output-file
instead of modifying
.Ar input-file
in place.
This path must not be the same as the
.Ar input-file .
.El
.Pp
This script works by invoking the
.Xr xorriso 1
program and essentially boils down to:
.Bd -literal
xorriso \\
-indev "$input_file" \\
-outdev "$output_file" \\
-boot_image grub keep \\
-pathspecs on \\
-add \\
="$input_directory"
.Ed
.Sh EXIT STATUS
.Nm
will exit 0 on success and non-zero otherwise.
On error, the input file is left alone.
.Sh EXAMPLES
To add some files and directories to an .iso filesystem, one can run:
.Bd -literal
mkdir directory
mkdir directory/foo
mkdir directory/foo/bar
echo qux > directory/foo/bar/qux
echo spam > directory/foo/bar/spam
tix-iso-add sortix.iso directory
.Ed
.Pp
To save the modified iso elsewhere, one can run:
.Bd -literal
tix-iso-add -o sortix-modified.iso sortix.iso directory
.Ed
.Sh SEE ALSO
.Xr xorriso 1 ,
.Xr release-iso-modification 7 ,
.Xr tix-iso-bootconfig 8 ,