Files
fruix/tests/system/run-phase7-system-closure.sh

204 lines
7.4 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_file=${OS_FILE:-$script_dir/phase7-minimal-operating-system.scm}
system_name=${SYSTEM_NAME:-phase7-operating-system}
store_dir=${STORE_DIR:-/frx/store}
metadata_target=${METADATA_OUT:-}
[ -x "$fruix_cmd" ] || {
echo "fruix command is not executable: $fruix_cmd" >&2
exit 1
}
cleanup=0
if [ -n "${WORKDIR:-}" ]; then
workdir=$WORKDIR
mkdir -p "$workdir"
else
workdir=$(mktemp -d /tmp/fruix-phase7-system-closure.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_a=$workdir/build-a.txt
build_out_b=$workdir/build-b.txt
metadata_file=$workdir/phase7-system-closure-metadata.txt
action_env() {
sudo env \
HOME="$HOME" \
GUILE_AUTO_COMPILE=0 \
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"
action_env "$fruix_cmd" system build "$os_file" --system "$system_name" --store "$store_dir" >"$build_out_a"
action_env "$fruix_cmd" system build "$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")
ready_marker=$(sed -n 's/^ready_marker=//p' "$build_out_a")
kernel_store=$(sed -n 's/^kernel_store=//p' "$build_out_a")
bootloader_store=$(sed -n 's/^bootloader_store=//p' "$build_out_a")
guile_store=$(sed -n 's/^guile_store=//p' "$build_out_a")
guile_extra_store=$(sed -n 's/^guile_extra_store=//p' "$build_out_a")
shepherd_store=$(sed -n 's/^shepherd_store=//p' "$build_out_a")
base_package_store_count=$(sed -n 's/^base_package_store_count=//p' "$build_out_a")
base_package_stores=$(sed -n 's/^base_package_stores=//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")
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")
host_freebsd_version=$(sed -n 's/^host_freebsd_version=//p' "$build_out_a")
host_uname=$(sed -n 's/^host_uname=//p' "$build_out_a")
usr_src_git_revision=$(sed -n 's/^usr_src_git_revision=//p' "$build_out_a")
usr_src_git_branch=$(sed -n 's/^usr_src_git_branch=//p' "$build_out_a")
usr_src_newvers_sha256=$(sed -n 's/^usr_src_newvers_sha256=//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")
case "$closure_path" in
/frx/store/*-fruix-system-fruix-freebsd) : ;;
*) echo "unexpected closure path: $closure_path" >&2; exit 1 ;;
esac
[ "$closure_path" = "$closure_rebuild_path" ] || {
echo "closure path was not reproducible: $closure_path != $closure_rebuild_path" >&2
exit 1
}
rc_script=$closure_path/usr/local/etc/rc.d/fruix-shepherd
shepherd_config=$closure_path/shepherd/init.scm
activation_script=$closure_path/activate
loader_conf=$closure_path/boot/loader.conf
profile_bin_sh=$closure_path/profile/bin/sh
profile_sbin_init=$closure_path/profile/sbin/init
profile_rc=$closure_path/profile/etc/rc
boot_loader_target=$(readlink "$closure_path/boot/loader")
kernel_link_target=$(readlink "$closure_path/boot/kernel/kernel")
for path in \
"$closure_path" \
"$kernel_store" \
"$bootloader_store" \
"$guile_store" \
"$guile_extra_store" \
"$shepherd_store" \
"$rc_script" \
"$shepherd_config" \
"$activation_script" \
"$loader_conf" \
"$profile_bin_sh" \
"$profile_sbin_init" \
"$profile_rc" \
"$closure_path/parameters.scm" \
"$host_base_provenance_file" \
"$store_layout_file"
do
[ -e "$path" ] || {
echo "required path missing: $path" >&2
exit 1
}
done
[ -x "$activation_script" ] || { echo "activation script is not executable" >&2; exit 1; }
[ -x "$rc_script" ] || { echo "fruix shepherd rc script is not executable" >&2; exit 1; }
[ -n "$base_package_store_count" ] || { echo "missing base package store count" >&2; exit 1; }
[ -n "$host_base_store_count" ] || { echo "missing host base store count" >&2; exit 1; }
[ -n "$fruix_runtime_store_count" ] || { echo "missing Fruix runtime store count" >&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; }
[ -n "$host_freebsd_version" ] || { echo "missing host freebsd version provenance" >&2; exit 1; }
[ -n "$host_uname" ] || { echo "missing host uname provenance" >&2; exit 1; }
case "$boot_loader_target" in
/frx/store/*/boot/loader) : ;;
*) echo "unexpected /boot/loader target in closure: $boot_loader_target" >&2; exit 1 ;;
esac
case "$kernel_link_target" in
/frx/store/*/boot/kernel/kernel) : ;;
*) echo "unexpected kernel link target: $kernel_link_target" >&2; exit 1 ;;
esac
grep -F 'fruix-ready' "$shepherd_config" >/dev/null || {
echo "shepherd config missing fruix-ready service" >&2
exit 1
}
grep -F "$ready_marker" "$shepherd_config" >/dev/null || {
echo "shepherd config missing ready marker path" >&2
exit 1
}
cat >"$metadata_file" <<EOF
workdir=$workdir
store_dir=$store_dir
closure_path=$closure_path
closure_rebuild_path=$closure_rebuild_path
ready_marker=$ready_marker
kernel_store=$kernel_store
bootloader_store=$bootloader_store
guile_store=$guile_store
guile_extra_store=$guile_extra_store
shepherd_store=$shepherd_store
base_package_store_count=$base_package_store_count
base_package_stores=$base_package_stores
reference_count=$reference_count
generated_file_count=$generated_file_count
host_base_store_count=$host_base_store_count
host_base_stores=$host_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
host_freebsd_version=$host_freebsd_version
host_uname=$host_uname
usr_src_git_revision=$usr_src_git_revision
usr_src_git_branch=$usr_src_git_branch
usr_src_newvers_sha256=$usr_src_newvers_sha256
rc_script=$rc_script
shepherd_config=$shepherd_config
activation_script=$activation_script
loader_conf=$loader_conf
boot_loader_target=$boot_loader_target
kernel_link_target=$kernel_link_target
profile_bin_sh=$profile_bin_sh
profile_sbin_init=$profile_sbin_init
profile_rc=$profile_rc
init_integration=freebsd-init+rc.d-shepherd
frontend_invocation=$fruix_cmd system build
EOF
if [ -n "$metadata_target" ]; then
mkdir -p "$(dirname "$metadata_target")"
cp "$metadata_file" "$metadata_target"
fi
printf 'PASS phase7-system-closure\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"