-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathawakening.ps1
More file actions
333 lines (317 loc) · 14.4 KB
/
Copy pathawakening.ps1
File metadata and controls
333 lines (317 loc) · 14.4 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
<#
.SYNOPSIS
Awakening - first-run setup for Armory command dispatcher.
#>
param(
[string]$CommandWord,
[string]$InstallDir = "$env:USERPROFILE\bin",
[switch]$Help,
[switch]$Sound,
[switch]$NoSound
)
$ErrorActionPreference = "Stop"
$hooks = Join-Path $PSScriptRoot "bard\lib\bard-hooks.ps1"
if (Test-Path $hooks) { . $hooks }
$soundContext = $null
if (Get-Command Initialize-ArmorySound -ErrorAction SilentlyContinue) {
$soundContext = Initialize-ArmorySound -Sound:$Sound -NoSound:$NoSound -RepoRoot $PSScriptRoot
Invoke-ArmoryCue -Context $soundContext -Type start
}
function Show-Usage {
Write-Host ""
Write-Host " Awakening" -ForegroundColor Cyan
Write-Host " -----------------------------" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Set a command word for Armory tools."
Write-Host " Crystal Saga onboarding begins with receiving the crystal at level one."
Write-Host ""
Write-Host " Usage:"
Write-Host " .\\awakening.ps1"
Write-Host " .\\awakening.ps1 -CommandWord crystal"
Write-Host " .\\awakening.ps1 -CommandWord faye"
Write-Host " .\\awakening.ps1 -CommandWord forge -InstallDir C:\\Tools\\bin"
Write-Host ""
Write-Host " Examples for command word: crystal, armory, ops, forge, faye, kit"
Write-Host ""
}
if ($Help) {
Show-Usage
if ($soundContext) { Invoke-ArmoryCue -Context $soundContext -Type success }
exit 0
}
if (-not $CommandWord) {
Show-Usage
Write-Host " Receive the Crystal and begin the journey." -ForegroundColor Yellow
$defaultWord = "crystal"
$entered = Read-Host (" Command word [{0}]" -f $defaultWord)
if ($entered) {
$CommandWord = $entered
} else {
$CommandWord = $defaultWord
}
}
if (-not $CommandWord -or $CommandWord -notmatch "^[a-zA-Z][a-zA-Z0-9-]{1,20}$") {
Write-Host " Invalid command word. Use letters, numbers, and dash only." -ForegroundColor Red
if ($soundContext) { Invoke-ArmoryCue -Context $soundContext -Type fail }
exit 1
}
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null
}
$repoRoot = (Resolve-Path $PSScriptRoot).Path
$cmdPath = Join-Path $InstallDir ("{0}.cmd" -f $CommandWord)
$cmdLines = @(
"@echo off",
"setlocal",
"set `"ARMORY_ROOT=$repoRoot`"",
"set `"ACTION=%~1`"",
"set `"CIVS_ON=0`"",
"for /f %%I in ('powershell -NoProfile -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\civs.ps1`" status -EmitFlag') do set `"CIVS_ON=%%I`"",
"if `"%ACTION%`"==`"`" goto :help",
"shift",
"if /I `"%ACTION%`"==`"help`" goto :help",
"if /I `"%ACTION%`"==`"list`" goto :list",
"if /I `"%ACTION%`"==`"keys-list`" (set `"CIV_TARGET=list`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"shop`" goto :shop",
"if /I `"%ACTION%`"==`"catalog`" (set `"CIV_TARGET=shop`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"forge`" goto :forge",
"if /I `"%ACTION%`"==`"materia-forge`" goto :forge",
"if /I `"%ACTION%`"==`"scaffold`" (set `"CIV_TARGET=forge`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"rename`" goto :rename",
"if /I `"%ACTION%`"==`"rename-word`" goto :rename",
"if /I `"%ACTION%`"==`"rename-cmd`" (set `"CIV_TARGET=rename`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"civs`" goto :civs",
"if /I `"%ACTION%`"==`"remedy`" goto :remedy",
"if /I `"%ACTION%`"==`"health`" (set `"CIV_TARGET=remedy`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"doctor`" goto :doctor",
"if /I `"%ACTION%`"==`"esuna`" goto :remedy",
"if /I `"%ACTION%`"==`"reload`" goto :reload",
"if /I `"%ACTION%`"==`"restart`" (set `"CIV_TARGET=reload`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"swap`" goto :swap",
"if /I `"%ACTION%`"==`"masamune`" goto :swap",
"if /I `"%ACTION%`"==`"keys`" (set `"CIV_TARGET=swap`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"bahamut`" goto :bahamut",
"if /I `"%ACTION%`"==`"restore`" (set `"CIV_TARGET=bahamut`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"ifrit`" goto :ifrit",
"if /I `"%ACTION%`"==`"create-agent`" (set `"CIV_TARGET=ifrit`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"odin`" goto :odin",
"if /I `"%ACTION%`"==`"cleanup`" (set `"CIV_TARGET=odin`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"ramuh`" goto :ramuh",
"if /I `"%ACTION%`"==`"diagnose`" (set `"CIV_TARGET=ramuh`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"shiva`" goto :shiva",
"if /I `"%ACTION%`"==`"snapshot`" (set `"CIV_TARGET=shiva`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"phoenix-down`" goto :phoenixdown",
"if /I `"%ACTION%`"==`"backup`" (set `"CIV_TARGET=phoenixdown`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"save-point`" goto :savepoint",
"if /I `"%ACTION%`"==`"backup-bootstrap`" (set `"CIV_TARGET=savepoint`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"aegis`" goto :aegis",
"if /I `"%ACTION%`"==`"services`" (set `"CIV_TARGET=aegis`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"sentinel`" goto :sentinel",
"if /I `"%ACTION%`"==`"scan`" goto :scan",
"if /I `"%ACTION%`"==`"secret-scan`" (set `"CIV_TARGET=scan`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"truesight`" goto :truesight",
"if /I `"%ACTION%`"==`"deep-security-scan`" (set `"CIV_TARGET=truesight`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"deep-scan`" goto :deepscan",
"if /I `"%ACTION%`"==`"libra`" goto :libra",
"if /I `"%ACTION%`"==`"ops-report`" (set `"CIV_TARGET=libra`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"cure`" goto :cure",
"if /I `"%ACTION%`"==`"backup-check`" (set `"CIV_TARGET=cure`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"protect`" goto :protect",
"if /I `"%ACTION%`"==`"scheduled-scan`" (set `"CIV_TARGET=protect`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"regen`" goto :regen",
"if /I `"%ACTION%`"==`"morning-report`" (set `"CIV_TARGET=regen`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"chronicle`" goto :chronicle",
"if /I `"%ACTION%`"==`"quartermaster`" goto :quartermaster",
"if /I `"%ACTION%`"==`"status`" (set `"CIV_TARGET=chronicle`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"repo-status`" (set `"CIV_TARGET=chronicle`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"bard`" goto :bard",
"if /I `"%ACTION%`"==`"audio`" (set `"CIV_TARGET=bard`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"alexander`" goto :alexander",
"if /I `"%ACTION%`"==`"gate`" (set `"CIV_TARGET=alexander`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"preflight`" (set `"CIV_TARGET=alexander`" & goto :civsRoute)",
"if /I `"%ACTION%`"==`"init`" goto :init",
"if /I `"%ACTION%`"==`"awakening`" goto :init",
"if /I `"%ACTION%`"==`"setup`" goto :setup",
"echo Unknown command: %ACTION%",
"goto :help",
":civsRoute",
"if /I `"%CIVS_ON%`"==`"1`" goto :%CIV_TARGET%",
"goto :civsDisabled",
":civsDisabled",
"echo Civilian Mode aliases are OFF because Crystal Saga Mode is active. Run %~n0 civs on to switch.",
"exit /b 1",
":swap",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\masamune\\masamune.ps1`" %*",
"exit /b %errorlevel%",
":list",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\masamune\\masamune.ps1`" list",
"exit /b %errorlevel%",
":shop",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\shop\\list-shop.ps1`" %*",
"exit /b %errorlevel%",
":forge",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\materia-forge.ps1`" %*",
"exit /b %errorlevel%",
":rename",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\rename-command-word.ps1`" %*",
"exit /b %errorlevel%",
":civs",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\civs.ps1`" %*",
"exit /b %errorlevel%",
":remedy",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\items\\remedy\\remedy.ps1`" %*",
"exit /b %errorlevel%",
":doctor",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\doctor.ps1`" %*",
"exit /b %errorlevel%",
":reload",
"powershell -ExecutionPolicy Bypass -Command `"openclaw gateway restart 2>`$null; if (`$LASTEXITCODE -ne 0) { nssm restart OpenClawGateway 2>`$null }`"",
"exit /b 0",
":bahamut",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\summons\\bahamut\\bahamut.ps1`" %*",
"exit /b %errorlevel%",
":ifrit",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\summons\\ifrit\\ifrit.ps1`" %*",
"exit /b %errorlevel%",
":odin",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\summons\\odin\\odin.ps1`" %*",
"exit /b %errorlevel%",
":ramuh",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\summons\\ramuh\\ramuh.ps1`" %*",
"exit /b %errorlevel%",
":shiva",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\summons\\shiva\\shiva.ps1`" %*",
"exit /b %errorlevel%",
":phoenixdown",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\phoenix-down\\phoenix-down.ps1`" %*",
"exit /b %errorlevel%",
":savepoint",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\phoenix-down\\save-point.ps1`" %*",
"exit /b %errorlevel%",
":aegis",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\aegis\\aegis.ps1`" %*",
"exit /b %errorlevel%",
":sentinel",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\sentinel\\sentinel.ps1`" %*",
"exit /b %errorlevel%",
":scan",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\scan\\scan.ps1`" %*",
"exit /b %errorlevel%",
":truesight",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\truesight\\truesight.ps1`" %*",
"exit /b %errorlevel%",
":deepscan",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\weapons\\scan\\deep-scan.ps1`" %*",
"exit /b %errorlevel%",
":libra",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\spells\\libra\\libra.ps1`" %*",
"exit /b %errorlevel%",
":cure",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\spells\\cure\\cure.ps1`" %*",
"exit /b %errorlevel%",
":protect",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\spells\\protect\\protect.ps1`" %*",
"exit /b %errorlevel%",
":regen",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\spells\\regen\\regen.ps1`" %*",
"exit /b %errorlevel%",
":chronicle",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\spells\\chronicle\\chronicle.ps1`" %*",
"exit /b %errorlevel%",
":quartermaster",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\items\\quartermaster\\quartermaster.ps1`" %*",
"exit /b %errorlevel%",
":bard",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\bard\\bard.ps1`" %*",
"exit /b %errorlevel%",
":alexander",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\summons\\alexander\\alexander.ps1`" %*",
"exit /b %errorlevel%",
":init",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\awakening.ps1`" %*",
"exit /b %errorlevel%",
":setup",
"powershell -ExecutionPolicy Bypass -File `"%ARMORY_ROOT%\\setup.ps1`" %*",
"exit /b %errorlevel%",
":help",
"echo.",
"echo Armory dispatcher",
"echo.",
"echo Commands:",
"echo help, list, shop, forge, materia-forge, rename, rename-word, civs, remedy, doctor, esuna, reload, swap, masamune",
"echo bahamut, ifrit, odin, ramuh, shiva, alexander, gate",
"echo phoenix-down, save-point",
"echo aegis, sentinel, scan, truesight, deep-scan",
"echo libra, cure, protect, regen, chronicle, quartermaster, status",
"echo bard, init, awakening, setup",
"echo civs on^|off^|status",
"echo.",
"echo Civilian aliases (for the uninitiated):",
"echo keys-list, catalog, scaffold, rename-cmd, health, restart, keys",
"echo restore, create-agent, cleanup, diagnose, snapshot, preflight",
"echo backup, backup-bootstrap, services, secret-scan, deep-security-scan",
"echo ops-report, backup-check, scheduled-scan, morning-report, repo-status, audio",
"echo.",
"exit /b 0"
)
Set-Content -Path $cmdPath -Value ($cmdLines -join "`r`n") -Encoding ASCII
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (-not $userPath) {
$userPath = ""
}
if ($userPath -notlike "*${InstallDir}*") {
if ($userPath.Length -gt 0 -and -not $userPath.EndsWith(";")) {
$newPath = "$userPath;$InstallDir"
} else {
$newPath = "$userPath$InstallDir"
}
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
}
$armoryDir = Join-Path $env:USERPROFILE ".armory"
if (-not (Test-Path $armoryDir)) {
New-Item -ItemType Directory -Path $armoryDir -Force | Out-Null
}
$configPath = Join-Path $armoryDir "config.json"
$modeValue = "saga"
if (Test-Path $configPath) {
try {
$existingConfig = Get-Content -Path $configPath -Raw | ConvertFrom-Json
if ($existingConfig.PSObject.Properties.Name -contains "mode") {
$rawMode = [string]$existingConfig.mode
if ($rawMode -eq "civ") {
$modeValue = "civ"
} elseif ($rawMode -in @("saga", "lore", "crystal")) {
$modeValue = "saga"
}
} elseif ($existingConfig.PSObject.Properties.Name -contains "civilianAliases") {
if ([bool]$existingConfig.civilianAliases) {
$modeValue = "civ"
} else {
$modeValue = "saga"
}
}
} catch {
$modeValue = "saga"
}
}
$config = [ordered]@{
commandWord = $CommandWord
installDir = $InstallDir
repoRoot = $repoRoot
mode = $modeValue
civilianAliases = ($modeValue -eq "civ")
}
$config | ConvertTo-Json -Depth 5 | Set-Content -Path $configPath -Encoding UTF8
Write-Host ""
Write-Host " Awakening complete" -ForegroundColor Green
Write-Host " Command word: $CommandWord" -ForegroundColor White
Write-Host " Wrapper: $cmdPath" -ForegroundColor DarkGray
Write-Host " Config: $configPath" -ForegroundColor DarkGray
Write-Host ""
Write-Host " Try commands:" -ForegroundColor Yellow
Write-Host " $CommandWord help" -ForegroundColor White
Write-Host " $CommandWord swap list" -ForegroundColor White
Write-Host " $CommandWord aegis" -ForegroundColor White
Write-Host ""
if ($soundContext) { Invoke-ArmoryCue -Context $soundContext -Type success }
exit 0