#!/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/phase15-declarative-base-pid1-operating-system.scm.in} system_name=${SYSTEM_NAME:-phase15-operating-system} store_dir=${STORE_DIR:-/frx/store} current_base_name=${CURRENT_BASE_NAME:-stable-default} current_base_version=${CURRENT_BASE_VERSION:-15.0-STABLE} current_base_release=${CURRENT_BASE_RELEASE:-15.0-STABLE} current_base_branch=${CURRENT_BASE_BRANCH:-stable/15} candidate_base_name=${CANDIDATE_BASE_NAME:-stable-canary} candidate_base_version=${CANDIDATE_BASE_VERSION:-15.0-STABLE-p1} candidate_base_release=${CANDIDATE_BASE_RELEASE:-15.0-STABLE} candidate_base_branch=${CANDIDATE_BASE_BRANCH:-stable/15} 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-phase15-base-coexistence.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 render_os() { output=$1 base_name=$2 base_version=$3 base_release=$4 base_branch=$5 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|g" \ -e "s|__BASE_RELEASE__|$base_release|g" \ -e "s|__BASE_BRANCH__|$base_branch|g" \ -e "s|__ROOT_AUTHORIZED_KEY__|$root_authorized_key|g" \ "$os_template" > "$output" } 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}" \ "$@" } build_os() { os_file=$1 out_file=$2 action_env "$fruix_cmd" system build "$os_file" --system "$system_name" --store "$store_dir" >"$out_file" } current_os=$workdir/current-operating-system.scm candidate_os=$workdir/candidate-operating-system.scm current_out_a=$workdir/current-build-a.txt current_out_b=$workdir/current-build-b.txt candidate_out=$workdir/candidate-build.txt metadata_file=$workdir/phase15-base-coexistence-metadata.txt render_os "$current_os" "$current_base_name" "$current_base_version" "$current_base_release" "$current_base_branch" render_os "$candidate_os" "$candidate_base_name" "$candidate_base_version" "$candidate_base_release" "$candidate_base_branch" build_os "$current_os" "$current_out_a" build_os "$candidate_os" "$candidate_out" build_os "$current_os" "$current_out_b" current_closure=$(sed -n 's/^closure_path=//p' "$current_out_a") current_closure_rebuild=$(sed -n 's/^closure_path=//p' "$current_out_b") candidate_closure=$(sed -n 's/^closure_path=//p' "$candidate_out") current_native_stores=$(sed -n 's/^native_base_stores=//p' "$current_out_a") candidate_native_stores=$(sed -n 's/^native_base_stores=//p' "$candidate_out") current_host_count=$(sed -n 's/^host_base_store_count=//p' "$current_out_a") candidate_host_count=$(sed -n 's/^host_base_store_count=//p' "$candidate_out") current_base_version_out=$(sed -n 's/^freebsd_base_version_label=//p' "$current_out_a") candidate_base_version_out=$(sed -n 's/^freebsd_base_version_label=//p' "$candidate_out") current_base_file=$(sed -n 's/^freebsd_base_file=//p' "$current_out_a") candidate_base_file=$(sed -n 's/^freebsd_base_file=//p' "$candidate_out") [ -n "$current_closure" ] || { echo "missing current closure" >&2; exit 1; } [ -n "$candidate_closure" ] || { echo "missing candidate closure" >&2; exit 1; } [ "$current_closure" = "$current_closure_rebuild" ] || { echo "current closure path was not reproducible: $current_closure != $current_closure_rebuild" >&2 exit 1 } [ "$current_closure" != "$candidate_closure" ] || { echo "current and candidate closures unexpectedly match" >&2 exit 1 } [ "$current_host_count" = 0 ] || { echo "current build has host base stores" >&2; exit 1; } [ "$candidate_host_count" = 0 ] || { echo "candidate build has host base stores" >&2; exit 1; } [ "$current_base_version_out" = "$current_base_version" ] || { echo "unexpected current base version label" >&2; exit 1; } [ "$candidate_base_version_out" = "$candidate_base_version" ] || { echo "unexpected candidate base version label" >&2; exit 1; } [ -f "$current_base_file" ] || { echo "missing current base file" >&2; exit 1; } [ -f "$candidate_base_file" ] || { echo "missing candidate base file" >&2; exit 1; } for path in "$current_closure" "$candidate_closure"; do [ -d "$path" ] || { echo "expected closure directory missing: $path" >&2 exit 1 } done printf '%s\n' "$current_native_stores" | tr ',' '\n' | grep "freebsd-native-kernel-$current_base_version$" >/dev/null || { echo "current native stores do not contain the expected kernel version label" >&2 exit 1 } printf '%s\n' "$candidate_native_stores" | tr ',' '\n' | grep "freebsd-native-kernel-$candidate_base_version$" >/dev/null || { echo "candidate native stores do not contain the expected kernel version label" >&2 exit 1 } [ "$current_native_stores" != "$candidate_native_stores" ] || { echo "current and candidate native store sets unexpectedly match" >&2 exit 1 } grep -F "(version-label . \"$current_base_version\")" "$current_base_file" >/dev/null || { echo "current base file missing version label" >&2 exit 1 } grep -F "(version-label . \"$candidate_base_version\")" "$candidate_base_file" >/dev/null || { echo "candidate base file missing version label" >&2 exit 1 } current_closure_base=$(basename "$current_closure") candidate_closure_base=$(basename "$candidate_closure") cat >"$metadata_file" <