# OpenPort installer for Windows $ErrorActionPreference = "Stop" try { [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12 -bor [System.Net.SecurityProtocolType]::Tls11 -bor [System.Net.SecurityProtocolType]::Tls } catch {} $ServerHost = "openport.pw" $ServerUrl = "http://$ServerHost" $InstallDir = "$env:USERPROFILE\.openport\bin" if (-not (Test-Path $InstallDir)) { New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null } if (Test-Path "$InstallDir\openport.ps1") { Remove-Item -Force "$InstallDir\openport.ps1" -ErrorAction SilentlyContinue } # Stop any running rathole instances to avoid file locking Stop-Process -Name "rathole" -Force -ErrorAction SilentlyContinue $wc = New-Object System.Net.WebClient Write-Host "Downloading openport..." $wc.DownloadFile("$ServerUrl/openport-cli.ps1", "$InstallDir\openport-cli.ps1") $wc.DownloadFile("$ServerUrl/openport.cmd", "$InstallDir\openport.cmd") $wc.DownloadFile("$ServerUrl/openport.bat", "$InstallDir\openport.bat") Write-Host "Downloading rathole core..." $wc.DownloadFile("$ServerUrl/client/rathole.exe", "$InstallDir\rathole.exe") try { Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force -ErrorAction SilentlyContinue } catch {} $UserPath = [Environment]::GetEnvironmentVariable("Path", [EnvironmentVariableTarget]::User) if ($UserPath -notlike "*$InstallDir*") { $NewPath = "$UserPath;$InstallDir" [Environment]::SetEnvironmentVariable("Path", $NewPath, [EnvironmentVariableTarget]::User) $env:Path = "$env:Path;$InstallDir" } Write-Host "" Write-Host "OpenPort installed successfully." Write-Host "Run 'openport 8080' in any terminal to get started."