-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.ps1
More file actions
106 lines (89 loc) · 3.73 KB
/
Copy pathsetup.ps1
File metadata and controls
106 lines (89 loc) · 3.73 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
# setup.ps1 - Entry point for dev-setup on Windows (PowerShell)
#
# This script detects the Windows environment and routes to the correct
# platform-specific installer. It does NOT install any tools itself.
#
# Usage:
# powershell -ExecutionPolicy Bypass -File setup.ps1
#
# Supported platforms:
# Windows (native PowerShell)
#
# For Linux/macOS/WSL, use setup.sh instead.
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
# -- Logging helpers -----------------------------------------------------------
function Write-Info { param([string]$Msg) Write-Output "[INFO] $Msg" }
function Write-Ok { param([string]$Msg) Write-Output "[OK] $Msg" }
function Write-Warn { param([string]$Msg) Write-Output "[WARN] $Msg" }
function Write-Err { param([string]$Msg) Write-Output "[ERROR] $Msg" }
# -- OS Detection -------------------------------------------------------------
function Get-Platform {
# $IsLinux, $IsMacOS, and $IsWindows are automatic variables introduced in PowerShell 6 (Core).
# On Windows PowerShell 5.x they do NOT exist, so referencing them directly under Set-StrictMode
# causes a hard "variable not set" error. To stay PS 5.1-compatible we use PSVersion-based guards.
# $PSVersionTable.PSVersion.Major has been available since PS 2.
# On PS 5.x Windows, $env:OS is always 'Windows_NT', giving us a reliable fallback.
$isWin = ($PSVersionTable.PSVersion.Major -ge 6 -and $IsWindows) -or `
($PSVersionTable.PSVersion.Major -lt 6 -and $env:OS -eq 'Windows_NT')
$isLin = $PSVersionTable.PSVersion.Major -ge 6 -and $IsLinux
$isMac = $PSVersionTable.PSVersion.Major -ge 6 -and $IsMacOS
if ($isLin -or $isMac) {
# Unlikely to be reached via PowerShell on Linux/macOS in most setups,
# but handle gracefully if pwsh is installed there.
return 'unix'
}
if ($isWin) {
# Detect WSL from within PowerShell (edge case: pwsh running inside WSL)
$procVersion = '/proc/version'
if (Test-Path $procVersion) {
$content = Get-Content $procVersion -Raw
if ($content -match 'microsoft') {
return 'wsl'
}
}
return 'windows'
}
return 'unknown'
}
# -- Routing -------------------------------------------------------------------
function Main {
# $PSScriptRoot is the reliable automatic variable for the script's directory (PS 3.0+).
# Fallback to $MyInvocation.MyCommand.Definition for dot-sourced or hosted execution contexts
# where $PSScriptRoot may be empty. Avoid .Path -- it is null in several common host environments.
$ScriptDir = if ($PSScriptRoot) { $PSScriptRoot } else { Split-Path -Parent $MyInvocation.MyCommand.Definition }
$platform = Get-Platform
Write-Info "dev-setup - entry point (PowerShell)"
Write-Info "Detected platform: $platform"
switch ($platform) {
'windows' {
Write-Ok "Platform: Windows"
Invoke-WindowsSetup -ScriptDir $ScriptDir
}
'wsl' {
Write-Warn "Detected WSL inside PowerShell. For best results, run setup.sh in your WSL terminal."
Invoke-WindowsSetup -ScriptDir $ScriptDir
}
'unix' {
Write-Warn "PowerShell detected on a Unix-like system. Consider using setup.sh instead."
Invoke-WindowsSetup -ScriptDir $ScriptDir
}
default {
Write-Err "Unrecognised platform. Cannot continue."
Write-Err "For Linux/macOS/WSL, use: bash setup.sh"
exit 1
}
}
}
function Invoke-WindowsSetup {
param([string]$ScriptDir)
$windowsScript = Join-Path $ScriptDir 'scripts\windows\setup.ps1'
if (-not (Test-Path $windowsScript)) {
Write-Err "Platform script not found: $windowsScript"
Write-Err "The repository may be incomplete. Please re-clone and try again."
exit 1
}
Write-Info "Handing off to: scripts\windows\setup.ps1"
& $windowsScript
}
Main