Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions scripts/register_phala_phone.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,49 @@
#!/bin/bash
# Register the surviving Signal number (phone B) via proxy :8081.
# Register SIGNAL_PHONE from docker/.phala.env via the live CVM proxy :8081.
#
# Phone B should already be registered on the live CVM — skip if
# accounts already lists it. Do not re-register phone A.
# Skip if /v1/debug/signal-accounts already lists that number.
# Do not point this at local docker/.env — that is a different number.
#
# Usage:
# CAPTCHA_TR='signalcaptcha://...' ./scripts/register_phala_phone.sh
# Then when SMS arrives:
# SMS_TR=123456 ./scripts/register_phala_phone.sh --verify
#
# Optional overrides: PHONE_TR, APP_ID, TR_PROXY, ENV_FILE
set -euo pipefail

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
ENV_FILE="${ENV_FILE:-$ROOT/docker/.phala.env}"

if [[ ! -f "$ENV_FILE" ]]; then
echo "Error: missing $ENV_FILE (copy docker/.phala.env.example)" >&2
exit 1
fi

# Load SIGNAL_PHONE from Phala env without sourcing the whole file.
SIGNAL_PHONE_FROM_ENV="$(
grep -E '^SIGNAL_PHONE=' "$ENV_FILE" | head -n1 | cut -d= -f2- | tr -d '\r' | tr -d '"' | tr -d "'"
)"
if [[ -z "${SIGNAL_PHONE_FROM_ENV}" ]]; then
echo "Error: SIGNAL_PHONE unset in $ENV_FILE" >&2
exit 1
fi

APP_ID="${APP_ID:-9adac7636fe255182f699940ffd1924960415507}"
GATEWAY="${GATEWAY:-dstack-pha-prod9.phala.network}"
TR_PROXY="${TR_PROXY:-https://${APP_ID}-8081.${GATEWAY}}"
PHONE_TR="${PHONE_TR:-+573107677679}"
# Prefer explicit PHONE_TR; otherwise always use docker/.phala.env SIGNAL_PHONE.
PHONE_TR="${PHONE_TR:-$SIGNAL_PHONE_FROM_ENV}"

MODE="${1:-register}"

if [[ "$PHONE_TR" == "$SIGNAL_PHONE_FROM_ENV" ]]; then
echo "Using phone $PHONE_TR from $ENV_FILE"
else
echo "Using phone $PHONE_TR (PHONE_TR override; .phala.env has $SIGNAL_PHONE_FROM_ENV)"
fi
echo "Proxy: $TR_PROXY"

if [[ "$MODE" == "--verify" ]]; then
if [[ -z "${SMS_TR:-}" ]]; then
echo "Error: set SMS_TR" >&2
Expand All @@ -28,7 +55,7 @@ if [[ "$MODE" == "--verify" ]]; then
echo
else
if [[ -z "${CAPTCHA_TR:-}" ]]; then
echo "Error: set CAPTCHA_TR (phone B / :8081)" >&2
echo "Error: set CAPTCHA_TR (full signalcaptcha://… string)" >&2
exit 1
fi
echo "Registering $PHONE_TR on :8081..."
Expand All @@ -38,5 +65,5 @@ else
echo
fi

echo "Accounts (translation :8081):"
echo "Accounts (CVM :8081):"
curl -sS "$TR_PROXY/v1/debug/signal-accounts"; echo
Loading