Files
vpn-proxy/install.ps1

106 lines
3.7 KiB
PowerShell

# ==========================================
# 🚀 VPN PROXY INSTALLER
# ==========================================
# This script automatically downloads and installs VPN Proxy
# Usage:
# iwr https://git.dokops.ru/dokril/vpn-proxy/raw/branch/master/install.ps1 | iex
# Enable UTF-8 for emoji support
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$ErrorActionPreference = "Stop"
# --- 1. Check Admin Rights ---
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]"Administrator")) {
Write-Warning "⚠️ Administrator rights required!"
Write-Host "🔄 Restarting script as Administrator..." -ForegroundColor Cyan
# Save script to temp file if running from memory (iex)
if ($MyInvocation.MyCommand.CommandType -eq 'Script') {
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$($MyInvocation.MyCommand.Path)`"" -Verb RunAs
}
else {
# If running via IEX, we cannot simple restart the file.
# We ask user to run terminal as admin.
Write-Error "Please run PowerShell as Administrator and try again."
}
exit
}
# --- 2. Settings ---
$InstallRoot = "C:\Tools"
$InstallDir = "$InstallRoot\vpn-proxy"
# Exact link provided by user
$ZipUrl = "https://git.dokops.ru/dokril/vpn-proxy/archive/master.zip"
$TempZip = "$env:TEMP\vpn-proxy-install.zip"
Write-Host "🚀 Starting VPN Proxy installation..." -ForegroundColor Green
Write-Host "📂 Install path: $InstallDir" -ForegroundColor Gray
# Move to temp folder to avoid blocking deletion if we are already in C:\Tools\vpn-proxy
Set-Location $env:TEMP
# --- 3. Prepare Directory ---
if (-not (Test-Path $InstallRoot)) {
New-Item -ItemType Directory -Path $InstallRoot -Force | Out-Null
}
# --- 4. Downloading ---
Write-Host "⬇️ Downloading update archive..." -ForegroundColor Cyan
try {
Invoke-WebRequest -Uri $ZipUrl -OutFile $TempZip
}
catch {
Write-Error "❌ Failed to download from $ZipUrl`nCheck your internet connection."
exit 1
}
# --- 5. Extracting ---
Write-Host "📦 Extracting..." -ForegroundColor Cyan
# If folder exists, delete old one
if (Test-Path $InstallDir) {
try {
Remove-Item $InstallDir -Recurse -Force -ErrorAction Stop
}
catch {
Write-Warning "⚠️ Failed to delete old folder $InstallDir"
Write-Warning " Error: $($_.Exception.Message)"
Write-Warning " Make sure files are not open in other programs and you are not inside this folder."
$retry = Read-Host " Press Enter to try again (or Ctrl+C to cancel)"
try {
Remove-Item $InstallDir -Recurse -Force -ErrorAction Stop
}
catch {
Write-Error "❌ Still failed to delete folder. Installation aborted."
exit 1
}
}
}
Expand-Archive -Path $TempZip -DestinationPath $InstallRoot -Force
# Archives usually extract to vpn-proxy-master or vpn-proxy-main
# We need to rename it to vpn-proxy
$ExtractedFolder = Get-ChildItem -Path $InstallRoot -Directory | Where-Object { $_.Name -match "vpn-proxy-(master|main)" } | Select-Object -First 1
if ($ExtractedFolder) {
Rename-Item -Path $ExtractedFolder.FullName -NewName "vpn-proxy" -Force
}
# Remove temp archive
Remove-Item $TempZip -Force
if (-not (Test-Path "$InstallDir\manage.ps1")) {
Write-Error "❌ Installation error: manage.ps1 not found in $InstallDir"
exit 1
}
# --- 6. Launching ---
Write-Host "✅ Installation complete!" -ForegroundColor Green
Write-Host "🚀 Launching control menu..." -ForegroundColor Cyan
Start-Sleep -Seconds 1
Set-Location $InstallDir
.\manage.ps1