-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.ps1
More file actions
189 lines (164 loc) · 7.1 KB
/
setup.ps1
File metadata and controls
189 lines (164 loc) · 7.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# SPDX-FileCopyrightText: 2024 eTMA Handler Contributors
# SPDX-License-Identifier: MIT
#
# eTMA Handler - Windows Setup Script (PowerShell)
# ================================================
#
# Run with:
# irm https://raw.githubusercontent.com/Hyperpolymath/tma-mark2/main/setup.ps1 | iex
#
# Or download and run:
# Invoke-WebRequest -Uri https://raw.githubusercontent.com/Hyperpolymath/tma-mark2/main/setup.ps1 -OutFile setup.ps1
# .\setup.ps1
#
# This script:
# 1. Installs Podman Desktop (if needed)
# 2. Installs Just (if needed)
# 3. Pulls the eTMA Handler container
# 4. Shows you how to run it
#
#Requires -Version 5.1
$ErrorActionPreference = "Stop"
# Colors
function Write-Info { Write-Host "ℹ $args" -ForegroundColor Cyan }
function Write-Success { Write-Host "✓ $args" -ForegroundColor Green }
function Write-Warn { Write-Host "⚠ $args" -ForegroundColor Yellow }
function Write-Err { Write-Host "✗ $args" -ForegroundColor Red; exit 1 }
# Header
Write-Host ""
Write-Host "╔═══════════════════════════════════════════════════════════╗" -ForegroundColor Magenta
Write-Host "║ eTMA Handler - Setup Script ║" -ForegroundColor Magenta
Write-Host "║ Open University Marking Tool ║" -ForegroundColor Magenta
Write-Host "║ (Windows Edition) ║" -ForegroundColor Magenta
Write-Host "╚═══════════════════════════════════════════════════════════╝" -ForegroundColor Magenta
Write-Host ""
# Check if running as admin (warn but don't block)
$isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Warn "Not running as Administrator. Some installations may require elevation."
}
# Check for winget
function Test-Winget {
try {
$null = Get-Command winget -ErrorAction Stop
return $true
} catch {
return $false
}
}
# Install Podman
function Install-Podman {
$podmanPath = Get-Command podman -ErrorAction SilentlyContinue
if ($podmanPath) {
$version = & podman --version 2>$null
Write-Success "Podman already installed: $version"
return
}
Write-Info "Installing Podman..."
if (Test-Winget) {
Write-Info "Using winget to install Podman Desktop..."
winget install -e --id RedHat.Podman
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
} else {
Write-Warn "winget not found. Please install Podman manually:"
Write-Host " https://podman.io/getting-started/installation#windows" -ForegroundColor Yellow
Write-Host ""
Write-Host " Or install winget from Microsoft Store (App Installer)" -ForegroundColor Yellow
exit 1
}
# Initialize Podman machine
Write-Info "Initializing Podman machine..."
try {
& podman machine init 2>$null
& podman machine start 2>$null
} catch {
Write-Warn "Podman machine may need manual initialization"
}
Write-Success "Podman installed"
}
# Install Just
function Install-Just {
$justPath = Get-Command just -ErrorAction SilentlyContinue
if ($justPath) {
$version = & just --version 2>$null
Write-Success "Just already installed: $version"
return
}
Write-Info "Installing Just..."
if (Test-Winget) {
winget install -e --id Casey.Just
# Refresh PATH
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
} else {
# Alternative: use cargo or scoop
if (Get-Command cargo -ErrorAction SilentlyContinue) {
Write-Info "Using cargo to install just..."
cargo install just
} elseif (Get-Command scoop -ErrorAction SilentlyContinue) {
Write-Info "Using scoop to install just..."
scoop install just
} else {
Write-Warn "Please install just manually:"
Write-Host " winget install Casey.Just" -ForegroundColor Yellow
Write-Host " OR" -ForegroundColor Yellow
Write-Host " scoop install just" -ForegroundColor Yellow
exit 1
}
}
Write-Success "Just installed"
}
# Create data directory
function New-DataDirectory {
$dataDir = "$env:APPDATA\etma_handler"
if (-not (Test-Path $dataDir)) {
New-Item -ItemType Directory -Path $dataDir -Force | Out-Null
}
Write-Success "Data directory: $dataDir"
return $dataDir
}
# Pull container
function Get-Container {
Write-Info "Pulling eTMA Handler container..."
$image = "ghcr.io/hyperpolymath/etma-handler:latest"
try {
& podman pull $image
Write-Success "Container pulled successfully"
} catch {
Write-Warn "Could not pull container (might not be published yet)"
Write-Info "You can build it locally after cloning the repository"
}
}
# Main
function Main {
Install-Podman
Install-Just
$dataDir = New-DataDirectory
Get-Container
Write-Host ""
Write-Host "═══════════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host " Setup Complete! " -ForegroundColor Green
Write-Host "═══════════════════════════════════════════════════════════" -ForegroundColor Green
Write-Host ""
Write-Host " To run eTMA Handler:" -ForegroundColor White
Write-Host ""
Write-Host " Option 1 - Direct with Podman:" -ForegroundColor White
Write-Host " podman run -p 4000:4000 -v ${dataDir}:/data ghcr.io/hyperpolymath/etma-handler" -ForegroundColor Cyan
Write-Host ""
Write-Host " Option 2 - Clone and use Just:" -ForegroundColor White
Write-Host " git clone https://github.com/Hyperpolymath/tma-mark2.git" -ForegroundColor Cyan
Write-Host " cd tma-mark2" -ForegroundColor Cyan
Write-Host " just do-it" -ForegroundColor Cyan
Write-Host ""
Write-Host " Then open: http://localhost:4000" -ForegroundColor Yellow
Write-Host ""
# Ask if they want to run now
$run = Read-Host "Run eTMA Handler now? (y/N)"
if ($run -eq 'y' -or $run -eq 'Y') {
Write-Info "Starting eTMA Handler..."
Write-Host " Opening http://localhost:4000 in 5 seconds..." -ForegroundColor Yellow
Start-Process "http://localhost:4000" -ErrorAction SilentlyContinue
& podman run -p 4000:4000 -v "${dataDir}:/data" ghcr.io/hyperpolymath/etma-handler:latest
}
}
Main