Files
vpndock/deploy.sh

63 lines
2.4 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
# deploy.sh Build and scale the vpndock stack
#
# Usage:
# ./deploy.sh → deploy 3 VPN exit nodes (default)
# ./deploy.sh 5 → deploy 5 VPN exit nodes
# ./deploy.sh 10 → deploy 10 VPN exit nodes (PureVPN's max simultaneous connections)
# ./deploy.sh 0 → tear down the stack
#
set -euo pipefail
SCALE=${1:-3}
MAX_CONNECTIONS=10
COMPOSE="docker compose"
# ── Sanity checks ─────────────────────────────────────────────────────────────
if [[ ! -f .env ]]; then
echo "ERROR: .env file not found. Copy .env.example and fill in your credentials:"
echo " cp .env.example .env && nano .env"
exit 1
fi
if [[ "$SCALE" -gt "$MAX_CONNECTIONS" ]]; then
echo "WARNING: PureVPN allows max $MAX_CONNECTIONS simultaneous connections."
echo " Capping scale at $MAX_CONNECTIONS."
SCALE=$MAX_CONNECTIONS
fi
# ── Tear down ─────────────────────────────────────────────────────────────────
if [[ "$SCALE" -eq 0 ]]; then
echo "Tearing down vpndock stack …"
$COMPOSE down
exit 0
fi
# ── Build & deploy ────────────────────────────────────────────────────────────
echo "──────────────────────────────────────────────"
echo " vpndock deploy"
echo " VPN exit nodes : $SCALE"
echo " SOCKS5 port : ${SOCKS5_PORT:-1080} (on host)"
echo " Stats UI : http://localhost:8404/stats"
echo "──────────────────────────────────────────────"
echo ""
echo "Building images …"
$COMPOSE build
echo ""
echo "Starting stack with $SCALE VPN exit node(s) …"
$COMPOSE up -d --scale vpn-node="$SCALE"
echo ""
echo "Stack is up. Waiting for containers to stabilise …"
sleep 5
$COMPOSE ps
echo ""
echo "Done! Configure your browser's SOCKS5 proxy:"
echo " Host : $(hostname -I | awk '{print $1}')"
echo " Port : ${SOCKS5_PORT:-1080}"
echo ""
echo "HAProxy stats: http://localhost:8404/stats (admin / admin)"