#!/bin/sh set -eu project_root=${PROJECT_ROOT:-$(pwd)} script_dir=$(CDPATH= cd -- "$(dirname "$0")" && pwd) fruix_cmd=$project_root/bin/fruix git_template=${GIT_SOURCE_TEMPLATE:-$script_dir/phase16-git-freebsd-source.scm.in} txz_template=${TXZ_SOURCE_TEMPLATE:-$script_dir/phase16-txz-freebsd-source.scm.in} store_dir=${STORE_DIR:-/frx/store} cache_dir=${CACHE_DIR:-/frx/var/cache/fruix/freebsd-source} git_source_name=${GIT_SOURCE_NAME:-stable15-git-ref} git_source_ref=${GIT_SOURCE_REF:-stable/15} txz_source_name=${TXZ_SOURCE_NAME:-release15-src-txz} txz_source_url=${TXZ_SOURCE_URL:-https://download.freebsd.org/releases/amd64/15.0-RELEASE/src.txz} txz_source_sha256=${TXZ_SOURCE_SHA256:-83c3e8157b6d7afcae57167fda75693bf1e5f581ca149a6ecb2d398b71bdfab0} metadata_target=${METADATA_OUT:-} [ -x "$fruix_cmd" ] || { echo "fruix command is not executable: $fruix_cmd" >&2 exit 1 } [ -f "$git_template" ] || { echo "missing git source template: $git_template" >&2 exit 1 } [ -f "$txz_template" ] || { echo "missing txz source template: $txz_template" >&2 exit 1 } cleanup=0 if [ -n "${WORKDIR:-}" ]; then workdir=$WORKDIR mkdir -p "$workdir" else workdir=$(mktemp -d /tmp/fruix-phase16-source-materialization.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 git_source_file=$workdir/git-source.scm txz_source_file=$workdir/txz-source.scm git_out_first=$workdir/git-first.txt git_out_second=$workdir/git-second.txt txz_out_first=$workdir/txz-first.txt txz_out_second=$workdir/txz-second.txt metadata_file=$workdir/phase16-source-materialization-metadata.txt sed \ -e "s|__SOURCE_NAME__|$git_source_name|g" \ -e "s|__SOURCE_REF__|$git_source_ref|g" \ "$git_template" > "$git_source_file" sed \ -e "s|__SOURCE_NAME__|$txz_source_name|g" \ -e "s|__SOURCE_URL__|$txz_source_url|g" \ -e "s|__SOURCE_SHA256__|$txz_source_sha256|g" \ "$txz_template" > "$txz_source_file" action_env() { sudo env \ HOME="$HOME" \ GUILE_AUTO_COMPILE=0 \ 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}" \ "$@" } extract_field() { key=$1 file=$2 sed -n "s/^${key}=//p" "$file" | tail -n 1 } assert_hex40() { value=$1 label=$2 printf '%s\n' "$value" | grep -E '^[0-9a-f]{40}$' >/dev/null || { echo "expected 40-hex $label, got: $value" >&2 exit 1 } } assert_hex64() { value=$1 label=$2 printf '%s\n' "$value" | grep -E '^[0-9a-f]{64}$' >/dev/null || { echo "expected 64-hex $label, got: $value" >&2 exit 1 } } assert_file() { path=$1 [ -e "$path" ] || { echo "missing expected path: $path" >&2 exit 1 } } action_env "$fruix_cmd" source materialize "$git_source_file" --source phase16-source --store "$store_dir" --cache "$cache_dir" > "$git_out_first" action_env "$fruix_cmd" source materialize "$git_source_file" --source phase16-source --store "$store_dir" --cache "$cache_dir" > "$git_out_second" action_env "$fruix_cmd" source materialize "$txz_source_file" --source phase16-source --store "$store_dir" --cache "$cache_dir" > "$txz_out_first" action_env "$fruix_cmd" source materialize "$txz_source_file" --source phase16-source --store "$store_dir" --cache "$cache_dir" > "$txz_out_second" git_store_first=$(extract_field materialized_source_store "$git_out_first") git_store_second=$(extract_field materialized_source_store "$git_out_second") git_root_first=$(extract_field materialized_source_root "$git_out_first") git_info_first=$(extract_field materialized_source_info_file "$git_out_first") git_tree_sha_first=$(extract_field materialized_source_tree_sha256 "$git_out_first") git_cache_first=$(extract_field materialized_source_cache_path "$git_out_first") git_kind_first=$(extract_field materialized_source_kind "$git_out_first") git_url_first=$(extract_field materialized_source_url "$git_out_first") git_ref_first=$(extract_field materialized_source_ref "$git_out_first") git_commit_first=$(extract_field materialized_source_commit "$git_out_first") txz_store_first=$(extract_field materialized_source_store "$txz_out_first") txz_store_second=$(extract_field materialized_source_store "$txz_out_second") txz_root_first=$(extract_field materialized_source_root "$txz_out_first") txz_info_first=$(extract_field materialized_source_info_file "$txz_out_first") txz_tree_sha_first=$(extract_field materialized_source_tree_sha256 "$txz_out_first") txz_cache_first=$(extract_field materialized_source_cache_path "$txz_out_first") txz_kind_first=$(extract_field materialized_source_kind "$txz_out_first") txz_url_first=$(extract_field materialized_source_url "$txz_out_first") txz_sha_first=$(extract_field materialized_source_sha256 "$txz_out_first") [ "$git_store_first" = "$git_store_second" ] || { echo "git materialization was not stable across two runs" >&2 exit 1 } [ "$txz_store_first" = "$txz_store_second" ] || { echo "txz materialization was not stable across two runs" >&2 exit 1 } [ "$git_kind_first" = git ] || { echo "unexpected git materialized kind: $git_kind_first" >&2 exit 1 } [ "$git_url_first" = https://git.FreeBSD.org/src.git ] || { echo "unexpected git materialized URL: $git_url_first" >&2 exit 1 } [ "$git_ref_first" = "$git_source_ref" ] || { echo "unexpected git materialized ref: $git_ref_first" >&2 exit 1 } assert_hex40 "$git_commit_first" "git materialized commit" assert_hex64 "$git_tree_sha_first" "git source tree sha256" assert_file "$git_store_first" assert_file "$git_root_first" assert_file "$git_info_first" assert_file "$git_cache_first" assert_file "$git_root_first/Makefile" assert_file "$git_root_first/sys/conf/newvers.sh" [ "$txz_kind_first" = src-txz ] || { echo "unexpected txz materialized kind: $txz_kind_first" >&2 exit 1 } [ "$txz_url_first" = "$txz_source_url" ] || { echo "unexpected txz materialized URL: $txz_url_first" >&2 exit 1 } [ "$txz_sha_first" = "$txz_source_sha256" ] || { echo "unexpected txz materialized sha256: $txz_sha_first" >&2 exit 1 } assert_hex64 "$txz_tree_sha_first" "txz source tree sha256" assert_file "$txz_store_first" assert_file "$txz_root_first" assert_file "$txz_info_first" assert_file "$txz_cache_first" assert_file "$txz_root_first/Makefile" assert_file "$txz_root_first/sys/conf/newvers.sh" cat > "$metadata_file" <