#!/bin/sh # ProxVN client installer — Linux, macOS, Android (Termux) # curl -fsSL https://proxvn.io.vn/install.sh | sh set -eu BASE="${PROXVN_BASE:-https://proxvn.io.vn}" say() { printf ' %s\n' "$*"; } die() { printf ' Lỗi: %s\n' "$*" >&2; exit 1; } BASE=${BASE%/} case "$BASE" in https://?*) ;; *) die "nguồn tải phải dùng HTTPS" ;; esac SUDO="" if command -v sha256sum >/dev/null 2>&1; then hash_file() { sha256sum "$1" | awk '{print tolower($1)}'; } elif command -v shasum >/dev/null 2>&1; then hash_file() { shasum -a 256 "$1" | awk '{print tolower($1)}'; } else die "cần sha256sum hoặc shasum để kiểm tra file tải về" fi os=$(uname -s | tr '[:upper:]' '[:lower:]') arch=$(uname -m) case "$arch" in x86_64|amd64) arch=amd64 ;; aarch64|arm64) arch=arm64 ;; *) die "kiến trúc $arch chưa được hỗ trợ — xem hệ thống được hỗ trợ tại $BASE/docs/client#install" ;; esac case "$os" in linux) if [ -n "${PREFIX:-}" ] && echo "$PREFIX" | grep -q termux; then os=android; fi ;; darwin) ;; *) die "hệ điều hành $os chưa được hỗ trợ — trên Windows dùng: irm $BASE/install.ps1 | iex" ;; esac [ "$os" = android ] && [ "$arch" != arm64 ] && die "Android chỉ hỗ trợ ARM64" file="proxvn-$os-$arch" url="$BASE/bin/client/$file" tmp=$(mktemp -d 2>/dev/null || mktemp -d -t proxvn) trap 'rm -rf "$tmp"' EXIT trap 'exit 1' HUP INT TERM printf '\n ProxVN Tunnel — đang cài đặt cho %s/%s\n\n' "$os" "$arch" if command -v curl >/dev/null 2>&1; then download() { curl --proto '=https' --proto-redir '=https' --tlsv1.2 -fsSL --connect-timeout 15 --max-time 300 --retry 3 "$1" -o "$2"; } elif command -v wget >/dev/null 2>&1; then download() { wget --https-only --timeout=30 --tries=3 -q "$1" -O "$2"; } else die "cần curl hoặc wget" fi # A missing, malformed or duplicate entry must never turn verification off. download "$BASE/bin/SHA256SUMS-client.txt" "$tmp/sums" || die "không tải được checksum SHA-256" want=$(awk -v name="$file" ' $2 == name || $2 == "*" name { if (NF != 2 || length($1) != 64 || $1 ~ /[^0-9a-fA-F]/) exit 1 hash = tolower($1); count++ } END { if (count != 1) exit 1; print hash } ' "$tmp/sums") || die "checksum SHA-256 cho $file bị thiếu hoặc không hợp lệ" download "$url" "$tmp/proxvn" || die "không tải được $url" got=$(hash_file "$tmp/proxvn") [ "$want" = "$got" ] || die "checksum không khớp — file tải về có thể bị hỏng" say "Đã kiểm tra checksum SHA-256" chmod +x "$tmp/proxvn" # Keep personal installations writable so verified updates can activate at the # next normal launch without asking for administrator privileges. if [ "$os" = android ]; then dest="$PREFIX/bin" elif [ "$(id -u)" = 0 ]; then dest=/usr/local/bin else dest="$HOME/.local/bin"; fi mkdir -p "$dest" 2>/dev/null || ${SUDO:-} mkdir -p "$dest" if [ "$os" = darwin ]; then xattr -d com.apple.quarantine "$tmp/proxvn" 2>/dev/null || true; fi ${SUDO:-} mv "$tmp/proxvn" "$dest/proxvn" say "Đã cài: $dest/proxvn" say "Tự tải bản tương thích; áp dụng ở lần chạy tiếp theo. Tắt bằng PROXVN_AUTO_UPDATE=false." case ":$PATH:" in *":$dest:"*) ;; *) say "Thêm vào PATH: export PATH=\"$dest:\$PATH\"" ;; esac printf '\n Bắt đầu:\n proxvn # hướng dẫn từng bước\n proxvn http 3000 # web → https://xxx.proxvn.io.vn\n proxvn tcp 22 # SSH\n\n Tài liệu: %s/docs/\n\n' "$BASE"