-
Notifications
You must be signed in to change notification settings - Fork 40
/
startup.ps1
88 lines (81 loc) · 3.07 KB
/
startup.ps1
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
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
$Dir = $Dir -replace "/var/tmp", "/root"
Set-Location $Dir
if($IsWindows){try { if ((Get-MpPreference).ExclusionPath -notcontains (Convert-Path .)) { Start-Process "powershell" -Verb runAs -ArgumentList "Add-MpPreference -ExclusionPath `'$Dir`'" -WindowStyle Minimized } }catch { }}
if (Test-Path ".\config\parameters\default.json") {
$Defaults = Get-Content ".\config\parameters\default.json" | ConvertFrom-Json
}
else {
Write-Host "Default.json is missing. Exiting" -ForegroundColor DarkRed
Start-Sleep -S 3
exit
}
$List = $Defaults.PSObject.Properties.Name
$parsed = @{ }
$start = $false
if ($args) {
if ( "-help" -in $args ) {
if ($IsWindows) {
$host.ui.RawUI.WindowTitle = "SWARM";
Start-Process "CMD" -ArgumentList "/C `"pwsh -noexit -executionpolicy Bypass -WindowStyle Maximized -command `"Set-Location C:\; Set-Location `'$Dir`'; .\build\powershell\scripts\help.ps1`"`"" -Verb RunAs
}
else {
Invoke-Expression ".\help.ps1"
}
}
else {
$Start = $true
$args | % {
$Command = $false
$ListCheck = $_ -replace "-", ""
if ($_[0] -eq "-") { $Command = $true; $Com = $_ -replace "-", "" }
if ($Command -eq $true) {
if ($ListCheck -in $List) {
$parsed.Add($Com, "new")
}
else {
Write-Host "Parameter `"$($ListCheck)`" Not Found. Exiting" -ForegroundColor Red
Start-Sleep -S 3
exit
}
}
else {
if ($parsed.$Com -eq "new") { $parsed.$Com = $_ }
else {
$NewArray = @()
$Parsed.$Com | % { $NewArray += $_ }
$NewArray += $_
$Parsed.$Com = $NewArray
}
}
}
}
}
elseif (test-path ".\config.json") {
$Start = $true
$parsed = @{ }
$arguments = Get-Content ".\config.json" | ConvertFrom-Json
$arguments.PSObject.Properties.Name | % { $Parsed.Add("$($_)", $arguments.$_) }
}
elseif (Test-Path ".\config\parameters\arguments.json") {
$Start = $true
$parsed = @{ }
$arguments = Get-Content ".\config\parameters\arguments.json" | ConvertFrom-Json
$arguments.PSObject.Properties.Name | % { $Parsed.Add("$($_)", $arguments.$_) }
}
else {
Write-Host "No Arguments or arguments.json file found. Exiting."
Start-Sleep -S 3
exit
}
$Defaults.PSObject.Properties.Name | % { if ($_ -notin $Parsed.keys) { $Parsed.Add("$($_)", $Defaults.$_) } }
$Parsed | convertto-json | Out-File ".\config\parameters\arguments.json"
if ($Start -eq $true) {
if ($IsWindows) {
$host.ui.RawUI.WindowTitle = "SWARM";
Start-Process "CMD" -ArgumentList "/C `"pwsh -noexit -executionpolicy Bypass -WindowStyle Maximized -command `"Set-Location C:\; Set-Location `'$Dir`'; .\swarm.ps1`"`"" -Verb RunAs
}
else {
Invoke-Expression ".\swarm.ps1"
}
}