81 lines
3.3 KiB
PowerShell
81 lines
3.3 KiB
PowerShell
# Auto download and install cloudflared
|
|
|
|
Write-Host "=== Cloudflare Tunnel Installer ===" -ForegroundColor Cyan
|
|
Write-Host ""
|
|
|
|
# Check if already installed
|
|
$cloudflaredPath = Get-Command cloudflared -ErrorAction SilentlyContinue
|
|
if ($cloudflaredPath) {
|
|
Write-Host "cloudflared is already installed" -ForegroundColor Green
|
|
cloudflared --version
|
|
exit 0
|
|
}
|
|
|
|
Write-Host "[1/3] Downloading cloudflared MSI..." -ForegroundColor Yellow
|
|
|
|
# Download URL
|
|
$downloadUrl = "https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.msi"
|
|
$downloadPath = "$env:TEMP\cloudflared-windows-amd64.msi"
|
|
|
|
try {
|
|
# Download file
|
|
Write-Host "Downloading from GitHub..." -ForegroundColor Cyan
|
|
Invoke-WebRequest -Uri $downloadUrl -OutFile $downloadPath -UseBasicParsing
|
|
|
|
if (Test-Path $downloadPath) {
|
|
Write-Host "Download completed: $downloadPath" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
Write-Host "[2/3] Installing cloudflared..." -ForegroundColor Yellow
|
|
Write-Host "Starting installer..." -ForegroundColor Cyan
|
|
|
|
# Install using msiexec
|
|
$installArgs = "/i `"$downloadPath`" /quiet /norestart"
|
|
Start-Process -FilePath "msiexec.exe" -ArgumentList $installArgs -Wait -NoNewWindow
|
|
|
|
Write-Host "Installation completed" -ForegroundColor Green
|
|
Write-Host ""
|
|
|
|
# Clean up
|
|
Remove-Item $downloadPath -Force -ErrorAction SilentlyContinue
|
|
|
|
Write-Host "[3/3] Verifying installation..." -ForegroundColor Yellow
|
|
|
|
# Refresh PATH
|
|
$machinePath = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
|
|
$userPath = [System.Environment]::GetEnvironmentVariable("Path", "User")
|
|
$env:Path = "$machinePath;$userPath"
|
|
|
|
# Wait for PATH update
|
|
Start-Sleep -Seconds 3
|
|
|
|
# Check installation
|
|
$cloudflaredPath = Get-Command cloudflared -ErrorAction SilentlyContinue
|
|
if ($cloudflaredPath) {
|
|
Write-Host "cloudflared installed successfully!" -ForegroundColor Green
|
|
Write-Host ""
|
|
cloudflared --version
|
|
Write-Host ""
|
|
Write-Host "=== Next Step ===" -ForegroundColor Cyan
|
|
Write-Host "Run this command to start tunnel:" -ForegroundColor Yellow
|
|
Write-Host " cloudflared tunnel --url http://localhost:8000" -ForegroundColor White
|
|
} else {
|
|
Write-Host "Installation completed, but you may need to restart PowerShell" -ForegroundColor Yellow
|
|
Write-Host "Please close and reopen PowerShell, then run: cloudflared --version" -ForegroundColor Yellow
|
|
}
|
|
} else {
|
|
Write-Host "Download failed" -ForegroundColor Red
|
|
Write-Host "Please download manually:" -ForegroundColor Yellow
|
|
Write-Host " $downloadUrl" -ForegroundColor Cyan
|
|
exit 1
|
|
}
|
|
} catch {
|
|
Write-Host "Download or installation failed: $_" -ForegroundColor Red
|
|
Write-Host ""
|
|
Write-Host "Please install manually:" -ForegroundColor Yellow
|
|
Write-Host "1. Visit: https://github.com/cloudflare/cloudflared/releases/latest" -ForegroundColor Cyan
|
|
Write-Host "2. Download: cloudflared-windows-amd64.msi" -ForegroundColor Cyan
|
|
Write-Host "3. Double-click to install" -ForegroundColor Cyan
|
|
exit 1
|
|
}
|