forked from prysmaticlabs/prysm
-
Notifications
You must be signed in to change notification settings - Fork 1
/
prysm.ps1
127 lines (106 loc) · 4.79 KB
/
prysm.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
$folderDist = "dist";
$ProgressPreference = 'SilentlyContinue' # Disable Invoke-WebRequest progress bar, makes it silent and faster.
# Complain if invalid arguments were provided.
if ("beacon-chain", "validator", "client-stats" -notcontains $args[0]) {
Write-Host @"
Usage: ./prysm.sh1 PROCESS FLAGS.
PROCESS can be beacon-chain, validator, or client-stats.
FLAGS are the flags or arguments passed to the PROCESS.
Use this script to download the latest Prysm release binaries.
Downloaded binaries are saved to .\dist
To specify a specific release version:
`$env:USE_PRYSM_VERSION="v1.0.0-beta.3"
to resume using the latest release:
Remove-Item env:USE_PRYSM_VERSION
To automatically restart crashed processes:
`$env:PRYSM_AUTORESTART=`$TRUE ; .\prysm.sh1 beacon-chain
to stop autorestart run:
Remove-Item env:PRYSM_AUTORESTART
"@;
exit;
}
# 64bit check.
if (-not [Environment]::Is64BitOperatingSystem) {
Write-Host "ERROR: prysm is only supported on 64-bit Operating Systems" -ForegroundColor Red;
exit;
}
# Create directory for us to download our binaries to, if it not yet exists.
if (-not (Test-Path $folderDist)) {
New-Item -Path . -Name $folderDist -ItemType "directory";
}
# Determine the latest release version, unless specified by $USE_PRYSM_VERSION.
if (Test-Path env:USE_PRYSM_VERSION) {
Write-Host "Detected variable `$env:USE_PRYSM_VERSION=$env:USE_PRYSM_VERSION";
$version = $env:USE_PRYSM_VERSION;
}
else {
try {
$response = Invoke-WebRequest -Uri "https://prysmaticlabs.com/releases/latest";
$version = $response.Content.Trim();
Write-Host "Using (latest) prysm version: $version";
}
catch {
Write-Host "ERROR: Failed to get the latest version:" -ForegroundColor Red;
Write-Host " $($_.Exception.Message)" -ForegroundColor Red;
exit;
}
}
# Make sure the binary we want to use is up to date, otherwise download (and possibly verify) it.
$fileName = "$($args[0])-$version-windows-amd64.exe";
$folderBin = "$folderDist\$fileName";
if ((Test-Path $folderBin) -and (Test-Path "$folderBin.sha256") -and (Test-Path "$folderBin.sig")) {
Write-Host "$($args[0]) is up to date with version: $version" -ForegroundColor Green;
}
else {
try {
Write-Host "Downloading $fileName" -ForegroundColor Green;
Invoke-WebRequest -Uri "https://prysmaticlabs.com/releases/$fileName" -OutFile "$folderBin";
Invoke-WebRequest -Uri "https://prysmaticlabs.com/releases/$fileName.sha256" -OutFile "$folderBin.sha256";
Invoke-WebRequest -Uri "https://prysmaticlabs.com/releases/$fileName.sig" -OutFile "$folderBin.sig";
Write-Host "Downloading complete!" -ForegroundColor Green;
}
catch {
Write-Host "ERROR: Failed to get download $fileName`:" -ForegroundColor Red;
Write-Host " $($_.Exception.Message)" -ForegroundColor Red;
exit;
}
}
# GPG not natively available on Windows, external module required.
Write-Host "WARN GPG verification is not natively available on Windows" -ForegroundColor Yellow;
Write-Host "WARN Skipping integrity verification of downloaded binary" -ForegroundColor Yellow;
# Check SHA256 File Hash before running
Write-Host "Verifying binary authenticity with SHA256 Hash";
$hashExpected = (Get-Content -Path "$folderBin.sha256" -Delimiter " ")[0].Trim().ToUpperInvariant();
$hashActual = (Get-FileHash -Path $folderBin -Algorithm SHA256).Hash.ToUpperInvariant();
if ($hashExpected -eq $hashActual) {
Write-Host "SHA256 Hash Match!" -ForegroundColor Green;
}
elseif ((Test-Path env:PRYSM_ALLOW_UNVERIFIED_BINARIES) -and $env:PRYSM_ALLOW_UNVERIFIED_BINARIES -eq $TRUE) {
Write-Host "WARN Failed to verify prysm binary" -ForegroundColor Yellow;
Write-Host "Detected `$env:PRYSM_ALLOW_UNVERIFIED_BINARIES=`$TRUE";
Write-Host "Proceeding...";
}
else {
Write-Host "ERROR Failed to verify prysm binary" -ForegroundColor Red;
Write-Host @"
Please erase downloads in the
dist directory and run this script again. Alternatively, you can use a
a prior version by specifying environment variable `$env:USE_PRYSM_VERSION
with the specific version, as desired. Example: `$env:USE_PRYSM_VERSION=v1.0.0-alpha.5
If you must wish to continue running an unverified binary, use:
`$env:PRYSM_ALLOW_UNVERIFIED_BINARIES=`$TRUE
"@;
exit;
}
# Finally, start the process.
do {
Write-Host "Starting: prysm $($args -join ' ')";
$argumentList = $args | Select-Object -Skip 1;
if ($argumentList.Length -gt 0) {
$process = Start-Process -FilePath $folderBin -ArgumentList $argumentList -NoNewWindow -PassThru -Wait;
}
else {
$process = Start-Process -FilePath $folderBin -NoNewWindow -PassThru -Wait;
}
$restart = (Test-Path env:PRYSM_AUTORESTART) -and $env:PRYSM_AUTORESTART -eq $TRUE -and $process.ExitCode -ne 0;
} while ($restart)