-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
102 lines (87 loc) · 4.82 KB
/
bootstrap.ps1
File metadata and controls
102 lines (87 loc) · 4.82 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
<#
.SYNOPSIS
Minimal Windows bootstrapper.
Installs Scoop + Git, clones the dotfiles repo, runs bootstrap.sh in
Git Bash for package installation, then creates symlinks directly in
PowerShell (which has the admin token).
.USAGE
irm https://raw.githubusercontent.com/yslib/dotfiles/master/bootstrap.ps1 | iex
#>
$ErrorActionPreference = "Stop"
$DotfilesRepo = "https://github.com/yslib/dotfiles.git"
# ── 0. Self-elevate if not admin ────────────────────────────────────
$isAdmin = ([Security.Principal.WindowsPrincipal] `
[Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
if (-not $isAdmin) {
Write-Host ">> Requesting administrator privileges (needed for symlinks)..." -ForegroundColor Yellow
$psExe = if ($PSVersionTable.PSVersion.Major -ge 7) { (Get-Process -Id $PID).Path } else { "powershell.exe" }
$cwd = (Get-Location).Path
Start-Process $psExe -Verb RunAs -ArgumentList @(
"-ExecutionPolicy", "Bypass",
"-Command", "Set-Location '$cwd'; irm https://raw.githubusercontent.com/yslib/dotfiles/master/bootstrap.ps1 | iex"
)
exit
}
# ── 1. Install Scoop ─────────────────────────────────────────────
if (-not (Get-Command scoop -ErrorAction SilentlyContinue)) {
Write-Host ">> Installing Scoop..." -ForegroundColor Cyan
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Invoke-RestMethod get.scoop.sh | Invoke-Expression
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + `
[System.Environment]::GetEnvironmentVariable("Path", "Machine")
} else {
Write-Host ">> Scoop already installed." -ForegroundColor Green
}
# ── 2. Install Git for Windows (provides bash) ───────────────────
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Host ">> Installing Git for Windows via Scoop..." -ForegroundColor Cyan
scoop install git
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "User") + ";" + `
[System.Environment]::GetEnvironmentVariable("Path", "Machine")
} else {
Write-Host ">> Git already installed." -ForegroundColor Green
}
# ── 3. Clone dotfiles repo (or detect we're already inside one) ──
if (Test-Path (Join-Path (Get-Location) "Scoopfile.json")) {
# Already inside the dotfiles repo (e.g. user ran .\bootstrap.ps1)
$DotfilesDir = (Get-Location).Path
Write-Host ">> Running from existing repo at $DotfilesDir" -ForegroundColor Green
} else {
$DotfilesDir = Join-Path (Get-Location) "dotfiles"
if (Test-Path (Join-Path $DotfilesDir ".git")) {
Write-Host ">> Dotfiles repo already exists at $DotfilesDir, pulling latest..." -ForegroundColor Green
git -C $DotfilesDir pull --rebase
} else {
Write-Host ">> Cloning dotfiles repo to $DotfilesDir..." -ForegroundColor Cyan
git clone $DotfilesRepo $DotfilesDir
}
}
# ── 4. Locate bash and run bootstrap.sh ──────────────────────────
$gitDir = Split-Path -Parent (Get-Command git).Source
$bashCandidates = @(
(Join-Path (Split-Path $gitDir) "bin\bash.exe"),
(Join-Path $gitDir "bash.exe"),
(Join-Path (Split-Path $gitDir) "usr\bin\bash.exe")
)
$bashExe = $bashCandidates | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $bashExe) { Write-Error "Could not find bash.exe from Git for Windows." }
Write-Host ">> Found bash at: $bashExe" -ForegroundColor Green
$unixPath = & $bashExe -c "cygpath '$DotfilesDir'" 2>$null
if (-not $unixPath) { $unixPath = $DotfilesDir -replace '\\','/' -replace '^([A-Za-z]):','/$1' }
Write-Host ">> Launching bootstrap.sh in Git Bash (install packages + nvim plugins)..." -ForegroundColor Cyan
& $bashExe --login -c "cd '$unixPath' && ./bootstrap.sh"
if ($LASTEXITCODE -ne 0) {
Write-Error "bootstrap.sh exited with code $LASTEXITCODE"
}
# ── 5. Create symlinks (PowerShell has admin token) ──────────────
$linkScript = Join-Path $DotfilesDir "scripts/link_config.ps1"
if (-not (Test-Path $linkScript)) {
Write-Error "link_config.ps1 not found: $linkScript"
}
& $linkScript -DotfilesDir $DotfilesDir
# ── Done ─────────────────────────────────────────────────────────
Write-Host "`n========================================" -ForegroundColor Green
Write-Host " Bootstrap complete!" -ForegroundColor Green
Write-Host " Please restart your terminal." -ForegroundColor Green
Write-Host "========================================" -ForegroundColor Green