& { $ErrorActionPreference = 'Stop' $ProgressPreference = 'SilentlyContinue' $feed = 'https://console.himoose.com/desktop-updates' $publisher = 'Farmball LLC' $downloadsPage = 'https://himoose.com/downloads/' $installer = $null try { if ($PSVersionTable.PSEdition -eq 'Core' -and -not $IsWindows) { throw 'This command is for Windows. On a Mac, run this in Terminal: curl -fsSL https://himoose.com/install.sh | bash' } if (-not [Environment]::Is64BitOperatingSystem -or [Environment]::OSVersion.Version.Major -lt 10) { throw 'Hi, Moose needs Windows 10 or later, 64-bit.' } if (Get-Process -Name 'HiMoose' -ErrorAction SilentlyContinue) { throw 'Hi, Moose is open. Quit it from the tray icon, then run this command again.' } [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 Write-Host '' Write-Host 'Looking up the latest version of Hi, Moose...' try { $manifest = (New-Object System.Net.WebClient).DownloadString("$feed/latest.yml") } catch { throw "Could not reach the release list. Check your connection and try again, or download from $downloadsPage" } $version = [regex]::Match($manifest, '(?m)^version:\s*(\S+)').Groups[1].Value $entry = [regex]::Match($manifest, '(?m)^\s*-\s+url:\s*(.+?\.exe)\s*\r?\n\s*sha512:\s*(\S+)\s*\r?\n\s*size:\s*(\d+)') if (-not $version -or -not $entry.Success) { throw "Could not read the release list. Try again in a minute, or download from $downloadsPage" } $fileName = $entry.Groups[1].Value $expectedHash = $entry.Groups[2].Value $sizeMb = [math]::Round([int64]$entry.Groups[3].Value / 1MB) $installer = Join-Path ([IO.Path]::GetTempPath()) ('HiMoose-Setup-{0}-{1}.exe' -f $version, [guid]::NewGuid().ToString('N').Substring(0, 8)) $url = "$feed/" + [Uri]::EscapeDataString($fileName) Write-Host "Downloading Hi, Moose $version ($sizeMb MB)..." $curl = Get-Command 'curl.exe' -CommandType Application -ErrorAction SilentlyContinue | Select-Object -First 1 if ($curl) { & $curl.Source -fL --progress-bar -o $installer $url if ($LASTEXITCODE -ne 0) { throw 'The download did not finish. Check your connection and run the command again.' } } else { try { (New-Object System.Net.WebClient).DownloadFile($url, $installer) } catch { throw 'The download did not finish. Check your connection and run the command again.' } } Write-Host 'Checking the download matches the published file...' $sha = [Security.Cryptography.SHA512]::Create() $stream = [IO.File]::OpenRead($installer) try { $actualHash = [Convert]::ToBase64String($sha.ComputeHash($stream)) } finally { $stream.Dispose() $sha.Dispose() } if ($actualHash -ne $expectedHash) { throw "The download does not match the published file, so it was not run. Try again, or download from $downloadsPage" } Write-Host "Checking the installer is signed by $publisher..." $signature = Get-AuthenticodeSignature -FilePath $installer if ($signature.Status -ne 'Valid' -or -not $signature.SignerCertificate -or $signature.SignerCertificate.Subject -notlike "CN=$publisher,*") { throw "The installer is not signed by $publisher, so it was not run. Download from $downloadsPage instead." } Write-Host 'Installing...' $process = Start-Process -FilePath $installer -ArgumentList '/S', '--force-run' -PassThru -Wait if ($process.ExitCode -ne 0) { throw "The installer stopped with code $($process.ExitCode). Download from $downloadsPage to install it by hand." } Write-Host '' Write-Host "Hi, Moose $version is installed and opening now." -ForegroundColor Green Write-Host '' } catch { Write-Host '' Write-Host $_.Exception.Message -ForegroundColor Red Write-Host '' } finally { if ($installer -and (Test-Path -LiteralPath $installer)) { Remove-Item -LiteralPath $installer -Force -ErrorAction SilentlyContinue } } }