| … | … | @@ -0,0 +1,138 @@ |
| 1 | #!/usr/bin/env bash |
| 2 | # Sync the currently-running Keet AppImage into this repo as a new commit. |
| 3 | # |
| 4 | # Default: auto-detects the running Keet's AppImage mount, infers version |
| 5 | # from its package.json, runs the audit, replaces the tracked tree with |
| 6 | # the new pretty/ snapshot, and commits + tags. |
| 7 | # |
| 8 | # Usage: |
| 9 | # tools/sync.sh # auto-detect everything |
| 10 | # tools/sync.sh --src <mount> # explicit mount path |
| 11 | # tools/sync.sh --version <v> # override version tag |
| 12 | # tools/sync.sh --no-tag # commit but don't tag |
| 13 | # tools/sync.sh --dry-run # show what would happen, no writes |
| 14 | # |
| 15 | # Pre-reqs: a running Keet AppImage so we can find its mount, OR pass --src. |
| 16 | |
| 17 | set -euo pipefail |
| 18 | |
| 19 | REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 20 | AUDIT_TOOL="$REPO_ROOT/../keet-cli/tools/keet-audit.cjs" |
| 21 | |
| 22 | SRC="" |
| 23 | VERSION="" |
| 24 | TAG=1 |
| 25 | DRY_RUN=0 |
| 26 | |
| 27 | while [ $# -gt 0 ]; do |
| 28 | case "$1" in |
| 29 | --src) SRC="$2"; shift 2 ;; |
| 30 | --version) VERSION="$2"; shift 2 ;; |
| 31 | --no-tag) TAG=0; shift ;; |
| 32 | --dry-run) DRY_RUN=1; shift ;; |
| 33 | -h|--help) sed -n '2,15p' "$0"; exit 0 ;; |
| 34 | *) echo "unknown arg: $1" >&2; exit 1 ;; |
| 35 | esac |
| 36 | done |
| 37 | |
| 38 | # Auto-detect mount from running Keet if --src not given |
| 39 | if [ -z "$SRC" ]; then |
| 40 | SRC=$(pgrep -af '/tmp/\.mount_Keet\..*/Keet' \ |
| 41 | | grep -oE '/tmp/\.mount_Keet\.[^ /]+' \ |
| 42 | | head -1) |
| 43 | if [ -z "$SRC" ]; then |
| 44 | echo "no running Keet AppImage found; pass --src <mount>" >&2 |
| 45 | exit 1 |
| 46 | fi |
| 47 | SRC="$SRC/resources/app/node_modules" |
| 48 | fi |
| 49 | |
| 50 | if [ ! -d "$SRC/@holepunchto" ]; then |
| 51 | echo "src does not look like a Keet node_modules dir: $SRC" >&2 |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | # Read version from app's own package.json |
| 56 | PKG_JSON="$(dirname "$SRC")/package.json" |
| 57 | if [ -z "$VERSION" ]; then |
| 58 | VERSION=$(grep -oE '"version"[[:space:]]*:[[:space:]]*"[^"]+"' "$PKG_JSON" \ |
| 59 | | head -1 | grep -oE '"[^"]+"$' | tr -d '"') |
| 60 | [ -z "$VERSION" ] && { echo "could not infer version from $PKG_JSON" >&2; exit 1; } |
| 61 | fi |
| 62 | |
| 63 | AUDIT_OUT="$REPO_ROOT/../keet-audit-$VERSION" |
| 64 | |
| 65 | echo "src: $SRC" |
| 66 | echo "version: $VERSION" |
| 67 | echo "audit out: $AUDIT_OUT" |
| 68 | echo "tag: $([ $TAG -eq 1 ] && echo "v$VERSION" || echo "(skipped)")" |
| 69 | echo "dry-run: $([ $DRY_RUN -eq 1 ] && echo yes || echo no)" |
| 70 | echo |
| 71 | |
| 72 | # Refuse if tag already exists |
| 73 | if [ $TAG -eq 1 ] && git -C "$REPO_ROOT" rev-parse "v$VERSION" >/dev/null 2>&1; then |
| 74 | echo "tag v$VERSION already exists in this repo — nothing to do." >&2 |
| 75 | exit 0 |
| 76 | fi |
| 77 | |
| 78 | # Refuse if working tree dirty |
| 79 | if [ -n "$(git -C "$REPO_ROOT" status --porcelain)" ]; then |
| 80 | echo "working tree is dirty; commit or stash first" >&2 |
| 81 | exit 1 |
| 82 | fi |
| 83 | |
| 84 | if [ $DRY_RUN -eq 1 ]; then |
| 85 | echo "(dry-run) would run: node $AUDIT_TOOL --src $SRC --out $AUDIT_OUT" |
| 86 | echo "(dry-run) would replace tracked tree from $AUDIT_OUT/pretty/" |
| 87 | echo "(dry-run) would commit + tag v$VERSION" |
| 88 | exit 0 |
| 89 | fi |
| 90 | |
| 91 | # 1. Run audit (idempotent — overwrites OUT) |
| 92 | if [ -d "$AUDIT_OUT" ]; then |
| 93 | echo "[1/4] audit dir already exists, reusing: $AUDIT_OUT" |
| 94 | else |
| 95 | echo "[1/4] running audit…" |
| 96 | node "$AUDIT_TOOL" --src "$SRC" --out "$AUDIT_OUT" >/dev/null |
| 97 | fi |
| 98 | |
| 99 | # 2. Wipe tracked content (keep .git, keep tools/, keep README files at root) |
| 100 | echo "[2/4] wiping tracked tree…" |
| 101 | cd "$REPO_ROOT" |
| 102 | git ls-files -z \ |
| 103 | | grep -zvE '^(tools/|README\.md$|\.gitignore$)' \ |
| 104 | | xargs -0 -r rm -f |
| 105 | find . -type d -empty -not -path './.git*' -not -path './tools*' -delete |
| 106 | |
| 107 | # 3. Copy fresh snapshot in |
| 108 | echo "[3/4] copying $VERSION snapshot…" |
| 109 | cp -a "$AUDIT_OUT/pretty/." ./ |
| 110 | cp "$AUDIT_OUT/MANIFEST.md" ./MANIFEST.md |
| 111 | |
| 112 | # 4. Commit + tag |
| 113 | echo "[4/4] committing…" |
| 114 | git add -A |
| 115 | if git diff --cached --quiet; then |
| 116 | echo "no changes vs prior commit — nothing to do." |
| 117 | exit 0 |
| 118 | fi |
| 119 | |
| 120 | PREV_TAG=$(git tag --sort=-v:refname | head -1) |
| 121 | git commit -q -m "keet $VERSION — OTA update from ${PREV_TAG:-initial} |
| 122 | |
| 123 | Captured: $(date -u +%Y-%m-%dT%H:%M:%SZ) |
| 124 | Source: $SRC |
| 125 | |
| 126 | Run \`git diff $PREV_TAG v$VERSION\` for the full changelog. |
| 127 | |
| 128 | Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>" |
| 129 | |
| 130 | if [ $TAG -eq 1 ]; then |
| 131 | git tag "v$VERSION" |
| 132 | fi |
| 133 | |
| 134 | echo |
| 135 | echo "done. summary:" |
| 136 | git log --oneline -3 |
| 137 | echo |
| 138 | git diff --shortstat "${PREV_TAG:-$(git rev-list --max-parents=0 HEAD)}" HEAD |