Files
fruix/tests/system/run-phase13-native-base-build.sh

225 lines
9.3 KiB
Bash
Executable File

#!/bin/sh
set -eu
project_root=${PROJECT_ROOT:-$(pwd)}
script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd)
fruix_cmd=$project_root/bin/fruix
os_template=${OS_TEMPLATE:-$script_dir/phase13-native-base-pid1-operating-system.scm.in}
system_name=${SYSTEM_NAME:-phase13-operating-system}
store_dir=${STORE_DIR:-/frx/store}
metadata_target=${METADATA_OUT:-}
root_authorized_key_file=${ROOT_AUTHORIZED_KEY_FILE:-$HOME/.ssh/id_ed25519.pub}
[ -x "$fruix_cmd" ] || {
echo "fruix command is not executable: $fruix_cmd" >&2
exit 1
}
[ -f "$os_template" ] || {
echo "missing operating-system template: $os_template" >&2
exit 1
}
[ -f "$root_authorized_key_file" ] || {
echo "missing root authorized key file: $root_authorized_key_file" >&2
exit 1
}
cleanup=0
if [ -n "${WORKDIR:-}" ]; then
workdir=$WORKDIR
mkdir -p "$workdir"
else
workdir=$(mktemp -d /tmp/fruix-phase13-native-build.XXXXXX)
cleanup=1
fi
if [ "${KEEP_WORKDIR:-0}" -eq 1 ]; then
cleanup=0
fi
cleanup_workdir() {
if [ "$cleanup" -eq 1 ]; then
rm -rf "$workdir" 2>/dev/null || sudo rm -rf "$workdir"
fi
}
trap cleanup_workdir EXIT INT TERM
phase13_os_file=$workdir/phase13-native-base-operating-system.scm
build_out_a=$workdir/build-a.txt
build_out_b=$workdir/build-b.txt
metadata_file=$workdir/phase13-native-base-build-metadata.txt
root_authorized_key=$(tr -d '\n' < "$root_authorized_key_file")
sed "s|__ROOT_AUTHORIZED_KEY__|$root_authorized_key|g" "$os_template" > "$phase13_os_file"
action_env() {
sudo env \
HOME="$HOME" \
GUILE_AUTO_COMPILE=0 \
FRUIX_FREEBSD_BUILD_JOBS="${FRUIX_FREEBSD_BUILD_JOBS:-8}" \
GUIX_SOURCE_DIR="${GUIX_SOURCE_DIR:-$HOME/repos/guix}" \
GUILE_BIN="${GUILE_BIN:-/tmp/guile-freebsd-validate-install/bin/guile}" \
GUILE_EXTRA_PREFIX="${GUILE_EXTRA_PREFIX:-/tmp/guile-gnutls-freebsd-validate-install}" \
SHEPHERD_PREFIX="${SHEPHERD_PREFIX:-/tmp/shepherd-freebsd-validate-install}" \
"$@"
}
printf 'Using fruix command: %s\n' "$fruix_cmd"
printf 'Working directory: %s\n' "$workdir"
printf 'Store directory: %s\n' "$store_dir"
printf 'OS template: %s\n' "$os_template"
action_env "$fruix_cmd" system build "$phase13_os_file" --system "$system_name" --store "$store_dir" >"$build_out_a"
action_env "$fruix_cmd" system build "$phase13_os_file" --system "$system_name" --store "$store_dir" >"$build_out_b"
closure_path=$(sed -n 's/^closure_path=//p' "$build_out_a")
closure_rebuild_path=$(sed -n 's/^closure_path=//p' "$build_out_b")
kernel_store=$(sed -n 's/^kernel_store=//p' "$build_out_a")
bootloader_store=$(sed -n 's/^bootloader_store=//p' "$build_out_a")
host_base_store_count=$(sed -n 's/^host_base_store_count=//p' "$build_out_a")
host_base_stores=$(sed -n 's/^host_base_stores=//p' "$build_out_a")
native_base_store_count=$(sed -n 's/^native_base_store_count=//p' "$build_out_a")
native_base_stores=$(sed -n 's/^native_base_stores=//p' "$build_out_a")
fruix_runtime_store_count=$(sed -n 's/^fruix_runtime_store_count=//p' "$build_out_a")
fruix_runtime_stores=$(sed -n 's/^fruix_runtime_stores=//p' "$build_out_a")
host_base_provenance_file=$(sed -n 's/^host_base_provenance_file=//p' "$build_out_a")
store_layout_file=$(sed -n 's/^store_layout_file=//p' "$build_out_a")
reference_count=$(sed -n 's/^reference_count=//p' "$build_out_a")
generated_file_count=$(sed -n 's/^generated_file_count=//p' "$build_out_a")
[ -n "$closure_path" ] || { echo "missing closure path" >&2; exit 1; }
[ "$closure_path" = "$closure_rebuild_path" ] || {
echo "native-base closure path was not reproducible: $closure_path != $closure_rebuild_path" >&2
exit 1
}
case "$kernel_store" in
/frx/store/*-freebsd-native-kernel-15.0-STABLE) : ;;
*) echo "unexpected native kernel store path: $kernel_store" >&2; exit 1 ;;
esac
case "$bootloader_store" in
/frx/store/*-freebsd-bootloader-15.0-STABLE) : ;;
*) echo "unexpected bootloader store path: $bootloader_store" >&2; exit 1 ;;
esac
[ "$host_base_store_count" = 1 ] || { echo "expected exactly one host-staged base store, got: $host_base_store_count" >&2; exit 1; }
[ "$native_base_store_count" = 2 ] || { echo "expected exactly two native base stores, got: $native_base_store_count" >&2; exit 1; }
[ -n "$fruix_runtime_store_count" ] || { echo "missing Fruix runtime store count" >&2; exit 1; }
[ -n "$reference_count" ] || { echo "missing reference count" >&2; exit 1; }
[ -n "$generated_file_count" ] || { echo "missing generated file count" >&2; exit 1; }
world_store=$(printf '%s\n' "$native_base_stores" | tr ',' '\n' | grep 'freebsd-native-world-15.0-STABLE$' | head -n 1)
[ -n "$world_store" ] || { echo "failed to recover native world store from metadata" >&2; exit 1; }
world_build_info=$world_store/.freebsd-native-build-info.scm
kernel_build_info=$kernel_store/.freebsd-native-build-info.scm
[ -f "$world_build_info" ] || { echo "missing world build info: $world_build_info" >&2; exit 1; }
[ -f "$kernel_build_info" ] || { echo "missing kernel build info: $kernel_build_info" >&2; exit 1; }
[ -f "$host_base_provenance_file" ] || { echo "missing host base provenance file: $host_base_provenance_file" >&2; exit 1; }
[ -f "$store_layout_file" ] || { echo "missing store layout file: $store_layout_file" >&2; exit 1; }
for path in \
"$kernel_store/boot/kernel/kernel" \
"$kernel_store/boot/kernel/linker.hints" \
"$world_store/bin/sh" \
"$world_store/sbin/init" \
"$world_store/etc/rc" \
"$world_store/usr/sbin/sshd" \
"$world_store/sbin/dhclient" \
"$world_store/usr/bin/cap_mkdb" \
"$world_store/usr/sbin/pwd_mkdb" \
"$world_store/usr/share/locale/C.UTF-8/LC_CTYPE"
do
[ -e "$path" ] || {
echo "required native world/kernel path missing: $path" >&2
exit 1
}
done
[ ! -e "$world_store/usr/share/man" ] || { echo "native world still contains pruned man pages" >&2; exit 1; }
[ ! -e "$world_store/usr/tests" ] || { echo "native world still contains pruned tests" >&2; exit 1; }
grep -F 'native-base-stores' "$store_layout_file" >/dev/null || {
echo "store layout metadata is missing native-base-stores" >&2
exit 1
}
grep -F 'source-root . "/usr/src"' "$world_build_info" >/dev/null || {
echo "world build info is missing /usr/src provenance" >&2
exit 1
}
grep -F 'source-root . "/usr/src"' "$kernel_build_info" >/dev/null || {
echo "kernel build info is missing /usr/src provenance" >&2
exit 1
}
world_source_tree_sha256=$(grep -o 'source-tree-sha256 . "[^"]*"' "$world_build_info" | head -n 1 | cut -d'"' -f2)
kernel_source_tree_sha256=$(grep -o 'source-tree-sha256 . "[^"]*"' "$kernel_build_info" | head -n 1 | cut -d'"' -f2)
world_build_root=$(grep -o 'build-root . "[^"]*"' "$world_build_info" | head -n 1 | cut -d'"' -f2)
kernel_build_root=$(grep -o 'build-root . "[^"]*"' "$kernel_build_info" | head -n 1 | cut -d'"' -f2)
world_build_log=$(grep -o 'buildworld-log . "[^"]*"' "$world_build_info" | head -n 1 | cut -d'"' -f2)
kernel_build_log=$(grep -o 'buildkernel-log . "[^"]*"' "$kernel_build_info" | head -n 1 | cut -d'"' -f2)
world_install_log=$(grep -o 'install-log . "[^"]*"' "$world_build_info" | head -n 1 | cut -d'"' -f2)
kernel_install_log=$(grep -o 'install-log . "[^"]*"' "$kernel_build_info" | head -n 1 | cut -d'"' -f2)
[ -n "$world_source_tree_sha256" ] || { echo "missing world source-tree hash" >&2; exit 1; }
[ -n "$kernel_source_tree_sha256" ] || { echo "missing kernel source-tree hash" >&2; exit 1; }
[ "$world_source_tree_sha256" = "$kernel_source_tree_sha256" ] || {
echo "native world/kernel source-tree hashes differ: $world_source_tree_sha256 != $kernel_source_tree_sha256" >&2
exit 1
}
[ "$world_build_root" = "$kernel_build_root" ] || {
echo "native world/kernel build roots differ: $world_build_root != $kernel_build_root" >&2
exit 1
}
for path in "$world_build_log" "$kernel_build_log" "$world_install_log" "$kernel_install_log"; do
[ -f "$path" ] || {
echo "expected native build log missing: $path" >&2
exit 1
}
done
closure_base=$(basename "$closure_path")
cat >"$metadata_file" <<EOF
workdir=$workdir
phase13_os_file=$phase13_os_file
closure_path=$closure_path
closure_rebuild_path=$closure_rebuild_path
closure_base=$closure_base
kernel_store=$kernel_store
world_store=$world_store
bootloader_store=$bootloader_store
host_base_store_count=$host_base_store_count
host_base_stores=$host_base_stores
native_base_store_count=$native_base_store_count
native_base_stores=$native_base_stores
fruix_runtime_store_count=$fruix_runtime_store_count
fruix_runtime_stores=$fruix_runtime_stores
host_base_provenance_file=$host_base_provenance_file
store_layout_file=$store_layout_file
reference_count=$reference_count
generated_file_count=$generated_file_count
world_source_tree_sha256=$world_source_tree_sha256
kernel_source_tree_sha256=$kernel_source_tree_sha256
world_build_root=$world_build_root
kernel_build_root=$kernel_build_root
world_build_log=$world_build_log
kernel_build_log=$kernel_build_log
world_install_log=$world_install_log
kernel_install_log=$kernel_install_log
frontend_invocation=$fruix_cmd system build
native_base_model=freebsd-world+freebsd-kernel-from-usr-src
init_mode=shepherd-pid1
EOF
if [ -n "$metadata_target" ]; then
mkdir -p "$(dirname "$metadata_target")"
cp "$metadata_file" "$metadata_target"
fi
printf 'PASS phase13-native-base-build\n'
printf 'Work directory: %s\n' "$workdir"
printf 'Metadata file: %s\n' "$metadata_file"
if [ -n "$metadata_target" ]; then
printf 'Copied metadata to: %s\n' "$metadata_target"
fi
printf '%s\n' '--- metadata ---'
cat "$metadata_file"