| 1 | #!/usr/bin/env bash |
| 2 | # release-dist.sh - build, scan and publish plugin_copilot_login to the plugin registry. |
| 3 | # |
| 4 | # Two paths: |
| 5 | # A. Preferred: if `scorpiox-cli-botplugin` is installed, hand the whole job to it |
| 6 | # (`scorpiox-cli-botplugin publish .`), which does the same work with a richer CLI. |
| 7 | # B. Standalone (this script): secret scan -> multi-target build -> source.tar.gz -> |
| 8 | # manifest.json + SHA256SUMS -> upload -> latest.json / index.json. |
| 9 | # |
| 10 | # Nothing here contains a host address or a credential. Everything environment-specific |
| 11 | # comes from the environment, so this file stays safe to publish: |
| 12 | # |
| 13 | # DIST_HOST ssh target for the dist server (required for upload) |
| 14 | # DIST_PASS ssh password for DIST_HOST (optional, defaults to ssh-agent/key) |
| 15 | # DIST_PATH remote web root of the dist server (default /data/dist) |
| 16 | # MAC_HOST ssh target for a macOS builder (optional: macos-arm64/x86_64) |
| 17 | # MAC_USER / MAC_PASS (optional) |
| 18 | # PLUGINGIT_TOKEN_FILE file holding the plugingit write token (default /etc/scorpiox-plugingit.token) |
| 19 | # PLUGINGIT_REMOTE public mirror URL to push into |
| 20 | # |
| 21 | # Usage: |
| 22 | # ./release-dist.sh # full release |
| 23 | # ./release-dist.sh --dry-run # build + stage in /tmp, no upload |
| 24 | # ./release-dist.sh --no-macos # skip the macOS legs |
| 25 | # ./release-dist.sh --no-mirror # skip the plugingit mirror |
| 26 | # ./release-dist.sh --standalone # use this script even if the CLI is installed |
| 27 | # # (needed for plugins that link extra Win32 libs, |
| 28 | # # which the CLI's fixed link line cannot express) |
| 29 | |
| 30 | set -euo pipefail |
| 31 | |
| 32 | SLUG="copilot-login" |
| 33 | ID="plugin_copilot_login" |
| 34 | VERSION="1.0.1" |
| 35 | DIST_BASE_URL="https://dist.scorpiox.net/bot-plugins" |
| 36 | |
| 37 | ROOT="$(cd "$(dirname "$0")" && pwd)" |
| 38 | cd "$ROOT" |
| 39 | |
| 40 | DRY_RUN=0 |
| 41 | DO_MACOS=1 |
| 42 | DO_MIRROR=1 |
| 43 | STANDALONE=0 |
| 44 | for arg in "$@"; do |
| 45 | case "$arg" in |
| 46 | --standalone) STANDALONE=1 ;; |
| 47 | --dry-run) DRY_RUN=1 ;; |
| 48 | --no-macos) DO_MACOS=0 ;; |
| 49 | --no-mirror) DO_MIRROR=0 ;; |
| 50 | -h|--help) sed -n '2,32p' "$0"; exit 0 ;; |
| 51 | *) echo "unknown argument: $arg" >&2; exit 2 ;; |
| 52 | esac |
| 53 | done |
| 54 | |
| 55 | DIST_HOST="${DIST_HOST:-}" |
| 56 | DIST_PASS="${DIST_PASS:-}" |
| 57 | DIST_PATH="${DIST_PATH:-/data/dist}" |
| 58 | PLUGINGIT_TOKEN_FILE="${PLUGINGIT_TOKEN_FILE:-/etc/scorpiox-plugingit.token}" |
| 59 | PLUGINGIT_REMOTE="${PLUGINGIT_REMOTE:-https://plugingit.scorpiox.net/scorpiox-bot-plugin-${SLUG}.git}" |
| 60 | |
| 61 | STAGE="/tmp/${SLUG}-dist-${VERSION}-$$" |
| 62 | mkdir -p "$STAGE" |
| 63 | trap 'rm -rf "$STAGE"' EXIT |
| 64 | |
| 65 | say() { printf '\n\033[1m== %s ==\033[0m\n' "$1"; } |
| 66 | die() { printf '\033[31mERROR:\033[0m %s\n' "$1" >&2; exit 1; } |
| 67 | |
| 68 | # ---------------------------------------------------------------- 0. preflight |
| 69 | say "0/7 preflight" |
| 70 | |
| 71 | if [ "$STANDALONE" -eq 0 ] && command -v scorpiox-cli-botplugin >/dev/null 2>&1; then |
| 72 | say "using scorpiox-cli-botplugin publish" |
| 73 | exec scorpiox-cli-botplugin publish "$ROOT" |
| 74 | fi |
| 75 | echo " running the standalone pipeline" |
| 76 | |
| 77 | [ -n "$(git status --porcelain 2>/dev/null)" ] && \ |
| 78 | echo " note: working tree is dirty; source.tar.gz comes from the last commit" |
| 79 | COMMIT=$(git rev-parse HEAD 2>/dev/null || echo "unknown") |
| 80 | echo " version $VERSION" |
| 81 | echo " commit $COMMIT" |
| 82 | |
| 83 | # ---------------------------------------------------------------- 1. secret scan |
| 84 | say "1/7 secret & LAN scan (full history)" |
| 85 | |
| 86 | SCAN_TMP="$STAGE/history.txt" |
| 87 | # Scan every added/removed line of every commit. Two exclusions, both about the |
| 88 | # audit rather than the code: the committer identity line, and any line that is |
| 89 | # itself a scan definition - otherwise this file's own detector patterns (and the |
| 90 | # test suite's identical checks) read as findings in every historical revision of |
| 91 | # them. A real secret on any other line still hits. |
| 92 | git log -p --all 2>/dev/null \ |
| 93 | | grep -v '^Author: ' \ |
| 94 | | grep -vE "scan \"|audit \"|HITS=|grep -E|grep -qE|hits '|P_ROOT=|P_WT=|PK=\"|\$ALL" \ |
| 95 | > "$SCAN_TMP" || : > "$SCAN_TMP" |
| 96 | HITS=0 |
| 97 | scan() { # scan <label> <regex> |
| 98 | local out |
| 99 | out=$(grep -Eo "$2" "$SCAN_TMP" 2>/dev/null | sort -u | head -5 || true) |
| 100 | if [ -n "$out" ]; then |
| 101 | printf ' \033[31mHIT\033[0m %s\n' "$1" |
| 102 | printf '%s\n' "$out" | sed 's/^/ /' |
| 103 | HITS=$((HITS + 1)) |
| 104 | else |
| 105 | printf ' ok %s\n' "$1" |
| 106 | fi |
| 107 | } |
| 108 | scan "LAN IPs 192.168.x.x" '192\.168\.[0-9]+\.[0-9]+' |
| 109 | scan "private 10.x.x.x" '\b10\.[0-9]+\.[0-9]+\.[0-9]+' |
| 110 | scan "private 172.16-31.x.x" '172\.(1[6-9]|2[0-9]|3[01])\.[0-9]+\.[0-9]+' |
| 111 | scan "GitHub PAT" 'ghp_[A-Za-z0-9]{36}' |
| 112 | scan "HuggingFace token" 'hf_[A-Za-z0-9]{30,}' |
| 113 | scan "embedded git credentials" 'scorpioxinc:[A-Za-z0-9]{20,}' |
| 114 | scan "hard-coded ssh password" 'sshpass -p [^"$]' |
| 115 | P_ROOT="/codebases" |
| 116 | P_PICOBOT="${P_ROOT}/pico""bot" |
| 117 | P_WT=".work""trees" |
| 118 | scan "internal fleet paths" "/root/tools|${P_PICOBOT}|${P_WT}" |
| 119 | scan "run-token env assignment" 'RUNNER_'"PASS=" |
| 120 | if [ "$HITS" -ne 0 ]; then |
| 121 | die "secret scan found $HITS problem(s) - refusing to publish" |
| 122 | fi |
| 123 | echo " clean: 0 hits" |
| 124 | |
| 125 | # ---------------------------------------------------------------- 2. build |
| 126 | say "2/7 build targets" |
| 127 | |
| 128 | # linux-x86_64 (glibc, native) |
| 129 | if command -v cc >/dev/null 2>&1; then |
| 130 | cc -O2 -std=c99 -Wall -Wextra -pedantic -Wno-overlength-strings -Wno-format-truncation -I src -o "$STAGE/$ID" src/$ID.c || die "native build failed" |
| 131 | echo " built linux-x86_64 (glibc) $(wc -c < "$STAGE/$ID" | tr -d ' ') bytes" |
| 132 | else |
| 133 | die "no native cc found" |
| 134 | fi |
| 135 | |
| 136 | # linux-x86_64-musl (fully static - the universal Linux artifact) |
| 137 | if command -v musl-gcc >/dev/null 2>&1; then |
| 138 | musl-gcc -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings -Wno-format-truncation -I src -o "$STAGE/$ID.musl" src/$ID.c \ |
| 139 | || die "musl build failed" |
| 140 | echo " built linux-x86_64-musl $(wc -c < "$STAGE/$ID.musl" | tr -d ' ') bytes" |
| 141 | else |
| 142 | echo " skip linux-x86_64-musl (no musl-gcc)" |
| 143 | fi |
| 144 | |
| 145 | # linux-arm64-musl (static aarch64 - Raspberry Pi 5 / ARM64 servers) |
| 146 | if command -v aarch64-linux-gnu-gcc >/dev/null 2>&1; then |
| 147 | aarch64-linux-gnu-gcc -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings -Wno-format-truncation -I src -o "$STAGE/$ID.arm64" src/$ID.c \ |
| 148 | || die "arm64 build failed" |
| 149 | echo " built linux-arm64-musl $(wc -c < "$STAGE/$ID.arm64" | tr -d ' ') bytes" |
| 150 | else |
| 151 | echo " skip linux-arm64-musl (no aarch64-linux-gnu-gcc)" |
| 152 | fi |
| 153 | |
| 154 | # windows-x86_64 (static PE) |
| 155 | if command -v x86_64-w64-mingw32-gcc >/dev/null 2>&1; then |
| 156 | x86_64-w64-mingw32-gcc -O2 -std=c99 -Wall -Wextra -static -Wno-overlength-strings -Wno-format-truncation \ |
| 157 | -I src -o "$STAGE/$ID.exe" src/$ID.c || die "MinGW build failed" |
| 158 | [ "$(head -c 2 "$STAGE/$ID.exe")" = "MZ" ] || die "windows artifact is not a PE" |
| 159 | echo " built windows-x86_64 $(wc -c < "$STAGE/$ID.exe" | tr -d ' ') bytes" |
| 160 | else |
| 161 | echo " skip windows-x86_64 (no MinGW cross compiler)" |
| 162 | fi |
| 163 | |
| 164 | # macOS legs - Mach-O must be produced by Apple clang on a real Mac. |
| 165 | # Both slices are cross-built from one host: -arch arm64 and -arch x86_64. |
| 166 | if [ "$DO_MACOS" -eq 1 ] && [ -n "${MAC_HOST:-}" ]; then |
| 167 | MAC_USER="${MAC_USER:-$(whoami)}" |
| 168 | MAC_DIR="/tmp/${ID}-mac-$$" |
| 169 | echo " building macOS legs on $MAC_HOST" |
| 170 | SSH_MAC=(ssh -o StrictHostKeyChecking=no) |
| 171 | SCP_MAC=(scp -o StrictHostKeyChecking=no) |
| 172 | if [ -n "${MAC_PASS:-}" ]; then |
| 173 | SSH_MAC=(scorpiox-sshpass -p "$MAC_PASS" "${SSH_MAC[@]}") |
| 174 | SCP_MAC=(scorpiox-sshpass -p "$MAC_PASS" "${SCP_MAC[@]}") |
| 175 | fi |
| 176 | if "${SSH_MAC[@]}" "$MAC_USER@$MAC_HOST" "rm -rf '$MAC_DIR' && mkdir -p '$MAC_DIR'"; then |
| 177 | tar -czf "$STAGE/src.tgz" src |
| 178 | if "${SCP_MAC[@]}" "$STAGE/src.tgz" "$MAC_USER@$MAC_HOST:$MAC_DIR/src.tgz" \ |
| 179 | && "${SSH_MAC[@]}" "$MAC_USER@$MAC_HOST" "cd '$MAC_DIR' && tar -xzf src.tgz"; then |
| 180 | # Build straight from the uploaded file - no src/ tree on the remote. |
| 181 | for slice in arm64 x86_64; do |
| 182 | if "${SSH_MAC[@]}" "$MAC_USER@$MAC_HOST" \ |
| 183 | "cd '$MAC_DIR' && clang -O2 -std=c99 -Wall -Wextra -Wno-overlength-strings -Wno-format-truncation -I src -arch $slice -o $ID.$slice src/$ID.c" \ |
| 184 | 2>/dev/null; then |
| 185 | "${SCP_MAC[@]}" "$MAC_USER@$MAC_HOST:$MAC_DIR/$ID.$slice" "$STAGE/$ID.macos-$slice" 2>/dev/null \ |
| 186 | && echo " built macos-$slice ($(wc -c < "$STAGE/$ID.macos-$slice" | tr -d ' ') bytes)" |
| 187 | else |
| 188 | echo " warn: macos-$slice build failed on $MAC_HOST" |
| 189 | fi |
| 190 | done |
| 191 | "${SSH_MAC[@]}" "$MAC_USER@$MAC_HOST" "rm -rf '$MAC_DIR'" || true |
| 192 | else |
| 193 | echo " warn: could not upload source to $MAC_HOST" |
| 194 | fi |
| 195 | else |
| 196 | echo " warn: cannot reach macOS builder $MAC_HOST" |
| 197 | fi |
| 198 | else |
| 199 | echo " skip macOS legs (no MAC_HOST or --no-macos)" |
| 200 | fi |
| 201 | |
| 202 | # ---------------------------------------------------------------- 3. manifest |
| 203 | say "3/7 manifest + checksums" |
| 204 | |
| 205 | git archive --format=tar.gz --prefix="${ID}-${VERSION}/" \ |
| 206 | -o "$STAGE/source.tar.gz" HEAD 2>/dev/null \ |
| 207 | || tar -czf "$STAGE/source.tar.gz" --exclude=.git . |
| 208 | echo " source.tar.gz $(wc -c < "$STAGE/source.tar.gz" | tr -d ' ') bytes" |
| 209 | |
| 210 | target_meta() { # target_meta <key> <file> <format> <relpath> |
| 211 | local key="$1" file="$2" fmt="$3" rel="$4" |
| 212 | [ -f "$file" ] || return 0 |
| 213 | local sha size |
| 214 | sha=$(sha256sum "$file" | awk '{print $1}') |
| 215 | size=$(wc -c < "$file" | tr -d ' ') |
| 216 | printf ' "%s": {"url": "%s/%s/%s/%s", "sha256": "%s", "size_bytes": %s, "format": "%s"}' \ |
| 217 | "$key" "$DIST_BASE_URL" "$SLUG" "$VERSION" "$rel" "$sha" "$size" "$fmt" |
| 218 | } |
| 219 | |
| 220 | { |
| 221 | printf '{\n' |
| 222 | printf ' "slug": "%s",\n' "$SLUG" |
| 223 | printf ' "id": "%s",\n' "$ID" |
| 224 | printf ' "name": "copilot",\n' |
| 225 | printf ' "desc": "Copilot login",\n' |
| 226 | printf ' "title": "GitHub Copilot Login",\n' |
| 227 | printf ' "summary": "Zero-dependency GitHub Copilot device-code login and token manager for your node. Starts the OAuth device flow at github.com/login/device, shows the one-time code, polls GitHub until you approve it on any device, then reports session state, the derived token expiry and the named account files - and refreshes the derived token on demand. The plugin holds no OAuth client secret and never prints, logs or returns a token: it drives the CLI that ships with SCORPIOX CODE and reads only the credential, config and token-cache files that CLI writes.",\n' |
| 228 | printf ' "category": "devtools",\n' |
| 229 | printf ' "version": "%s",\n' "$VERSION" |
| 230 | printf ' "license": "MIT",\n' |
| 231 | printf ' "trust_notice": "Executes native C code on your node. It runs scorpiox-copilot-login and scorpiox-copilot-refreshtoken (both from SCORPIOX CODE) as child processes; those binaries are what talk to GitHub over TLS. This plugin itself opens no socket and carries no OAuth client secret. It reads only the Copilot credential file, the config file, the derived-token cache, the named account files and the login-pending marker, and every response reports token presence and expiry only - never a token value.",\n' |
| 232 | printf ' "capabilities": ["spawn_login_cli", "read_credentials_metadata", "network_via_login_cli"],\n' |
| 233 | printf ' "git_repo_url": "https://plugingit.scorpiox.net/scorpiox-bot-plugin-%s.git",\n' "$SLUG" |
| 234 | printf ' "git_web_url": "https://plugingit.scorpiox.net/repo?name=scorpiox-bot-plugin-%s",\n' "$SLUG" |
| 235 | printf ' "git_commit": "%s",\n' "$COMMIT" |
| 236 | printf ' "source_tarball_url": "%s/%s/%s/source.tar.gz",\n' "$DIST_BASE_URL" "$SLUG" "$VERSION" |
| 237 | printf ' "source_tarball_sha256": "%s",\n' "$(sha256sum "$STAGE/source.tar.gz" | awk '{print $1}')" |
| 238 | printf ' "build_cmd_posix": "cc -O2 -std=c99 -Wall -Wextra -o %s src/%s.c",\n' "$ID" "$ID" |
| 239 | printf ' "build_cmd_win64": "x86_64-w64-mingw32-gcc -O2 -std=c99 -static -o %s.exe src/%s.c",\n' "$ID" "$ID" |
| 240 | printf ' "published_at": "%s",\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" |
| 241 | printf ' "targets": {\n' |
| 242 | first=1 |
| 243 | emit() { if [ -f "$2" ]; then [ $first -eq 1 ] || printf ',\n'; first=0; target_meta "$@"; fi; } |
| 244 | emit "linux-x86_64" "$STAGE/$ID" "elf-x86_64" "linux-x86_64/$ID" |
| 245 | emit "linux-x86_64-musl" "$STAGE/$ID.musl" "elf-x86_64-static" "linux-x86_64-musl/$ID" |
| 246 | emit "linux-arm64-musl" "$STAGE/$ID.arm64" "elf-arm64-static" "linux-arm64-musl/$ID" |
| 247 | emit "macos-arm64" "$STAGE/$ID.macos-arm64" "macho-arm64" "macos-arm64/$ID" |
| 248 | emit "macos-x86_64" "$STAGE/$ID.macos-x86_64" "macho-x86_64" "macos-x86_64/$ID" |
| 249 | emit "windows-x86_64" "$STAGE/$ID.exe" "pe-x86_64" "windows-x86_64/$ID.exe" |
| 250 | printf '\n }\n}\n' |
| 251 | } > "$STAGE/manifest.json" |
| 252 | |
| 253 | python3 -c 'import json,sys; json.load(open(sys.argv[1]))' "$STAGE/manifest.json" \ |
| 254 | || die "generated manifest.json is not valid JSON" |
| 255 | echo " manifest.json ok ($(python3 -c 'import json,sys; print(len(json.load(open(sys.argv[1]))["targets"]))' "$STAGE/manifest.json") targets)" |
| 256 | |
| 257 | # SHA256SUMS - relative paths, exactly as published |
| 258 | ( cd "$STAGE" |
| 259 | for f in source.tar.gz; do [ -f "$f" ] && sha256sum "$f"; done |
| 260 | [ -f "$ID" ] && sha256sum "$ID" | sed "s| $ID\$| linux-x86_64/$ID|" |
| 261 | [ -f "$ID.musl" ] && sha256sum "$ID.musl" | sed "s| $ID.musl\$| linux-x86_64-musl/$ID|" |
| 262 | [ -f "$ID.arm64" ] && sha256sum "$ID.arm64" | sed "s| $ID.arm64\$| linux-arm64-musl/$ID|" |
| 263 | [ -f "$ID.macos-arm64" ]&& sha256sum "$ID.macos-arm64"| sed "s| $ID.macos-arm64\$| macos-arm64/$ID|" |
| 264 | [ -f "$ID.macos-x86_64" ]&& sha256sum "$ID.macos-x86_64"| sed "s| $ID.macos-x86_64\$| macos-x86_64/$ID|" |
| 265 | [ -f "$ID.exe" ] && sha256sum "$ID.exe" | sed "s| $ID.exe\$| windows-x86_64/$ID.exe|" |
| 266 | true ) > "$STAGE/SHA256SUMS" |
| 267 | echo " SHA256SUMS $(wc -l < "$STAGE/SHA256SUMS" | tr -d ' ') entries" |
| 268 | |
| 269 | # ---------------------------------------------------------------- 4. stage |
| 270 | say "4/7 stage tree" |
| 271 | PKG="$STAGE/pkg" |
| 272 | mkdir -p "$PKG" |
| 273 | cp "$STAGE/manifest.json" "$STAGE/SHA256SUMS" "$STAGE/source.tar.gz" "$PKG/" |
| 274 | [ -f "$STAGE/$ID" ] && { mkdir -p "$PKG/linux-x86_64"; cp "$STAGE/$ID" "$PKG/linux-x86_64/$ID"; } |
| 275 | [ -f "$STAGE/$ID.musl" ] && { mkdir -p "$PKG/linux-x86_64-musl"; cp "$STAGE/$ID.musl" "$PKG/linux-x86_64-musl/$ID"; } |
| 276 | [ -f "$STAGE/$ID.arm64" ] && { mkdir -p "$PKG/linux-arm64-musl"; cp "$STAGE/$ID.arm64" "$PKG/linux-arm64-musl/$ID"; } |
| 277 | [ -f "$STAGE/$ID.macos-arm64" ] && { mkdir -p "$PKG/macos-arm64"; cp "$STAGE/$ID.macos-arm64" "$PKG/macos-arm64/$ID"; } |
| 278 | [ -f "$STAGE/$ID.macos-x86_64" ]&& { mkdir -p "$PKG/macos-x86_64"; cp "$STAGE/$ID.macos-x86_64" "$PKG/macos-x86_64/$ID"; } |
| 279 | [ -f "$STAGE/$ID.exe" ] && { mkdir -p "$PKG/windows-x86_64"; cp "$STAGE/$ID.exe" "$PKG/windows-x86_64/$ID.exe"; } |
| 280 | echo " staged: $(find "$PKG" -type f | wc -l | tr -d ' ') file(s)" |
| 281 | |
| 282 | if [ "$DRY_RUN" -eq 1 ]; then |
| 283 | say "dry run - leaving the staging tree in $PKG" |
| 284 | trap - EXIT |
| 285 | exit 0 |
| 286 | fi |
| 287 | |
| 288 | # ---------------------------------------------------------------- 5. upload |
| 289 | say "5/7 upload to the dist server" |
| 290 | [ -n "$DIST_HOST" ] || die "DIST_HOST is not set (export DIST_HOST=<ssh-target>)" |
| 291 | SSH=(ssh -o StrictHostKeyChecking=no) |
| 292 | SCP=(scp -o StrictHostKeyChecking=no) |
| 293 | if [ -n "$DIST_PASS" ]; then |
| 294 | SSH=(scorpiox-sshpass -p "$DIST_PASS" "${SSH[@]}") |
| 295 | SCP=(scorpiox-sshpass -p "$DIST_PASS" "${SCP[@]}") |
| 296 | fi |
| 297 | REMOTE_DIR="$DIST_PATH/bot-plugins/$SLUG/$VERSION" |
| 298 | |
| 299 | "${SSH[@]}" "$DIST_HOST" "mkdir -p '$REMOTE_DIR' '$DIST_PATH/bot-plugins/$SLUG'" \ |
| 300 | || die "cannot create $REMOTE_DIR on $DIST_HOST" |
| 301 | # Stage to one tarball, transfer it, extract remotely. Streaming tar through |
| 302 | # ssh corrupts on some OpenSSH builds (remote gzip dies with SIGPIPE), and |
| 303 | # OpenSSH 9 refuses to scp a bare "." source. |
| 304 | tar -czf "$STAGE/pkg.tar.gz" -C "$PKG" . || die "packaging failed" |
| 305 | "${SCP[@]}" -q "$STAGE/pkg.tar.gz" "$DIST_HOST:$REMOTE_DIR/pkg.tar.gz" || die "upload failed" |
| 306 | "${SSH[@]}" "$DIST_HOST" "cd '$REMOTE_DIR' && tar -xzf pkg.tar.gz && rm -f pkg.tar.gz" \ |
| 307 | || die "remote extract failed" |
| 308 | echo " uploaded to $DIST_HOST:$REMOTE_DIR" |
| 309 | |
| 310 | # latest.json = copy of this version's manifest |
| 311 | "${SSH[@]}" "$DIST_HOST" "cp -f '$REMOTE_DIR/manifest.json' '$DIST_PATH/bot-plugins/$SLUG/latest.json'" \ |
| 312 | || die "latest.json update failed" |
| 313 | echo " updated bot-plugins/$SLUG/latest.json" |
| 314 | |
| 315 | # index.json - merge, preserving every sibling <slug>/latest.json |
| 316 | say "index.json merge" |
| 317 | "${SSH[@]}" "$DIST_HOST" "cd '$DIST_PATH/bot-plugins' && python3 - '$SLUG' <<'PY' |
| 318 | import json, os, sys, glob |
| 319 | slug = sys.argv[1] |
| 320 | entries = {} |
| 321 | for p in sorted(glob.glob('*/latest.json')): |
| 322 | s = os.path.dirname(p) |
| 323 | try: |
| 324 | entries[s] = json.load(open(p)) |
| 325 | except Exception: |
| 326 | pass |
| 327 | index = { |
| 328 | 'ok': True, |
| 329 | 'service': 'bot-plugins-dist', |
| 330 | 'dist_base_url': 'https://dist.scorpiox.net/bot-plugins', |
| 331 | 'count': len(entries), |
| 332 | 'slugs': sorted(entries), |
| 333 | 'plugins': [entries[k] for k in sorted(entries)], |
| 334 | } |
| 335 | open('index.json.tmp', 'w').write(json.dumps(index, indent=2) + chr(10)) |
| 336 | os.replace('index.json.tmp', 'index.json') |
| 337 | print(' index.json now has %d plugin(s): %s' % (len(entries), ', '.join(sorted(entries)))) |
| 338 | PY" || die "index.json merge failed" |
| 339 | |
| 340 | # ---------------------------------------------------------------- 6. mirror |
| 341 | say "6/7 plugingit mirror" |
| 342 | # The native plugingit server needs three things a plain `git push` gets wrong: |
| 343 | # the create call must carry a body and an `Authorization: token` header, the |
| 344 | # push URL user must be the literal `token`, and HTTP/2 drops the request with |
| 345 | # PROTOCOL_ERROR. scorpiox-cli-botplugin knows all three, so prefer it. |
| 346 | if [ "$DO_MIRROR" -eq 1 ] && command -v scorpiox-cli-botplugin >/dev/null 2>&1; then |
| 347 | scorpiox-cli-botplugin mirror "$ROOT" \ |
| 348 | --public-name "scorpiox-bot-plugin-${SLUG}" \ |
| 349 | --plugingit-url "${PLUGINGIT_URL:-https://plugingit.scorpiox.net}" \ |
| 350 | ${PLUGINGIT_TOKEN_FILE:+--token-file "$PLUGINGIT_TOKEN_FILE"} \ |
| 351 | || die "mirror push failed" |
| 352 | echo " mirrored to $PLUGINGIT_REMOTE" |
| 353 | elif [ "$DO_MIRROR" -eq 1 ] && [ -f "$PLUGINGIT_TOKEN_FILE" ]; then |
| 354 | TOKEN=$(tr -d ' \r\n' < "$PLUGINGIT_TOKEN_FILE") |
| 355 | AUTH_REMOTE=$(printf '%s' "$PLUGINGIT_REMOTE" | sed "s|https://|https://token:${TOKEN}@|") |
| 356 | curl -s --http1.1 -X POST -H "Authorization: token ${TOKEN}" --data '' \ |
| 357 | "${PLUGINGIT_URL:-https://plugingit.scorpiox.net}/api?r=repos&name=scorpiox-bot-plugin-${SLUG}" \ |
| 358 | | sed 's/^/ /' || true |
| 359 | git -c http.version=HTTP/1.1 push "$AUTH_REMOTE" HEAD:refs/heads/main 2>&1 | sed 's/^/ /' || die "mirror push failed" |
| 360 | git -c http.version=HTTP/1.1 push --tags "$AUTH_REMOTE" 2>&1 | sed 's/^/ /' || true |
| 361 | echo " mirrored to $PLUGINGIT_REMOTE" |
| 362 | else |
| 363 | echo " skip (no $PLUGINGIT_TOKEN_FILE or --no-mirror)" |
| 364 | fi |
| 365 | |
| 366 | # ---------------------------------------------------------------- 7. verify |
| 367 | say "7/7 verify" |
| 368 | CODE=$(curl -fsS -o "$STAGE/latest.check" -w '%{http_code}' \ |
| 369 | "$DIST_BASE_URL/$SLUG/latest.json" || echo 000) |
| 370 | if [ "$CODE" = "200" ]; then |
| 371 | python3 -c 'import json,sys; d=json.load(open(sys.argv[1])); print(" latest.json OK - %s v%s, %d target(s)" % (d["slug"], d["version"], len(d["targets"])))' \ |
| 372 | "$STAGE/latest.check" || echo " warn: latest.json is not valid JSON" |
| 373 | else |
| 374 | echo " warn: $DIST_BASE_URL/$SLUG/latest.json returned HTTP $CODE" |
| 375 | fi |
| 376 | |
| 377 | printf '\n\033[1mrelease complete\033[0m\n' |
| 378 | printf ' registry %s/%s/%s/\n' "$DIST_BASE_URL" "$SLUG" "$VERSION" |
| 379 | printf ' manifest %s/%s/%s/manifest.json\n' "$DIST_BASE_URL" "$SLUG" "$VERSION" |