161 lines
6.3 KiB
Bash
Executable File
161 lines
6.3 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
repo_root=${PROJECT_ROOT:-$(pwd)}
|
|
metadata_target=${METADATA_OUT:-}
|
|
cleanup=0
|
|
|
|
if [ -n "${WORKDIR:-}" ]; then
|
|
workdir=$WORKDIR
|
|
mkdir -p "$workdir"
|
|
else
|
|
workdir=$(mktemp -d /tmp/fruix-phase19-generation-layout-qemu.XXXXXX)
|
|
cleanup=1
|
|
fi
|
|
if [ "${KEEP_WORKDIR:-0}" -eq 1 ]; then
|
|
cleanup=0
|
|
fi
|
|
|
|
inner_workdir=$workdir/phase18-install
|
|
inner_metadata=$workdir/phase18-system-install-metadata.txt
|
|
metadata_file=$workdir/phase19-generation-layout-qemu-metadata.txt
|
|
mnt_esp=$workdir/mnt-esp
|
|
mnt_root=$workdir/mnt-root
|
|
md_unit=
|
|
|
|
cleanup_workdir() {
|
|
if [ -n "$md_unit" ]; then
|
|
sudo umount "$mnt_esp" >/dev/null 2>&1 || true
|
|
sudo umount "$mnt_root" >/dev/null 2>&1 || true
|
|
sudo mdconfig -d -u "$md_unit" >/dev/null 2>&1 || true
|
|
fi
|
|
if [ "$cleanup" -eq 1 ]; then
|
|
rm -rf "$workdir" 2>/dev/null || sudo rm -rf "$workdir"
|
|
fi
|
|
}
|
|
trap cleanup_workdir EXIT INT TERM
|
|
|
|
mkdir -p "$mnt_esp" "$mnt_root"
|
|
|
|
KEEP_WORKDIR=1 WORKDIR="$inner_workdir" METADATA_OUT="$inner_metadata" \
|
|
"$repo_root/tests/system/run-phase18-system-install.sh" >/dev/null
|
|
|
|
field() {
|
|
sed -n "s/^$1=//p" "$inner_metadata" | tail -n 1
|
|
}
|
|
|
|
target_image=$(field target_image)
|
|
closure_path=$(field closure_path)
|
|
materialized_source_store=$(field materialized_source_store)
|
|
install_metadata_path=$(field install_metadata_path)
|
|
run_current_system_target_reported=$(field run_current_system_target)
|
|
serial_log=$(field serial_log)
|
|
closure_base=$(basename "$closure_path")
|
|
|
|
guest_md=$(sudo mdconfig -a -t vnode -f "$target_image")
|
|
md_unit=${guest_md#md}
|
|
sudo mount -t msdosfs "/dev/${guest_md}p1" "$mnt_esp"
|
|
sudo mount -t ufs -o ro "/dev/${guest_md}p2" "$mnt_root"
|
|
|
|
system_root=$mnt_root/var/lib/fruix/system
|
|
generation_root=$system_root/generations/1
|
|
gcroots_root=$mnt_root/frx/var/fruix/gcroots
|
|
|
|
[ -d "$system_root" ] || { echo "missing explicit system generation root" >&2; exit 1; }
|
|
[ -d "$generation_root" ] || { echo "missing generation 1 directory" >&2; exit 1; }
|
|
[ -f "$system_root/current-generation" ] || { echo "missing current-generation file" >&2; exit 1; }
|
|
[ -L "$system_root/current" ] || { echo "missing current generation link" >&2; exit 1; }
|
|
[ -L "$generation_root/closure" ] || { echo "missing generation closure link" >&2; exit 1; }
|
|
[ -f "$generation_root/metadata.scm" ] || { echo "missing generation metadata file" >&2; exit 1; }
|
|
[ -f "$generation_root/provenance.scm" ] || { echo "missing generation provenance file" >&2; exit 1; }
|
|
[ -f "$generation_root/install.scm" ] || { echo "missing generation install metadata file" >&2; exit 1; }
|
|
[ -L "$gcroots_root/current-system" ] || { echo "missing current-system gc root" >&2; exit 1; }
|
|
[ -L "$gcroots_root/system-1" ] || { echo "missing system-1 gc root" >&2; exit 1; }
|
|
|
|
current_generation=$(tr -d '\n' < "$system_root/current-generation")
|
|
current_link=$(readlink "$system_root/current")
|
|
generation_closure=$(readlink "$generation_root/closure")
|
|
gcroot_current=$(readlink "$gcroots_root/current-system")
|
|
gcroot_generation=$(readlink "$gcroots_root/system-1")
|
|
run_current_system_target=$(readlink "$mnt_root/run/current-system")
|
|
generation_metadata=$(cat "$generation_root/metadata.scm")
|
|
generation_provenance=$(cat "$generation_root/provenance.scm")
|
|
generation_install=$(cat "$generation_root/install.scm")
|
|
install_metadata_host=$(cat "$mnt_root$install_metadata_path")
|
|
|
|
[ "$current_generation" = 1 ] || { echo "unexpected current generation: $current_generation" >&2; exit 1; }
|
|
[ "$current_link" = generations/1 ] || { echo "unexpected current link target: $current_link" >&2; exit 1; }
|
|
[ "$generation_closure" = "/frx/store/$closure_base" ] || { echo "unexpected generation closure target: $generation_closure" >&2; exit 1; }
|
|
[ "$gcroot_current" = "/frx/store/$closure_base" ] || { echo "unexpected current-system gc root: $gcroot_current" >&2; exit 1; }
|
|
[ "$gcroot_generation" = "/frx/store/$closure_base" ] || { echo "unexpected system-1 gc root: $gcroot_generation" >&2; exit 1; }
|
|
[ "$run_current_system_target" = "/frx/store/$closure_base" ] || { echo "unexpected /run/current-system target: $run_current_system_target" >&2; exit 1; }
|
|
[ "$run_current_system_target_reported" = "/frx/store/$closure_base" ] || { echo "unexpected reported guest current-system target: $run_current_system_target_reported" >&2; exit 1; }
|
|
|
|
case "$generation_metadata" in
|
|
*"$closure_path"*) : ;;
|
|
*) echo "generation metadata does not record closure path" >&2; exit 1 ;;
|
|
esac
|
|
case "$generation_metadata" in
|
|
*"$install_metadata_path"*) : ;;
|
|
*) echo "generation metadata does not record install metadata path" >&2; exit 1 ;;
|
|
esac
|
|
case "$generation_provenance" in
|
|
*"$closure_path/metadata/store-layout.scm"*) : ;;
|
|
*) echo "generation provenance does not reference store layout metadata" >&2; exit 1 ;;
|
|
esac
|
|
case "$generation_install" in
|
|
*"$closure_path"*) : ;;
|
|
*) echo "generation install metadata does not record closure path" >&2; exit 1 ;;
|
|
esac
|
|
case "$generation_install" in
|
|
*"$materialized_source_store"*) : ;;
|
|
*) echo "generation install metadata does not record materialized source store" >&2; exit 1 ;;
|
|
esac
|
|
case "$install_metadata_host" in
|
|
*"$closure_path"*) : ;;
|
|
*) echo "installed target metadata does not record closure path" >&2; exit 1 ;;
|
|
esac
|
|
|
|
sudo umount "$mnt_esp"
|
|
sudo umount "$mnt_root"
|
|
sudo mdconfig -d -u "$md_unit"
|
|
md_unit=
|
|
|
|
cat >"$metadata_file" <<EOF
|
|
workdir=$workdir
|
|
inner_workdir=$inner_workdir
|
|
inner_metadata=$inner_metadata
|
|
target_image=$target_image
|
|
closure_path=$closure_path
|
|
closure_base=$closure_base
|
|
materialized_source_store=$materialized_source_store
|
|
install_metadata_path=$install_metadata_path
|
|
system_root=$system_root
|
|
generation_root=$generation_root
|
|
gcroots_root=$gcroots_root
|
|
current_generation=$current_generation
|
|
current_link=$current_link
|
|
generation_closure=$generation_closure
|
|
gcroot_current=$gcroot_current
|
|
gcroot_generation=$gcroot_generation
|
|
run_current_system_target=$run_current_system_target
|
|
serial_log=$serial_log
|
|
generation_layout=explicit
|
|
boot_backend=qemu-uefi-tcg
|
|
generation_layout_validation=ok
|
|
EOF
|
|
|
|
if [ -n "$metadata_target" ]; then
|
|
mkdir -p "$(dirname "$metadata_target")"
|
|
cp "$metadata_file" "$metadata_target"
|
|
fi
|
|
|
|
printf 'PASS phase19-generation-layout-qemu\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"
|