#!/bin/sh
set -eu
umask 022

script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)
output_dir=${1:?usage: prepare_g3_fixtures.sh OUTPUT-DIRECTORY}

for tool in mkfs.erofs fsck.erofs dump.erofs python3 sha256sum; do
	command -v "$tool" >/dev/null 2>&1 || {
		printf 'missing tool: %s\n' "$tool" >&2
		exit 1
	}
done
test ! -e "$output_dir" || {
	printf 'output already exists: %s\n' "$output_dir" >&2
	exit 1
}

python3 -B "$script_dir/pre15/fixtures/g3.py" make-all --output "$output_dir"
python3 -B "$script_dir/pre15/fixtures/g3.py" verify --output "$output_dir"
printf 'G3_MANIFEST=%s\n' "$output_dir/G3-MANIFEST.json"
