#!/usr/bin/env bash # Export all live CyberLux .onion URLs to onion-urls.txt in the repo root. # Reads /var/lib/tor/*/hostname — run with sudo if needed. # # bash scripts/export-onion-urls.sh # sudo bash scripts/export-onion-urls.sh # set -euo pipefail REPO="$(cd "$(dirname "$0")/.." && pwd)" TOR_DIRS="${REPO}/scripts/generated/tor-dirs.txt" LABELS="${REPO}/scripts/generated/onion-labels.tsv" OUT="${REPO}/onion-urls.txt" if [[ ! -f "${TOR_DIRS}" ]]; then echo "[!] Missing ${TOR_DIRS}. Run: node scripts/generate-onion-config.cjs" exit 1 fi declare -A ROLE=() if [[ -f "${LABELS}" ]]; then while IFS=$'\t' read -r dir desc || [[ -n "${dir}" ]]; do [[ -z "${dir}" ]] && continue ROLE["${dir}"]="${desc}" done < "${LABELS}" fi read_host() { local f="$1" if [[ -r "${f}" ]]; then tr -d '\n' < "${f}" elif command -v sudo >/dev/null 2>&1 && sudo test -r "${f}" 2>/dev/null; then sudo tr -d '\n' < "${f}" else echo "" fi } { echo "# CyberLux — Live .onion URLs" echo "# Generated: $(date -u '+%Y-%m-%d %H:%M:%S UTC')" echo "# Open in: Tor Browser / Onion Browser (iOS) — http:// only" echo "#" echo "" ready=0 missing=0 while IFS= read -r d || [[ -n "${d}" ]]; do [[ -z "${d}" ]] && continue f="/var/lib/tor/${d}/hostname" host="$(read_host "${f}")" role="${ROLE[$d]:-}" if [[ -n "${host}" ]]; then printf '%-28s http://%s\n' "${d}" "${host}" [[ -n "${role}" ]] && printf '%-28s %s\n' "" "# ${role}" echo "" ((ready++)) || true else printf '%-28s (not available — %s)\n' "${d}" "${f}" echo "" ((missing++)) || true fi done < "${TOR_DIRS}" echo "# Services resolved: ${ready}" [[ "${missing}" -gt 0 ]] && echo "# Services pending: ${missing} (start Tor and wait ~30s)" } > "${OUT}" chmod a+r "${OUT}" 2>/dev/null || true echo "[*] Wrote ${OUT}" echo "[*] Services resolved: ${ready} / $((ready + missing))" [[ "${missing}" -gt 0 ]] && echo "[!] ${missing} hostname(s) not yet available — run again after Tor fully starts."