learning_ai_common_plat/scripts/switch-network.sh
saravanakumardb1 2c588c51a3 refactor(scripts): simplify switch-network to env-var based approach
Single env var NETWORK=corp|home controls all proxy config.
Source from ~/.zshrc — sets http_proxy, NPM_CONFIG_REGISTRY,
PIP_TRUSTED_HOST, NODE_TLS_REJECT_UNAUTHORIZED automatically.
No more ~/.npmrc rewriting.
2026-02-12 20:38:57 -08:00

53 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# ─────────────────────────────────────────────────────────────
# Dual-network development setup
# ─────────────────────────────────────────────────────────────
#
# Controls: one env var — NETWORK=corp or NETWORK=home
#
# Usage (add to ~/.zshrc):
# export NETWORK=corp # at work
# export NETWORK=home # at home (or just unset it)
#
# Then source this file from ~/.zshrc:
# source "$HOME/code/mygh/learning_ai_common_plat/scripts/switch-network.sh"
#
# What it sets:
# NETWORK=corp → http_proxy, https_proxy, npm/pnpm registry, pip trusted-host
# NETWORK=home → all proxy vars unset, default registries
# ─────────────────────────────────────────────────────────────
_CORP_PROXY="http://cso.proxy.att.com:8080/"
_CORP_NPM_REGISTRY="https://jfrog-pkg-proxy.it.att.com/artifactory/api/npm/att-npm-proxy-group/"
if [ "${NETWORK:-home}" = "corp" ]; then
# ── Corporate proxy ──
export http_proxy="$_CORP_PROXY"
export https_proxy="$_CORP_PROXY"
export HTTP_PROXY="$_CORP_PROXY"
export HTTPS_PROXY="$_CORP_PROXY"
export NPM_CONFIG_REGISTRY="$_CORP_NPM_REGISTRY"
export NPM_CONFIG_PROXY="$_CORP_PROXY"
export NPM_CONFIG_HTTPS_PROXY="$_CORP_PROXY"
export NPM_CONFIG_STRICT_SSL="false"
export PIP_TRUSTED_HOST="pypi.org files.pythonhosted.org"
export NODE_TLS_REJECT_UNAUTHORIZED="0"
else
# ── Home / direct internet ──
unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY 2>/dev/null
unset NPM_CONFIG_REGISTRY NPM_CONFIG_PROXY NPM_CONFIG_HTTPS_PROXY 2>/dev/null
unset NPM_CONFIG_STRICT_SSL NODE_TLS_REJECT_UNAUTHORIZED 2>/dev/null
unset PIP_TRUSTED_HOST 2>/dev/null
fi
# Quick status on new shell (only if interactive)
if [[ $- == *i* ]]; then
if [ "${NETWORK:-home}" = "corp" ]; then
echo "🏢 NETWORK=corp — proxy active"
else
echo "🏠 NETWORK=home — direct internet"
fi
fi
unset _CORP_PROXY _CORP_NPM_REGISTRY