#!/usr/bin/env bash # Sync the deploy manifests needed by the in-browser socialweb provider and # the MarketRequester app. The source checkout is read-only; everything here # is regenerated from it. set -euo pipefail SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd) DEST="$REPO_ROOT/socialweb-wasm/manifests" # From socialweb-wasm this is ../../../linux-kcp/socialweb-computer-kcp. DEFAULT_SRC="$REPO_ROOT/../../linux-kcp/socialweb-computer-kcp" usage() { cat <&2; usage >&2; exit 2 ;; *) if [ -n "$source_dir" ]; then echo "error: more than one source directory given" >&2 exit 2 fi source_dir=$1 ;; esac shift done source_dir=${source_dir:-${SOCIALWEB_KCP:-$DEFAULT_SRC}} if [ ! -d "$source_dir/deploy" ]; then echo "error: no socialweb-computer-kcp checkout at $source_dir (missing deploy/)" >&2 exit 1 fi source_dir=$(cd "$source_dir" && pwd) deploy="$source_dir/deploy" require_file() { local rel=$1 if [ -L "$deploy/$rel" ] || [ ! -f "$deploy/$rel" ]; then echo "error: expected regular file: $deploy/$rel" >&2 exit 1 fi } require_file apps/workspace-app.yaml require_file market-network/10-rbac.yaml if [ ! -d "$deploy/apps/market-requester" ]; then echo "error: missing directory: $deploy/apps/market-requester" >&2 exit 1 fi tmp=$(mktemp -d "${TMPDIR:-/tmp}/socialweb-manifests.XXXXXX") trap 'rm -rf "$tmp"' EXIT files=() while IFS= read -r file; do rel=${file#"$deploy/"} mkdir -p "$tmp/$(dirname "$rel")" cp -p "$file" "$tmp/$rel" files+=("$rel") done < <( { find "$deploy" -maxdepth 1 -type f -name '*.yaml' find "$deploy/apps/market-requester" -maxdepth 1 -type f -name '*.yaml' printf '%s\n' "$deploy/apps/workspace-app.yaml" printf '%s\n' "$deploy/market-network/10-rbac.yaml" } | LC_ALL=C sort ) # A mirror made with `git archive` has no .git of its own; it records the # source commit in .mirror-commit (see the socialweb build helpers). if [[ -f "$source_dir/.mirror-commit" ]]; then commit=$(cat "$source_dir/.mirror-commit") else commit=$(git -c safe.directory="$source_dir" -C "$source_dir" rev-parse HEAD) fi { printf '# Socialweb KCP manifests\n\n' printf 'Generated by `scripts/sync-socialweb-manifests.sh` from\n' printf '`linux-kcp/socialweb-computer-kcp` at `%s`.\n\n' "$commit" printf 'Do not edit by hand; run `make sync-socialweb-manifests` to refresh.\n\n' printf '## Files (%d)\n\n' "${#files[@]}" for rel in "${files[@]}"; do printf -- '- `%s`\n' "$rel" done } > "$tmp/README.md" if ((check)); then differs=$(diff -rq "$tmp" "$DEST" 2>&1) && { echo "in sync: ${#files[@]} files in $DEST" exit 0 } echo "out of sync: $DEST differs from $deploy" >&2 printf '%s\n' "$differs" >&2 exit 1 fi case "$DEST" in "$REPO_ROOT"/socialweb-wasm/manifests) ;; *) echo "error: refusing to replace unexpected path: $DEST" >&2; exit 1 ;; esac rm -rf "$DEST" mkdir -p "$DEST" cp -R "$tmp"/. "$DEST"/ echo "synced ${#files[@]} files from $source_dir (commit $commit) to $DEST"