-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
206 lines (163 loc) · 8.18 KB
/
bootstrap.ps1
File metadata and controls
206 lines (163 loc) · 8.18 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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#Requires -Version 5.1
# Stage 1 bootstrap for Windows. Idempotent.
[CmdletBinding()]
param()
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$RepoUrl = "https://github.com/robvenn/dotfiles.git"
if ($PSScriptRoot) {
$DotfilesDir = Split-Path -Parent $PSScriptRoot
} else {
$DotfilesDir = "$env:USERPROFILE\dotfiles"
}
# ── Helpers ───────────────────────────────────────────────────────────────────
function Write-Info { param([string]$Msg) Write-Host " [ .. ] $Msg" -ForegroundColor Blue }
function Write-Success { param([string]$Msg) Write-Host " [ OK ] $Msg" -ForegroundColor Green }
function Write-Warn { param([string]$Msg) Write-Host " [WARN] $Msg" -ForegroundColor Yellow }
function Set-PersistentEnv {
param([string]$Name, [string]$Value)
$current = [Environment]::GetEnvironmentVariable($Name, 'User')
if ($current -eq $Value) {
Write-Success "$Name already set"
return
}
[Environment]::SetEnvironmentVariable($Name, $Value, 'User')
Set-Item -Path "Env:\$Name" -Value $Value
Write-Success "$Name = $Value"
}
$warnings = @()
# ── Developer Mode ────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Developer Mode" -ForegroundColor Magenta
$devModeKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
try {
$val = Get-ItemPropertyValue -Path $devModeKey -Name AllowDevelopmentWithoutDevLicense -ErrorAction SilentlyContinue
if ($val -eq 1) {
Write-Success "Developer Mode already enabled"
} else {
Write-Info "Attempting to enable Developer Mode (requires admin)..."
Set-ItemProperty -Path $devModeKey -Name AllowDevelopmentWithoutDevLicense -Value 1 -ErrorAction Stop
Write-Success "Developer Mode enabled"
}
} catch {
$warnings += "Developer Mode not enabled (not admin). Dotter will use file copies instead of symlinks."
Write-Warn $warnings[-1]
}
# ── Scoop ─────────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Scoop" -ForegroundColor Magenta
if (Get-Command scoop -ErrorAction SilentlyContinue) {
Write-Success "Scoop already installed"
} else {
Write-Info "Installing Scoop..."
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression
Write-Success "Scoop installed"
}
# ── Git ───────────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Git" -ForegroundColor Magenta
if (Get-Command git -ErrorAction SilentlyContinue) {
Write-Success "Git already installed"
} else {
Write-Info "Installing git via scoop..."
scoop install git
if ($LASTEXITCODE -ne 0) { throw "scoop install git failed" }
Write-Success "Git installed"
}
# ── Scoop Buckets ─────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Scoop Buckets" -ForegroundColor Magenta
$installedBuckets = scoop bucket list | Select-Object -ExpandProperty Name
if ($installedBuckets -contains "main") {
Write-Success "main bucket already added"
} else {
Write-Info "Adding main bucket..."
scoop bucket add main
if ($LASTEXITCODE -ne 0) { throw "scoop bucket add main failed" }
Write-Success "main bucket added"
}
# ── Core Tools ────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Core Tools" -ForegroundColor Magenta
foreach ($tool in @("nu", "dotter")) {
if (Get-Command $tool -ErrorAction SilentlyContinue) {
Write-Success "$tool already installed"
} else {
Write-Info "Installing $tool..."
scoop install $tool
if ($LASTEXITCODE -ne 0) { throw "scoop install $tool failed" }
Write-Success "$tool installed"
}
}
# ── Environment Variables ─────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Environment Variables" -ForegroundColor Magenta
Set-PersistentEnv "XDG_CONFIG_HOME" "$env:USERPROFILE\.config"
Set-PersistentEnv "XDG_DATA_HOME" "$env:USERPROFILE\.local\share"
Set-PersistentEnv "XDG_STATE_HOME" "$env:USERPROFILE\.local\state"
Set-PersistentEnv "XDG_CACHE_HOME" "$env:USERPROFILE\.cache"
Set-PersistentEnv "EDITOR" "hx"
Set-PersistentEnv "VISUAL" "hx"
Set-PersistentEnv "BAT_CONFIG_PATH" "$env:USERPROFILE\.config\bat\config"
Set-PersistentEnv "RIPGREP_CONFIG_PATH" "$env:USERPROFILE\.config\ripgrep\config"
Set-PersistentEnv "FZF_DEFAULT_OPTS_FILE" "$env:USERPROFILE\.config\fzf\config"
Set-PersistentEnv "FZF_DEFAULT_COMMAND" "fd --type f --hidden --follow --exclude .git"
# ── Clone Dotfiles ────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Dotfiles Repo" -ForegroundColor Magenta
if (Test-Path "$DotfilesDir\.git") {
Write-Success "Dotfiles repo already exists at $DotfilesDir"
} else {
Write-Info "Cloning dotfiles repo..."
git clone $RepoUrl $DotfilesDir
if ($LASTEXITCODE -ne 0) { throw "git clone failed" }
Write-Success "Dotfiles repo cloned"
}
# ── Dotter local.toml ────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Dotter Configuration" -ForegroundColor Magenta
$localToml = "$DotfilesDir\.dotter\local.toml"
if (Test-Path $localToml) {
Write-Success "local.toml already exists"
} else {
Write-Info "Creating local.toml for Windows..."
@'
includes = [".dotter/windows.toml"]
packages = ["nushell", "git", "ssh", "editorconfig", "bat", "ripgrep", "fzf", "mise", "helix", "zed", "starship", "topgrade"]
'@ | Set-Content -Path $localToml -NoNewline
Write-Success "local.toml created"
}
# ── Dotter Deploy ─────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Dotter Deploy" -ForegroundColor Magenta
Write-Info "Deploying dotfiles..."
Push-Location $DotfilesDir
try {
dotter deploy
if ($LASTEXITCODE -ne 0) { throw "dotter deploy failed" }
Write-Success "Dotfiles deployed"
} finally {
Pop-Location
}
# ── Summary ───────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Summary" -ForegroundColor Magenta
if ($warnings.Count -eq 0) {
Write-Success "All steps completed successfully"
} else {
Write-Warn "$($warnings.Count) warning(s):"
foreach ($w in $warnings) {
Write-Warn " - $w"
}
}
# ── Stage 2 ───────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "==> Stage 2" -ForegroundColor Magenta
$provisionScript = "$DotfilesDir\scripts\provision.nu"
if (Test-Path $provisionScript) {
Write-Info "Invoking provision.nu..."
nu $provisionScript
} else {
Write-Warn "provision.nu not found -- skipping Stage 2"
}