summaryrefslogtreecommitdiffstats
path: root/web/install.ps1
diff options
context:
space:
mode:
Diffstat (limited to 'web/install.ps1')
-rw-r--r--web/install.ps1108
1 files changed, 108 insertions, 0 deletions
diff --git a/web/install.ps1 b/web/install.ps1
new file mode 100644
index 0000000..92eef83
--- /dev/null
+++ b/web/install.ps1
@@ -0,0 +1,108 @@
1# Zagan-Bet installer for Windows.
2#
3# Asks the site which build is newest, verifies its SHA-256, installs it for
4# the current user and adds a Start-menu shortcut. Point it at a staging site
5# with -Site http://127.0.0.1:8899; add -NoPause for automation.
6#
7# Run it with:
8# powershell -ExecutionPolicy Bypass -File .\install.ps1
9param(
10 [string]$Site = "https://zagan.2137697.xyz",
11 [switch]$NoPause
12)
13
14$ErrorActionPreference = "Stop"
15
16function Finish([int]$Code) {
17 if (-not $NoPause) {
18 Read-Host "Press Enter to close" | Out-Null
19 }
20 exit $Code
21}
22
23function Stop-Install([string]$Message) {
24 Write-Host "install: $Message" -ForegroundColor Red
25 Finish 1
26}
27
28try {
29 $latest = (Invoke-WebRequest -Uri "$Site/latest.php" -UseBasicParsing).Content
30} catch {
31 Stop-Install "could not read $Site/latest.php: $_"
32}
33
34$line = ($latest -split "`r?`n") |
35 Where-Object { $_ -match '^gui windows x86_64 ' } |
36 Select-Object -First 1
37if (-not $line) {
38 Stop-Install "no Windows build is published yet"
39}
40
41$parts = $line.Trim() -split '\s+'
42if ($parts.Count -lt 6) {
43 Stop-Install "the latest-build file is malformed"
44}
45$Version = $parts[3]
46$Binary = $parts[4]
47$Sha256 = $parts[5]
48$Url = "$Site/bin/gui/$Binary"
49
50Write-Host "Newest Zagan-Bet is $Version."
51
52$here = Split-Path -Parent $MyInvocation.MyCommand.Path
53$candidates = @(
54 (Join-Path $here $Binary),
55 (Join-Path (Get-Location) $Binary),
56 (Join-Path $env:USERPROFILE "Downloads\$Binary")
57)
58$sourceFile = $null
59foreach ($candidate in $candidates) {
60 if (Test-Path -LiteralPath $candidate) {
61 $sourceFile = $candidate
62 break
63 }
64}
65
66$temporary = $null
67if (-not $sourceFile) {
68 $temporary = Join-Path ([System.IO.Path]::GetTempPath()) $Binary
69 Write-Host "Downloading $Binary..."
70 try {
71 Invoke-WebRequest -Uri $Url -OutFile $temporary -UseBasicParsing
72 } catch {
73 Stop-Install "download failed: $_"
74 }
75 $sourceFile = $temporary
76}
77
78try {
79 $actual = (Get-FileHash -LiteralPath $sourceFile -Algorithm SHA256).Hash.ToLowerInvariant()
80 if ($actual -ne $Sha256.ToLowerInvariant()) {
81 Stop-Install "checksum mismatch: expected $Sha256, got $actual"
82 }
83
84 $installDir = Join-Path $env:LOCALAPPDATA "Programs\Zagan-Bet"
85 New-Item -ItemType Directory -Force -Path $installDir | Out-Null
86 $target = Join-Path $installDir "zagan-bet-gui.exe"
87 Copy-Item -LiteralPath $sourceFile -Destination $target -Force
88
89 $startMenu = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs"
90 New-Item -ItemType Directory -Force -Path $startMenu | Out-Null
91 $shortcutPath = Join-Path $startMenu "Zagan-Bet.lnk"
92 $shell = New-Object -ComObject WScript.Shell
93 $shortcut = $shell.CreateShortcut($shortcutPath)
94 $shortcut.TargetPath = $target
95 $shortcut.WorkingDirectory = $installDir
96 $shortcut.IconLocation = "$target,0"
97 $shortcut.Description = "Slots, roulette, blackjack and crash"
98 $shortcut.Save()
99
100 Write-Host "Installed Zagan-Bet $Version to $target"
101 Write-Host "A Start-menu shortcut was created."
102} finally {
103 if ($temporary -and (Test-Path -LiteralPath $temporary)) {
104 Remove-Item -LiteralPath $temporary -Force
105 }
106}
107
108Finish 0