#!/usr/bin/env bash # SPDX-License-Identifier: MIT # Which play-* sites' web/controls.js differ from this one (its home copy). Each copy's # second line names the play-nes commit it came from; everything after that line must # equal this repository's web/controls.js at that commit, and is compared with the # working copy here too. The sites are found as sibling checkouts of this one. # Usage: scripts/controls-drift.sh [site ...] (exit 1 when any copy drifts) set -euo pipefail ROOT=$(cd "$(dirname "$0")/.." && pwd) PARENT=$(dirname "$ROOT") SITES=("$@") [ ${#SITES[@]} -gt 0 ] || SITES=(play-gb play-pce play-md emu-galaga galaga-remix z80-wasm play-2600) body() { tail -n +3; } drift=0 for site in "${SITES[@]}"; do copy="$PARENT/$site/web/controls.js" if [ ! -f "$copy" ]; then printf '%-14s no copy\n' "$site"; drift=1; continue; fi source=$(sed -n '2s/.*from play-nes \([0-9a-f]\{7,40\}\).*/\1/p' "$copy") if [ -z "$source" ]; then printf '%-14s no source commit on line 2\n' "$site"; drift=1; continue; fi if git -C "$ROOT" cat-file -e "$source:web/controls.js" 2>/dev/null \ && cmp -s <(body < "$copy") <(git -C "$ROOT" show "$source:web/controls.js" | body); then at="= play-nes $source" else at="EDITED since play-nes $source"; drift=1 fi if cmp -s <(body < "$copy") <(body < "$ROOT/web/controls.js"); then now="current"; else now="behind"; drift=1; fi printf '%-14s %s, %s\n' "$site" "$at" "$now" done exit $drift