|
| 1 | +# GhostWin One-Line Installer for Windows |
| 2 | +# Usage: iwr -useb https://raw.githubusercontent.com/yourusername/ghostwin/main/install.ps1 | iex |
| 3 | + |
| 4 | +param( |
| 5 | + [switch]$SkipRust, |
| 6 | + [string]$InstallPath = "$env:USERPROFILE\GhostWin", |
| 7 | + [switch]$Help |
| 8 | +) |
| 9 | + |
| 10 | +if ($Help) { |
| 11 | + Write-Host @" |
| 12 | +GhostWin Installer |
| 13 | +
|
| 14 | +Usage: |
| 15 | + iwr -useb https://your-repo/install.ps1 | iex # Full install |
| 16 | + iwr -useb https://your-repo/install.ps1 | iex -SkipRust # Skip Rust install |
| 17 | + iwr -useb https://your-repo/install.ps1 | iex -InstallPath "C:\Tools\GhostWin" |
| 18 | +
|
| 19 | +Options: |
| 20 | + -SkipRust Skip Rust installation (if already installed) |
| 21 | + -InstallPath Custom installation directory |
| 22 | + -Help Show this help |
| 23 | +"@ |
| 24 | + exit 0 |
| 25 | +} |
| 26 | + |
| 27 | +$ErrorActionPreference = "Stop" |
| 28 | + |
| 29 | +Write-Host "🚀 GhostWin Installation Script" -ForegroundColor Cyan |
| 30 | +Write-Host "================================" -ForegroundColor Cyan |
| 31 | + |
| 32 | +# Check if running as administrator |
| 33 | +if (-NOT ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) { |
| 34 | + Write-Host "⚠️ This script requires Administrator privileges for optimal setup." -ForegroundColor Yellow |
| 35 | + Write-Host " Some features may not work without admin rights." -ForegroundColor Yellow |
| 36 | + Write-Host "" |
| 37 | +} |
| 38 | + |
| 39 | +# Function to check if command exists |
| 40 | +function Test-Command($cmdname) { |
| 41 | + return [bool](Get-Command -Name $cmdname -ErrorAction SilentlyContinue) |
| 42 | +} |
| 43 | + |
| 44 | +# Install Rust if not present |
| 45 | +if (-not $SkipRust) { |
| 46 | + Write-Host "🔧 Checking for Rust installation..." -ForegroundColor Yellow |
| 47 | + |
| 48 | + if (Test-Command "cargo") { |
| 49 | + Write-Host "✅ Rust is already installed!" -ForegroundColor Green |
| 50 | + cargo --version |
| 51 | + } else { |
| 52 | + Write-Host "📦 Installing Rust..." -ForegroundColor Yellow |
| 53 | + |
| 54 | + # Download and run rustup-init |
| 55 | + $rustupUrl = "https://win.rustup.rs/x86_64" |
| 56 | + $rustupPath = "$env:TEMP\rustup-init.exe" |
| 57 | + |
| 58 | + Write-Host " Downloading rustup-init.exe..." -ForegroundColor Gray |
| 59 | + Invoke-WebRequest -Uri $rustupUrl -OutFile $rustupPath |
| 60 | + |
| 61 | + Write-Host " Running Rust installer (this may take a few minutes)..." -ForegroundColor Gray |
| 62 | + & $rustupPath -y --default-toolchain stable --default-host x86_64-pc-windows-msvc |
| 63 | + |
| 64 | + # Refresh environment |
| 65 | + $env:PATH = [System.Environment]::GetEnvironmentVariable("PATH", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("PATH", "User") |
| 66 | + |
| 67 | + if (Test-Command "cargo") { |
| 68 | + Write-Host "✅ Rust installed successfully!" -ForegroundColor Green |
| 69 | + } else { |
| 70 | + Write-Host "❌ Rust installation failed. Please install manually from https://rustup.rs/" -ForegroundColor Red |
| 71 | + exit 1 |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +# Create installation directory |
| 77 | +Write-Host "📁 Creating installation directory: $InstallPath" -ForegroundColor Yellow |
| 78 | +New-Item -ItemType Directory -Path $InstallPath -Force | Out-Null |
| 79 | + |
| 80 | +# Clone or download GhostWin |
| 81 | +Write-Host "⬇️ Downloading GhostWin..." -ForegroundColor Yellow |
| 82 | + |
| 83 | +# Check if git is available |
| 84 | +if (Test-Command "git") { |
| 85 | + Write-Host " Using git to clone repository..." -ForegroundColor Gray |
| 86 | + git clone https://github.com/yourusername/ghostwin.git $InstallPath |
| 87 | +} else { |
| 88 | + Write-Host " Git not found, downloading ZIP..." -ForegroundColor Gray |
| 89 | + $zipUrl = "https://github.com/yourusername/ghostwin/archive/main.zip" |
| 90 | + $zipPath = "$env:TEMP\ghostwin.zip" |
| 91 | + |
| 92 | + Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath |
| 93 | + Expand-Archive -Path $zipPath -DestinationPath $env:TEMP -Force |
| 94 | + Move-Item "$env:TEMP\ghostwin-main\*" $InstallPath -Force |
| 95 | + Remove-Item "$env:TEMP\ghostwin-main" -Recurse -Force |
| 96 | +} |
| 97 | + |
| 98 | +# Build GhostWin |
| 99 | +Write-Host "🔨 Building GhostWin..." -ForegroundColor Yellow |
| 100 | +Push-Location $InstallPath |
| 101 | + |
| 102 | +try { |
| 103 | + Write-Host " Running cargo build --release (this may take several minutes)..." -ForegroundColor Gray |
| 104 | + cargo build --release |
| 105 | + |
| 106 | + if (Test-Path "target\release\ghostwin.exe") { |
| 107 | + Write-Host "✅ GhostWin built successfully!" -ForegroundColor Green |
| 108 | + } else { |
| 109 | + Write-Host "❌ Build failed!" -ForegroundColor Red |
| 110 | + exit 1 |
| 111 | + } |
| 112 | +} finally { |
| 113 | + Pop-Location |
| 114 | +} |
| 115 | + |
| 116 | +# Add to PATH (optional) |
| 117 | +$addToPath = Read-Host "Add GhostWin to PATH? (y/N)" |
| 118 | +if ($addToPath -eq "y" -or $addToPath -eq "Y") { |
| 119 | + $currentPath = [Environment]::GetEnvironmentVariable("PATH", "User") |
| 120 | + $newPath = $currentPath + ";" + "$InstallPath\target\release" |
| 121 | + [Environment]::SetEnvironmentVariable("PATH", $newPath, "User") |
| 122 | + Write-Host "✅ Added to PATH. Restart your terminal to use 'ghostwin' command." -ForegroundColor Green |
| 123 | +} |
| 124 | + |
| 125 | +# Validate installation |
| 126 | +Write-Host "🔍 Validating installation..." -ForegroundColor Yellow |
| 127 | +& "$InstallPath\target\release\ghostwin.exe" validate |
| 128 | + |
| 129 | +Write-Host "" |
| 130 | +Write-Host "🎉 GhostWin Installation Complete!" -ForegroundColor Green |
| 131 | +Write-Host "=================================" -ForegroundColor Green |
| 132 | +Write-Host "" |
| 133 | +Write-Host "Location: $InstallPath" -ForegroundColor Cyan |
| 134 | +Write-Host "Executable: $InstallPath\target\release\ghostwin.exe" -ForegroundColor Cyan |
| 135 | +Write-Host "" |
| 136 | +Write-Host "Quick Start:" -ForegroundColor Yellow |
| 137 | +Write-Host " cd `"$InstallPath`"" -ForegroundColor Gray |
| 138 | +Write-Host " .\target\release\ghostwin.exe gui" -ForegroundColor Gray |
| 139 | +Write-Host "" |
| 140 | +Write-Host "For help: .\target\release\ghostwin.exe --help" -ForegroundColor Gray |
| 141 | +Write-Host "" |
| 142 | +Write-Host "Ready to deploy! 🚀" -ForegroundColor Green |
0 commit comments