-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
112 lines (105 loc) · 3.17 KB
/
Copy pathbootstrap.ps1
File metadata and controls
112 lines (105 loc) · 3.17 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
# Bootstrap Script Wrapper - Delegates to the appropriate bootstrap
# On Windows: invokes bootstrap/bootstrap.ps1 (native PowerShell)
# On Unix (via Git Bash): invokes bootstrap.sh (bash script)
$ErrorActionPreference = 'Stop'
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
# On Windows, use the native PowerShell bootstrap
$windowsBootstrap = Join-Path $ScriptDir "bootstrap\bootstrap.ps1"
if (Test-Path $windowsBootstrap) {
# Build splattable parameters hashtable
$params = @{}
$i = 0
while ($i -lt $args.Length) {
$arg = $args[$i]
switch ($arg) {
{ $_ -in "-y", "-Y", "--yes" } {
$params["Y"] = $true
$i++
}
{ $_ -in "-DryRun", "--dry-run" } {
$params["DryRun"] = $true
$i++
}
{ $_ -in "-Categories", "--categories", "-Category" } {
if ($i + 1 -lt $args.Length) {
$params["Categories"] = $args[$i + 1]
$i += 2
} else {
$i++
}
}
{ $_ -in "-SkipUpdate", "--skip-update" } {
$params["SkipUpdate"] = $true
$i++
}
{ $_ -in "-h", "-?", "--help" } {
# Show help using PowerShell's built-in mechanism
Get-Help -Full $windowsBootstrap
exit 0
}
default {
# Pass through unknown arguments
$i++
}
}
}
& $windowsBootstrap @params
exit $LASTEXITCODE
}
# Fall back to bash script (for Git Bash on Windows or Unix systems)
# Ensure Git Bash is available
if (-not (Get-Command bash -ErrorAction SilentlyContinue)) {
Write-Error "Git Bash (bash.exe) not found. Please install Git for Windows."
Write-Error "Download: https://git-scm.com/download/win"
exit 1
}
# Map PowerShell parameter names to bash equivalents
$mappedArgs = @()
$i = 0
while ($i -lt $args.Length) {
$arg = $args[$i]
switch ($arg) {
{ $_ -in "-y", "-Y", "--yes" } {
$mappedArgs += "--yes"
$i++
}
{ $_ -in "-DryRun", "--dry-run" } {
$mappedArgs += "--dry-run"
$i++
}
{ $_ -in "-Categories", "--categories", "-Category" } {
if ($i + 1 -lt $args.Length) {
$mappedArgs += "--categories"
$mappedArgs += $args[$i + 1]
$i += 2
} else {
$i++
}
}
{ $_ -in "-SkipUpdate", "--skip-update" } {
$mappedArgs += "--skip-update"
$i++
}
{ $_ -in "-h", "--help" } {
$mappedArgs += "--help"
$i++
}
default {
$mappedArgs += $arg
$i++
}
}
}
# Change to script directory and invoke bash as login shell
$origLocation = Get-Location
try {
Set-Location $ScriptDir
$argList = $mappedArgs -join ' '
$bashArgs = @("-l", "-c", "./bootstrap.sh $argList")
& bash @bashArgs
$exitCode = $LASTEXITCODE
}
finally {
Set-Location $origLocation
}
exit $exitCode