-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
101 lines (87 loc) · 3.74 KB
/
install.ps1
File metadata and controls
101 lines (87 loc) · 3.74 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
#Requires -Version 5.1
<#
.SYNOPSIS
Developer environment bootstrapper.
Downloads and runs the setup script for your platform.
.DESCRIPTION
Quick-start:
irm https://raw.githubusercontent.com/darki73/developer/main/install.ps1 | iex
Or clone the repo and run directly:
git clone https://github.com/darki73/developer.git
.\developer\windows\setup.ps1
#>
$ErrorActionPreference = "Stop"
# Determine platform
if ($env:OS -eq "Windows_NT") {
$platform = "windows"
} else {
Write-Host "This bootstrapper currently supports Windows only." -ForegroundColor Red
Write-Host "Linux and macOS support coming soon." -ForegroundColor Yellow
Write-Host "See: https://github.com/darki73/developer" -ForegroundColor Gray
exit 1
}
# Check if we're already in the repo
$localSetup = Join-Path $PSScriptRoot "$platform\setup.ps1"
if (Test-Path $localSetup) {
Write-Host "Running local setup script..." -ForegroundColor Cyan
& $localSetup @args
exit $LASTEXITCODE
}
# Otherwise, clone to temp and run
$tempDir = Join-Path $env:TEMP "developer-setup-$(Get-Random)"
$cleanupDir = $tempDir
try {
Write-Host "Downloading developer setup..." -ForegroundColor Cyan
# Try git clone first
$gitAvailable = Get-Command git -ErrorAction SilentlyContinue
if ($gitAvailable) {
$cloneOutput = git clone --depth 1 https://github.com/darki73/developer.git $tempDir 2>&1
if ($LASTEXITCODE -ne 0) {
Write-Host "Git clone failed: $cloneOutput" -ForegroundColor Yellow
Write-Host "Falling back to zip download..." -ForegroundColor Yellow
$gitAvailable = $null
}
}
if (-not $gitAvailable) {
# Fallback: download zip
$zipUrl = "https://github.com/darki73/developer/archive/refs/heads/main.zip"
$zipPath = Join-Path $env:TEMP "developer-setup.zip"
Invoke-WebRequest -Uri $zipUrl -OutFile $zipPath -UseBasicParsing
# Sanity check — a real zip is well over 10 KB; smaller probably means
# an HTML error page from GitHub got saved with a .zip extension.
$zipSize = (Get-Item $zipPath).Length
if ($zipSize -lt 10KB) {
Remove-Item $zipPath -Force -ErrorAction SilentlyContinue
Write-Host "Downloaded zip is only $zipSize bytes — likely an error page, not the repo." -ForegroundColor Red
exit 1
}
Expand-Archive $zipPath -DestinationPath $tempDir -Force
Remove-Item $zipPath -Force
# The zip extracts to developer-main/
$innerDir = Get-ChildItem $tempDir -Directory | Select-Object -First 1
if ($innerDir) {
$tempDir = $innerDir.FullName
}
}
# Layout sanity check — confirms what we got actually looks like this repo
# before executing setup.ps1 from it.
$expectedPaths = @(
(Join-Path $tempDir "$platform\setup.ps1"),
(Join-Path $tempDir "$platform\lib"),
(Join-Path $tempDir "$platform\tools")
)
$missing = $expectedPaths | Where-Object { -not (Test-Path $_) }
if ($missing) {
Write-Host "Downloaded archive is missing expected paths:" -ForegroundColor Red
foreach ($m in $missing) { Write-Host " $m" -ForegroundColor Red }
Write-Host "Refusing to execute — the archive does not look like darki73/developer." -ForegroundColor Red
exit 1
}
$setupScript = Join-Path $tempDir "$platform\setup.ps1"
& $setupScript @args
} finally {
# Cleanup — always remove the original temp dir (not the reassigned inner path)
if (Test-Path $cleanupDir) {
Remove-Item $cleanupDir -Recurse -Force -ErrorAction SilentlyContinue
}
}