#!/bin/sh set -eu project_root=${PROJECT_ROOT:-$(pwd)} os_file=${OS_FILE:-$project_root/tests/system/phase7-minimal-operating-system.scm} system_name=${SYSTEM_NAME:-phase7-operating-system} store_dir=${STORE_DIR:-/frx/store} disk_capacity=${DISK_CAPACITY:-5g} metadata_target=${METADATA_OUT:-} cleanup=0 if [ -n "${WORKDIR:-}" ]; then workdir=$WORKDIR mkdir -p "$workdir" else workdir=$(mktemp -d /tmp/fruix-phase10-system-command.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 build_out=$workdir/build.txt image_out=$workdir/image.txt metadata_file=$workdir/phase10-fruix-system-command-metadata.txt sudo env \ HOME="$HOME" \ 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}" \ "$project_root/bin/fruix" system build "$os_file" --system "$system_name" --store "$store_dir" >"$build_out" closure_path=$(sed -n 's/^closure_path=//p' "$build_out") generated_file_count=$(sed -n 's/^generated_file_count=//p' "$build_out") reference_count=$(sed -n 's/^reference_count=//p' "$build_out") case "$closure_path" in /frx/store/*-fruix-system-fruix-freebsd) : ;; *) echo "unexpected closure path: $closure_path" >&2; exit 1 ;; esac [ -x "$closure_path/activate" ] || { echo "missing activate script in closure" >&2; exit 1; } [ -n "$generated_file_count" ] || { echo "missing generated_file_count" >&2; exit 1; } [ -n "$reference_count" ] || { echo "missing reference_count" >&2; exit 1; } sudo env \ HOME="$HOME" \ 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}" \ "$project_root/bin/fruix" system image "$os_file" --system "$system_name" --store "$store_dir" --disk-capacity "$disk_capacity" >"$image_out" image_store_path=$(sed -n 's/^image_store_path=//p' "$image_out") disk_image=$(sed -n 's/^disk_image=//p' "$image_out") disk_capacity_reported=$(sed -n 's/^disk_capacity=//p' "$image_out") store_item_count=$(sed -n 's/^store_item_count=//p' "$image_out") case "$image_store_path" in /frx/store/*-fruix-bhyve-image-fruix-freebsd) : ;; *) echo "unexpected image store path: $image_store_path" >&2; exit 1 ;; esac case "$disk_image" in /frx/store/*-fruix-bhyve-image-fruix-freebsd/disk.img) : ;; *) echo "unexpected disk image path: $disk_image" >&2; exit 1 ;; esac [ -f "$disk_image" ] || { echo "missing disk image" >&2; exit 1; } [ -n "$disk_capacity_reported" ] || { echo "missing disk capacity report" >&2; exit 1; } [ -n "$store_item_count" ] || { echo "missing store item count" >&2; exit 1; } cat >"$metadata_file" <