|
| 1 | +# EZ Language Installer for Windows |
| 2 | +# |
| 3 | +# Copyright (c) 2025-Present Marshall A Burns |
| 4 | +# Licensed under the MIT License. See LICENSE for details. |
| 5 | +# |
| 6 | +# Run as Administrator for system-wide installation, |
| 7 | +# or as regular user for user-local installation. |
| 8 | + |
| 9 | +$ErrorActionPreference = "Stop" |
| 10 | + |
| 11 | +Write-Host "EZ Language Installer" -ForegroundColor Cyan |
| 12 | +Write-Host "====================" -ForegroundColor Cyan |
| 13 | +Write-Host "" |
| 14 | + |
| 15 | +# Check if running as Administrator |
| 16 | +$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) |
| 17 | + |
| 18 | +if ($isAdmin) { |
| 19 | + $InstallDir = "$env:ProgramFiles\ez" |
| 20 | + $PathScope = "Machine" |
| 21 | + Write-Host "Running as Administrator - installing system-wide" -ForegroundColor Green |
| 22 | +} else { |
| 23 | + $InstallDir = "$env:LOCALAPPDATA\ez" |
| 24 | + $PathScope = "User" |
| 25 | + Write-Host "Running as regular user - installing for current user only" -ForegroundColor Yellow |
| 26 | + Write-Host "(Run as Administrator for system-wide installation)" -ForegroundColor Gray |
| 27 | +} |
| 28 | + |
| 29 | +Write-Host "" |
| 30 | + |
| 31 | +# Check if Go is installed |
| 32 | +try { |
| 33 | + $goVersion = go version |
| 34 | + Write-Host "Found: $goVersion" -ForegroundColor Green |
| 35 | +} catch { |
| 36 | + Write-Host "Error: Go is not installed" -ForegroundColor Red |
| 37 | + Write-Host "Please install Go from https://golang.org/dl/" -ForegroundColor Yellow |
| 38 | + exit 1 |
| 39 | +} |
| 40 | + |
| 41 | +# Build the binary |
| 42 | +Write-Host "" |
| 43 | +Write-Host "Building EZ..." -ForegroundColor Cyan |
| 44 | +try { |
| 45 | + go build -o ez.exe ./cmd/ez |
| 46 | + if (-not (Test-Path "ez.exe")) { |
| 47 | + throw "Build failed - ez.exe not created" |
| 48 | + } |
| 49 | + Write-Host "Build successful" -ForegroundColor Green |
| 50 | +} catch { |
| 51 | + Write-Host "Error: Build failed" -ForegroundColor Red |
| 52 | + Write-Host $_.Exception.Message -ForegroundColor Red |
| 53 | + exit 1 |
| 54 | +} |
| 55 | + |
| 56 | +# Create install directory |
| 57 | +Write-Host "" |
| 58 | +Write-Host "Installing to $InstallDir..." -ForegroundColor Cyan |
| 59 | +try { |
| 60 | + if (-not (Test-Path $InstallDir)) { |
| 61 | + New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null |
| 62 | + Write-Host "Created directory: $InstallDir" -ForegroundColor Green |
| 63 | + } |
| 64 | + |
| 65 | + # Move binary to install directory |
| 66 | + Move-Item -Path "ez.exe" -Destination "$InstallDir\ez.exe" -Force |
| 67 | + Write-Host "Installed ez.exe to $InstallDir" -ForegroundColor Green |
| 68 | +} catch { |
| 69 | + Write-Host "Error: Failed to install" -ForegroundColor Red |
| 70 | + Write-Host $_.Exception.Message -ForegroundColor Red |
| 71 | + # Clean up local binary if it exists |
| 72 | + if (Test-Path "ez.exe") { Remove-Item "ez.exe" -Force } |
| 73 | + exit 1 |
| 74 | +} |
| 75 | + |
| 76 | +# Add to PATH if not already present |
| 77 | +$currentPath = [Environment]::GetEnvironmentVariable("Path", $PathScope) |
| 78 | +if ($currentPath -notlike "*$InstallDir*") { |
| 79 | + Write-Host "" |
| 80 | + Write-Host "Adding $InstallDir to PATH..." -ForegroundColor Cyan |
| 81 | + try { |
| 82 | + $newPath = "$currentPath;$InstallDir" |
| 83 | + [Environment]::SetEnvironmentVariable("Path", $newPath, $PathScope) |
| 84 | + Write-Host "Added to $PathScope PATH" -ForegroundColor Green |
| 85 | + Write-Host "Note: Restart your terminal for PATH changes to take effect" -ForegroundColor Yellow |
| 86 | + } catch { |
| 87 | + Write-Host "Warning: Could not add to PATH automatically" -ForegroundColor Yellow |
| 88 | + Write-Host "Please add '$InstallDir' to your PATH manually" -ForegroundColor Yellow |
| 89 | + } |
| 90 | +} else { |
| 91 | + Write-Host "$InstallDir is already in PATH" -ForegroundColor Green |
| 92 | +} |
| 93 | + |
| 94 | +Write-Host "" |
| 95 | +Write-Host "========================================" -ForegroundColor Cyan |
| 96 | +Write-Host "EZ installed successfully!" -ForegroundColor Green |
| 97 | +Write-Host "========================================" -ForegroundColor Cyan |
| 98 | +Write-Host "" |
| 99 | +Write-Host "Run 'ez <file>' to execute EZ programs" -ForegroundColor White |
| 100 | +Write-Host "" |
| 101 | +Write-Host "To uninstall, run:" -ForegroundColor Gray |
| 102 | +Write-Host " Remove-Item -Recurse -Force '$InstallDir'" -ForegroundColor Gray |
| 103 | +if ($PathScope -eq "Machine") { |
| 104 | + Write-Host " (Run as Administrator)" -ForegroundColor Gray |
| 105 | +} |
| 106 | +Write-Host "" |
0 commit comments