#!/usr/bin/env bash # Stamp landing footers with version + last content change + linkified commit. # # Usage (from koopa-admin-log root): # ./scripts/taler-landing/stamp-landing-version.sh # re-stamp with HEAD + current version # ./scripts/taler-landing/stamp-landing-version.sh --bump # version += 1, then stamp HEAD # ./scripts/taler-landing/stamp-landing-version.sh --set 42 # force version # # Typical flow after editing landing HTML/CSS/JS: # 1) edit landings # 2) ./scripts/taler-landing/stamp-landing-version.sh --bump # 3) git add configs/ && git commit # 4) ./scripts/taler-landing/stamp-landing-version.sh && git add configs/ && git commit --amend --no-edit # # Or one-shot (commits for you if GIT_STAMP_COMMIT=1). set -euo pipefail ROOT="$(cd "$(dirname "$0")/../.." && pwd)" VER_FILE="$ROOT/configs/shared/landing-version.json" REPO_WEB="${LANDING_REPO_WEB:-https://git.hacktivism.ch/hernani/koopa-admin-log}" LANDINGS=( "$ROOT/configs/bank-landing/index.html" "$ROOT/configs/exchange-landing/index.html" "$ROOT/configs/merchant-landing/index.html" ) export TZ="${TZ:-Europe/Zurich}" bump=0 set_ver="" while [ $# -gt 0 ]; do case "$1" in --bump) bump=1; shift ;; --set) set_ver="${2:-}"; shift 2 ;; -h|--help) sed -n '2,20p' "$0" exit 0 ;; *) echo "unknown arg: $1" >&2; exit 2 ;; esac done if [ ! -f "$VER_FILE" ]; then echo '{"version":42,"updated_iso":"","updated_human":"","commit":"","commit_short":""}' >"$VER_FILE" fi version=$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1])).get("version",42))' "$VER_FILE") if [ -n "$set_ver" ]; then version="$set_ver" elif [ "$bump" = 1 ]; then version=$((version + 1)) fi # Prefer staged/index commit identity after commit; allow OVERRIDE_COMMIT if [ -n "${OVERRIDE_COMMIT:-}" ]; then full="$OVERRIDE_COMMIT" else full=$(git -C "$ROOT" rev-parse HEAD 2>/dev/null || echo "unknown") fi short=$(git -C "$ROOT" rev-parse --short=7 "$full" 2>/dev/null || echo "${full:0:7}") iso=$(date +%Y-%m-%dT%H:%M:%S%z | sed -E 's/([+-][0-9]{2})([0-9]{2})$/\1:\2/') human=$(date +"%Y-%m-%d %H:%M %Z") url="${REPO_WEB}/commit/${full}" python3 - "$VER_FILE" "$version" "$iso" "$human" "$full" "$short" "$url" <<'PY' import json, sys path, version, iso, human, full, short, url = sys.argv[1:] data = { "version": int(version), "updated_iso": iso, "updated_human": human, "commit": full, "commit_short": short, "repo_commit_url": url, "note": "Bump with scripts/taler-landing/stamp-landing-version.sh --bump after each landing content change.", } open(path, "w", encoding="utf-8").write(json.dumps(data, indent=2, ensure_ascii=False) + "\n") print(f"version={version} commit={short} at={human}") PY # HTML block injected into each footer (idempotent via markers) block=$(cat <

Landing v${version} · content · ${short}

EOF ) css_snip=' .landing-rev { margin: 0.75rem 0 0; font-size: 0.72rem; color: var(--muted, #9a8fb0); line-height: 1.45; text-align: center; } .landing-rev a { color: inherit; text-decoration: underline; text-underline-offset: 2px; opacity: 0.95; } .landing-rev strong { font-weight: 750; } ' for f in "${LANDINGS[@]}"; do [ -f "$f" ] || { echo "missing $f" >&2; exit 1; } # ensure CSS once if ! grep -q '\.landing-rev' "$f"; then # insert before of first style block python3 - "$f" "$css_snip" <<'PY' import sys path, snip = sys.argv[1], sys.argv[2] t = open(path, encoding="utf-8").read() if ".landing-rev" in t: sys.exit(0) idx = t.find("") if idx < 0: raise SystemExit(f"no in {path}") t = t[:idx] + snip + "\n" + t[idx:] open(path, "w", encoding="utf-8").write(t) print(f"css → {path}") PY fi # replace or insert rev block before python3 - "$f" "$block" <<'PY' import sys, re path, block = sys.argv[1], sys.argv[2] t = open(path, encoding="utf-8").read() block = block.rstrip() + "\n" pat = re.compile(r"[ \t]*.*?\n?", re.S) if pat.search(t): t = pat.sub(block, t, count=1) else: # before closing footer t2, n = re.subn(r"(\n)([ \t]*)", r"\1" + block + r"\2", t, count=1) if n != 1: raise SystemExit(f"could not insert landing-rev in {path}") t = t2 open(path, "w", encoding="utf-8").write(t) print(f"stamp → {path}") PY done echo "OK landing v${version} → ${short} (${human})"