#!/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/phase16-git-materialized-source-operating-system.scm.in} system_name=${SYSTEM_NAME:-phase16-operating-system} store_dir=${STORE_DIR:-/frx/store} base_name=${BASE_NAME:-git-materialized-source} base_version_label=${BASE_VERSION_LABEL:-15.0-STABLE-git-materialized} base_release=${BASE_RELEASE:-15.0-STABLE} base_branch=${BASE_BRANCH:-stable/15} source_name=${SOURCE_NAME:-stable15-network-source} source_ref=${SOURCE_REF:-stable/15} declared_source_root=${DECLARED_SOURCE_ROOT:-/var/empty/fruix-unused-source-root} 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-phase16-source-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 phase16_os_file=$workdir/phase16-git-materialized-source-operating-system.scm build_out=$workdir/build.txt metadata_file=$workdir/phase16-source-driven-native-build-metadata.txt root_authorized_key=$(tr -d '\n' < "$root_authorized_key_file") sed \ -e "s|__BASE_NAME__|$base_name|g" \ -e "s|__BASE_VERSION_LABEL__|$base_version_label|g" \ -e "s|__BASE_RELEASE__|$base_release|g" \ -e "s|__BASE_BRANCH__|$base_branch|g" \ -e "s|__SOURCE_NAME__|$source_name|g" \ -e "s|__SOURCE_REF__|$source_ref|g" \ -e "s|__DECLARED_SOURCE_ROOT__|$declared_source_root|g" \ -e "s|__ROOT_AUTHORIZED_KEY__|$root_authorized_key|g" \ "$os_template" > "$phase16_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}" \ "$@" } action_env "$fruix_cmd" system build "$phase16_os_file" --system "$system_name" --store "$store_dir" >"$build_out" field() { sed -n "s/^$1=//p" "$build_out" | tail -n 1 } closure_path=$(field closure_path) kernel_store=$(field kernel_store) bootloader_store=$(field bootloader_store) native_base_store_count=$(field native_base_store_count) native_base_stores=$(field native_base_stores) host_base_store_count=$(field host_base_store_count) freebsd_base_name_out=$(field freebsd_base_name) freebsd_base_version_label_out=$(field freebsd_base_version_label) freebsd_base_release_out=$(field freebsd_base_release) freebsd_base_branch_out=$(field freebsd_base_branch) freebsd_base_source_root_out=$(field freebsd_base_source_root) freebsd_base_file=$(field freebsd_base_file) freebsd_source_name_out=$(field freebsd_source_name) freebsd_source_kind_out=$(field freebsd_source_kind) freebsd_source_url_out=$(field freebsd_source_url) freebsd_source_ref_out=$(field freebsd_source_ref) freebsd_source_file=$(field freebsd_source_file) freebsd_source_materializations_file=$(field freebsd_source_materializations_file) materialized_source_store_count=$(field materialized_source_store_count) materialized_source_stores=$(field materialized_source_stores) store_layout_file=$(field store_layout_file) [ -n "$closure_path" ] || { echo "missing closure path" >&2; exit 1; } [ "$host_base_store_count" = 0 ] || { echo "expected zero host base stores, got: $host_base_store_count" >&2; exit 1; } [ "$native_base_store_count" = 3 ] || { echo "expected three native base stores, got: $native_base_store_count" >&2; exit 1; } [ "$materialized_source_store_count" = 1 ] || { echo "expected one materialized source store, got: $materialized_source_store_count" >&2; exit 1; } [ "$freebsd_base_name_out" = "$base_name" ] || { echo "unexpected freebsd base name: $freebsd_base_name_out" >&2; exit 1; } [ "$freebsd_base_version_label_out" = "$base_version_label" ] || { echo "unexpected freebsd base version label: $freebsd_base_version_label_out" >&2; exit 1; } [ "$freebsd_base_release_out" = "$base_release" ] || { echo "unexpected freebsd base release: $freebsd_base_release_out" >&2; exit 1; } [ "$freebsd_base_branch_out" = "$base_branch" ] || { echo "unexpected freebsd base branch: $freebsd_base_branch_out" >&2; exit 1; } [ "$freebsd_base_source_root_out" = "$declared_source_root" ] || { echo "unexpected declared source root: $freebsd_base_source_root_out" >&2; exit 1; } [ "$freebsd_source_name_out" = "$source_name" ] || { echo "unexpected freebsd source name: $freebsd_source_name_out" >&2; exit 1; } [ "$freebsd_source_kind_out" = git ] || { echo "unexpected freebsd source kind: $freebsd_source_kind_out" >&2; exit 1; } [ "$freebsd_source_url_out" = https://git.FreeBSD.org/src.git ] || { echo "unexpected freebsd source URL: $freebsd_source_url_out" >&2; exit 1; } [ "$freebsd_source_ref_out" = "$source_ref" ] || { echo "unexpected freebsd source ref: $freebsd_source_ref_out" >&2; exit 1; } [ -f "$freebsd_base_file" ] || { echo "missing freebsd base file: $freebsd_base_file" >&2; exit 1; } [ -f "$freebsd_source_file" ] || { echo "missing freebsd source file: $freebsd_source_file" >&2; exit 1; } [ -f "$freebsd_source_materializations_file" ] || { echo "missing source materializations file: $freebsd_source_materializations_file" >&2; exit 1; } [ -f "$store_layout_file" ] || { echo "missing store layout file: $store_layout_file" >&2; exit 1; } case "$kernel_store" in /frx/store/*-freebsd-native-kernel-$base_version_label) : ;; *) echo "unexpected kernel store path: $kernel_store" >&2; exit 1 ;; esac case "$bootloader_store" in /frx/store/*-freebsd-native-bootloader-$base_version_label) : ;; *) echo "unexpected bootloader store path: $bootloader_store" >&2; exit 1 ;; esac case "$materialized_source_stores" in /frx/store/*-freebsd-source-$source_name) : ;; *) echo "unexpected materialized source store path: $materialized_source_stores" >&2; exit 1 ;; esac materialized_source_root=$materialized_source_stores/tree [ -f "$materialized_source_root/Makefile" ] || { echo "materialized git source root missing Makefile" >&2; exit 1; } [ -f "$materialized_source_root/sys/conf/newvers.sh" ] || { echo "materialized git source root missing newvers.sh" >&2; exit 1; } runtime_store=$(printf '%s\n' "$native_base_stores" | tr ',' '\n' | grep "freebsd-native-runtime-$base_version_label$" | head -n 1) [ -n "$runtime_store" ] || { echo "failed to recover runtime store" >&2; exit 1; } resolved_commit=$(grep -Eo '\(commit \. "[0-9a-f]{40}"\)' "$freebsd_source_materializations_file" | head -n 1 | sed 's/.*"\([0-9a-f]\{40\}\)".*/\1/') printf '%s\n' "$resolved_commit" | grep -E '^[0-9a-f]{40}$' >/dev/null || { echo "failed to recover resolved git commit from source materializations file" >&2 exit 1 } grep -F "$materialized_source_stores" "$freebsd_source_materializations_file" >/dev/null || { echo "source materializations file missing store path" >&2 exit 1 } grep -F "$materialized_source_root" "$freebsd_source_materializations_file" >/dev/null || { echo "source materializations file missing source root" >&2 exit 1 } grep -F "(materialized-source-store-count . 1)" "$store_layout_file" >/dev/null || { echo "store layout file missing materialized source count" >&2 exit 1 } grep -F "$materialized_source_stores" "$store_layout_file" >/dev/null || { echo "store layout file missing materialized source store path" >&2 exit 1 } for path in "$kernel_store/.freebsd-native-build-info.scm" "$bootloader_store/.freebsd-native-build-info.scm" "$runtime_store/.freebsd-native-build-info.scm"; do [ -f "$path" ] || { echo "missing native build info file: $path" >&2 exit 1 } grep -F "(declared-source" "$path" >/dev/null || { echo "native build info missing declared-source block in $path" >&2 exit 1 } grep -F "(materialized-source" "$path" >/dev/null || { echo "native build info missing materialized-source block in $path" >&2 exit 1 } grep -F "(ref . \"$source_ref\")" "$path" >/dev/null || { echo "native build info missing declared source ref in $path" >&2 exit 1 } grep -F "(source-root . \"$materialized_source_root\")" "$path" >/dev/null || { echo "native build info missing materialized source root in $path" >&2 exit 1 } grep -F "(store-path . \"$materialized_source_stores\")" "$path" >/dev/null || { echo "native build info missing materialized source store path in $path" >&2 exit 1 } grep -F "(commit . \"$resolved_commit\")" "$path" >/dev/null || { echo "native build info missing resolved git commit in $path" >&2 exit 1 } if grep -F "(source-root . \"$declared_source_root\")" "$path" >/dev/null; then echo "native build info still records the unused declared source root in $path" >&2 exit 1 fi done grep -F "(source-root . \"$declared_source_root\")" "$closure_path/parameters.scm" >/dev/null || { echo "closure parameters no longer record the declared transitional source root" >&2 exit 1 } closure_base=$(basename "$closure_path") cat >"$metadata_file" <