#!/usr/bin/env bash # Export accounts.json → Hugging Face CONFIG_ENV secret format. # # Usage: # ./scripts/export-config-env.sh # ./scripts/export-config-env.sh /path/to/accounts.json # ./scripts/export-config-env.sh /path/to/accounts.json /path/to/output.txt # # Default output: /hf-config-env.txt (gitignored) # Paste that file into HF Space Settings → Secrets → CONFIG_ENV. set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)" ACCOUNTS_FILE="${1:-${HOME}/.config/antigravity-proxy/accounts.json}" OUTPUT_FILE="${2:-${REPO_ROOT}/hf-config-env.txt}" if [[ ! -f "${ACCOUNTS_FILE}" ]]; then echo "Error: accounts file not found: ${ACCOUNTS_FILE}" >&2 echo "Usage: $0 [path/to/accounts.json] [path/to/output.txt]" >&2 exit 1 fi node --input-type=module - "${ACCOUNTS_FILE}" <<'EOF' > "${OUTPUT_FILE}" import { readFileSync } from 'fs'; const accountsPath = process.argv[2]; let data; try { data = JSON.parse(readFileSync(accountsPath, 'utf8')); } catch (error) { console.error(`Error: failed to read ${accountsPath}: ${error.message}`); process.exit(1); } const accounts = data.accounts; if (!Array.isArray(accounts) || accounts.length === 0) { console.error('Error: no accounts found in file'); process.exit(1); } const lines = []; for (let i = 0; i < accounts.length; i += 1) { const acc = accounts[i]; const n = i + 1; const email = String(acc.email || '').trim(); const refreshToken = String(acc.refreshToken || '').trim(); if (!email || !refreshToken) { console.error(`Error: account ${n} is missing email or refreshToken`); process.exit(1); } const parts = refreshToken.split('|'); const projectId = String( acc.subscription?.projectId || parts[1] || parts[2] || '' ).trim(); let tier = String(acc.subscription?.tier || '').trim().toLowerCase(); if (!tier || tier === 'unknown') { tier = 'pro'; } lines.push(`ANTIGRAVITY_${n}_EMAIL=${email}`); lines.push(`ANTIGRAVITY_${n}_REFRESH_TOKEN=${refreshToken}`); if (projectId) { lines.push(`ANTIGRAVITY_${n}_PROJECT_ID=${projectId}`); } lines.push(`ANTIGRAVITY_${n}_TIER=${tier}`); lines.push(''); } process.stdout.write(lines.join('\n')); EOF chmod 600 "${OUTPUT_FILE}" account_count="$(grep -c '^ANTIGRAVITY_[0-9]\+_EMAIL=' "${OUTPUT_FILE}" || true)" echo "Wrote ${account_count} account(s) to: ${OUTPUT_FILE}" echo "Paste that file into Hugging Face → Space Settings → Secrets → CONFIG_ENV" echo "Do not commit this file (listed in .gitignore)."