diff --git a/scripts/switch-network.sh b/scripts/switch-network.sh index e5a08e7b..4cad71b6 100755 --- a/scripts/switch-network.sh +++ b/scripts/switch-network.sh @@ -91,12 +91,35 @@ fi unset _CORP_PROXY _CORP_NPM_REGISTRY -# ── Gitea NPM token (always, regardless of NETWORK) ────────────── -# Local Gitea registry at localhost:3300 — token for publish access. -# Reads: public without auth. Writes: need GITEA_NPM_TOKEN. -# Store token in ~/.gitea_npm_token (one line, no newline). -# Create: curl -s -u admin:PASSWORD http://localhost:3300/api/v1/users/admin/tokens \ -# -H 'Content-Type: application/json' -d '{"name":"npm"}' | jq -r '.sha1 // .token' +# ── Gitea NPM registry (NETWORK-aware) ──────────────────────────── +# Repos use .npmrc with: @bytelyst:registry=http://${GITEA_NPM_HOST}:3300/... +# +# NETWORK=corp → Gitea runs locally on this machine (localhost) +# NETWORK=home → Gitea runs on the Azure VM (read host from ~/.gitea_vm_host) +# +# To configure the VM host (one-time): +# echo "bytelyst-vm.eastus.cloudapp.azure.com" > ~/.gitea_vm_host +# +# Token for publish access (reads are public, writes need auth): +# Store in ~/.gitea_npm_token (one line, no newline) +# Create: curl -s -u admin:PASSWORD http://:3300/api/v1/users/admin/tokens \ +# -H 'Content-Type: application/json' -d '{"name":"npm"}' | jq -r '.sha1 // .token' + +_GITEA_VM_HOST_FILE="$HOME/.gitea_vm_host" +if [ "${NETWORK:-home}" = "corp" ]; then + export GITEA_NPM_HOST="localhost" +else + if [ -f "$_GITEA_VM_HOST_FILE" ]; then + export GITEA_NPM_HOST + GITEA_NPM_HOST="$(cat "$_GITEA_VM_HOST_FILE")" + else + # Fallback: assume Gitea on localhost (e.g., local Docker or SSH tunnel) + export GITEA_NPM_HOST="localhost" + fi +fi +unset _GITEA_VM_HOST_FILE + +# Token: load from file if not already set _GITEA_TOKEN_FILE="$HOME/.gitea_npm_token" if [ -z "${GITEA_NPM_TOKEN:-}" ] && [ -f "$_GITEA_TOKEN_FILE" ]; then export GITEA_NPM_TOKEN