#!/usr/bin/env bash set -euo pipefail DEFAULT_REF="${FREEVPN_REF:-main}" BASE_URL="${FREEVPN_BASE_URL:-https://raw.githubusercontent.com/fvp1717/freevpn/${DEFAULT_REF}}" BASE_URL="${BASE_URL%/}" need_cmd() { if ! command -v "$1" >/dev/null 2>&1; then echo "Missing required command: $1" >&2 exit 1 fi } download_file() { local rel_path="$1" local dest_path="$2" local url="${BASE_URL}/${rel_path}" mkdir -p "$(dirname "$dest_path")" if command -v curl >/dev/null 2>&1; then curl -fsSL "$url" -o "$dest_path" elif command -v wget >/dev/null 2>&1; then wget -qO "$dest_path" "$url" else echo "Missing required command: curl or wget" >&2 exit 1 fi } need_cmd bash need_cmd ssh need_cmd scp tmp_dir="$(mktemp -d 2>/dev/null || mktemp -d -t freevpn)" cleanup() { rm -rf "$tmp_dir" } trap cleanup EXIT echo "Downloading deployment scripts..." for rel_path in \ deploy.sh \ s-ui-install.sh \ scripts/remote_configure.sh \ scripts/configure_s_ui.py \ scripts/verify_remote.sh \ scripts/preflight_remote.sh do download_file "$rel_path" "$tmp_dir/$rel_path" done if [[ ! -f "$tmp_dir/deploy.sh" ]]; then echo "Downloaded scripts do not contain deploy.sh" >&2 exit 1 fi if [[ -e /dev/tty ]] && { true /dev/null; then bash "$tmp_dir/deploy.sh" "$@"