$ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $Base = if ($env:FEARMINER_DOWNLOAD) { $env:FEARMINER_DOWNLOAD } else { 'https://download.fearminer.com/latest' } $GitHub = 'https://github.com/fearminer/fearminer/releases/latest/download' $Asset = 'fearminer-windows-x86_64.zip' function Say($m) { Write-Host "fearminer: $m" } function Die($m) { Write-Host "fearminer: $m" -ForegroundColor Red; throw "fearminer: $m" } function Add-ToPath($Dir) { try { $Key = [Microsoft.Win32.Registry]::CurrentUser.CreateSubKey('Environment') try { $Old = [string]$Key.GetValue('Path', '', [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) $Entries = $Old -split ';' | Where-Object { $_ } | ForEach-Object { [Environment]::ExpandEnvironmentVariables($_).TrimEnd('\') } if ($Entries -notcontains $Dir) { $Kind = if ($Old) { $Key.GetValueKind('Path') } else { [Microsoft.Win32.RegistryValueKind]::ExpandString } $Key.SetValue('Path', ((@($Old.TrimEnd(';'), $Dir) | Where-Object { $_ }) -join ';'), $Kind) [Environment]::SetEnvironmentVariable('FEARMINER_PATH_CHANGED', '1', 'User') [Environment]::SetEnvironmentVariable('FEARMINER_PATH_CHANGED', $null, 'User') Say "$Dir is on PATH" } } finally { $Key.Close() } } catch { Say "$Dir could not be put on PATH ($($_.Exception.Message)): fearminer goes by its full path in new terminals" } if (($env:Path -split ';' | ForEach-Object { $_.TrimEnd('\') }) -notcontains $Dir) { $env:Path = "$env:Path;$Dir" } } if ($env:PROCESSOR_ARCHITECTURE -ne 'AMD64') { Die "no release for $($env:PROCESSOR_ARCHITECTURE) Windows yet (x86_64 only)" } if ($env:FEARMINER_WALLET -and -not $env:FEARMINER_POOL) { Die "FEARMINER_WALLET needs FEARMINER_POOL: `$env:FEARMINER_POOL='stratum+ssl://POOL:PORT' (the pool is yours to choose)" } if ($env:FEARMINER_POOL -and -not $env:FEARMINER_WALLET) { Die "FEARMINER_POOL goes with FEARMINER_WALLET: `$env:FEARMINER_WALLET='ADDRESS'" } $Tmp = Join-Path ([IO.Path]::GetTempPath()) ("fearminer-" + [guid]::NewGuid()) New-Item -ItemType Directory -Path $Tmp | Out-Null try { Say 'downloading the latest release for Windows x86_64' $Sums = (Invoke-WebRequest -UseBasicParsing "$Base/SHA256SUMS").Content $Hub = (Invoke-WebRequest -UseBasicParsing "$GitHub/SHA256SUMS").Content if ($Sums -is [byte[]]) { $Sums = [Text.Encoding]::ASCII.GetString($Sums) } if ($Hub -is [byte[]]) { $Hub = [Text.Encoding]::ASCII.GetString($Hub) } $Line = ($Sums -split "`n" | Where-Object { $_ -match " $([regex]::Escape($Asset))\s*$" } | Select-Object -First 1) $HubLine = ($Hub -split "`n" | Where-Object { $_ -match " $([regex]::Escape($Asset))\s*$" } | Select-Object -First 1) if (-not $Line -or $Line.Trim() -ne "$HubLine".Trim()) { Die "download.fearminer.com and GitHub disagree on ${Asset}: nothing installed" } $Expected = ($Line.Trim() -split '\s+')[0].ToUpper() $Zip = Join-Path $Tmp $Asset Invoke-WebRequest -UseBasicParsing "$Base/$Asset" -OutFile $Zip if ((Get-FileHash $Zip -Algorithm SHA256).Hash -ne $Expected) { Die "$Asset does not match its SHA-256: nothing installed" } Say 'verified (download.fearminer.com and GitHub agree, SHA-256 matches)' Expand-Archive $Zip -DestinationPath $Tmp $Exe = Get-ChildItem $Tmp -Recurse -Filter 'fearminer.exe' | Select-Object -First 1 if (-not $Exe) { Die 'the archive has no fearminer.exe' } Unblock-File $Exe.FullName Add-ToPath (Join-Path $env:LOCALAPPDATA 'Programs\FearMiner') $CliArgs = @('service', 'install') if ($env:FEARMINER_ENROLL) { $CliArgs += @('--enroll', $env:FEARMINER_ENROLL) } if ($env:FEARMINER_WALLET) { $CliArgs += @('-o', $env:FEARMINER_POOL, '-u', $env:FEARMINER_WALLET) if ($env:FEARMINER_WORKER) { $CliArgs += @('-w', $env:FEARMINER_WORKER) } } & $Exe.FullName @CliArgs if ($LASTEXITCODE -ne 0) { Die "fearminer service install failed ($LASTEXITCODE)" } } finally { Remove-Item -Recurse -Force $Tmp -ErrorAction SilentlyContinue }