#!/usr/bin/env bash set -euo pipefail command_name="${1:?command is required}" shift artifact_dir="" artifact_kind="" target_sha="" workflow_sha="" image_refs=() shared_package_sha256="${OPENCLAW_SHARED_IMAGE_PACKAGE_SHA256:-}" shared_archive_sha256="${OPENCLAW_SHARED_IMAGE_ARCHIVE_SHA256:-}" shared_run_id="${OPENCLAW_SHARED_IMAGE_RUN_ID:-}" shared_run_attempt="${OPENCLAW_SHARED_IMAGE_RUN_ATTEMPT:-}" archive_name="shared-images.tar.zst" manifest_path="" archive_path="" fail() { echo "$*" >&2 exit 1 } require_sha() { local label="$1" local value="$2" if [[ ! "$value" =~ ^[a-f0-9]{40}$ ]]; then fail "$label must be a lowercase full commit SHA." fi } require_positive_decimal() { local label="$1" local value="$2" if [[ ! "$value" =~ ^[1-9][0-9]*$ ]]; then fail "$label must be a positive decimal integer." fi } configure_image_artifact_inputs() { if [[ "$#" -lt 5 ]]; then fail "usage: $0 ..." fi artifact_dir="$1" artifact_kind="$2" target_sha="$3" workflow_sha="$4" image_refs=("${@:5}") manifest_path="${artifact_dir}/shared-image-artifact.json" archive_path="${artifact_dir}/${archive_name}" } verify_uploaded_artifact() { if [[ "$#" -ne 6 ]]; then fail "usage: $0 verify-upload