-
Notifications
You must be signed in to change notification settings - Fork 40
/
startup.ps1
executable file
·136 lines (128 loc) · 5.22 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
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
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
$Dir = $Dir -replace "/var/tmp", "/root"
Set-Location $Dir
if ($IsLinux) {$Global:EUID = (Invoke-Expression "bash -c set" | ConvertFrom-StringData).EUID}
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
$noconfig = $false
## Arguments take highest priority
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_linux"
}
}
else {
$Start = $true
$args | % {
if ($_ -is [string]) {
$_ = $_.replace("cnight", "cryptonight")
}
$Command = $false
$ListCheck = $_ -replace "-", ""
if ($_[0] -eq "-") { $Command = $true; $Com = $_ -replace "-", "" }
if ($Command -eq $true) {
if ($ListCheck -in $List) {
if ($ListCheck -notin $parsed.keys) {
$parsed.Add($Com, "new")
}
else {
Write-Host "Found $Listcheck twice in arguments" -ForegroundColor Red
Write-Host "Contiuning startup, but this may cause major issues." -ForegroundColor red
Start-Sleep -S 3
}
}
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
}
}
}
}
}
## Check if h-run.sh ran config.json
elseif (test-path ".\config.json") {
$parsed = @{ }
$arguments = Get-Content ".\config.json" | ConvertFrom-Json
if ([string]$arguments -ne "") {
$Start = $true
$arguments.PSObject.Properties.Name | % { $Parsed.Add("$($_)", $arguments.$_) }
}
## run help if no newarguments
elseif (-not (test-path ".\config\parameters\newarguments.json")) {
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_linux"
}
Start-Sleep -S 3
exit
}
elseif (".\config\parameters\newarguments.json") {
$Start = $true
$parsed = @{ }
$arguments = Get-Content ".\config\parameters\newarguments.json" | ConvertFrom-Json
$arguments.PSObject.Properties.Name | % { $Parsed.Add("$($_)", $arguments.$_) }
}
}
## Check for hiveos saved/help saved config
elseif (Test-Path ".\config\parameters\newarguments.json") {
$Start = $true
$parsed = @{ }
$arguments = Get-Content ".\config\parameters\newarguments.json" | ConvertFrom-Json
$arguments.PSObject.Properties.Name | % { $Parsed.Add("$($_)", $arguments.$_) }
}
## Run help if all fails
else {
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_linux"
}
Start-Sleep -S 3
exit
}
if ($Start -eq $true) {
$Defaults.PSObject.Properties.Name | % { if ($_ -notin $Parsed.keys) { $Parsed.Add("$($_)", $Defaults.$_) } }
$Parsed | convertto-json | Out-File ".\config\parameters\arguments.json"
if ($IsWindows) {
$host.ui.RawUI.WindowTitle = "SWARM";
Start-Process "pwsh" -ArgumentList "-noexit -executionpolicy Bypass -WindowStyle Maximized -command `"Set-Location C:\; Set-Location `'$Dir`'; .\swarm.ps1`"" -Verb RunAs
}
else {
## Add Arguments to newarguments.json
if (test-path "/hive-config") {
Write-Host "Saving Arguments To .\config\parameters\newarguments.json" -ForegroundColor Yellow
$Parsed | ConvertTo-Json | Out-File ".\config\parameters\newarguments.json"
}
Invoke-Expression ".\swarm.ps1"
}
}