summaryrefslogtreecommitdiffstats
path: root/scripts/installers/windows.ps1.in
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/installers/windows.ps1.in')
-rw-r--r--scripts/installers/windows.ps1.in75
1 files changed, 75 insertions, 0 deletions
diff --git a/scripts/installers/windows.ps1.in b/scripts/installers/windows.ps1.in
new file mode 100644
index 0000000..fd2b8b3
--- /dev/null
+++ b/scripts/installers/windows.ps1.in
@@ -0,0 +1,75 @@
1# Zagan-Bet desktop installer for Windows.
2#
3# Verifies the app against its published SHA-256, installs it for the current
4# user and adds a Start-menu shortcut. Put the downloaded app next to this
5# script, or run the script on its own and it will fetch the matching binary.
6#
7# Run it with:
8# powershell -ExecutionPolicy Bypass -File .\zagan-bet-gui-*-install.ps1
9$ErrorActionPreference = "Stop"
10
11$Version = "__VERSION__"
12$Binary = "__BINARY__"
13$Sha256 = "__SHA256__"
14$Url = "__URL__"
15
16function Stop-Install([string]$Message) {
17 Write-Host "install: $Message" -ForegroundColor Red
18 exit 1
19}
20
21$here = Split-Path -Parent $MyInvocation.MyCommand.Path
22$candidates = @(
23 (Join-Path $here $Binary),
24 (Join-Path (Get-Location) $Binary),
25 (Join-Path $env:USERPROFILE "Downloads\$Binary")
26)
27$sourceFile = $null
28foreach ($candidate in $candidates) {
29 if (Test-Path -LiteralPath $candidate) {
30 $sourceFile = $candidate
31 break
32 }
33}
34
35$temporary = $null
36if (-not $sourceFile) {
37 $temporary = Join-Path ([System.IO.Path]::GetTempPath()) $Binary
38 Write-Host "Downloading $Binary..."
39 try {
40 Invoke-WebRequest -Uri $Url -OutFile $temporary -UseBasicParsing
41 } catch {
42 Stop-Install "download failed: $_"
43 }
44 $sourceFile = $temporary
45}
46
47try {
48 $actual = (Get-FileHash -LiteralPath $sourceFile -Algorithm SHA256).Hash.ToLowerInvariant()
49 if ($actual -ne $Sha256.ToLowerInvariant()) {
50 Stop-Install "checksum mismatch: expected $Sha256, got $actual"
51 }
52
53 $installDir = Join-Path $env:LOCALAPPDATA "Programs\Zagan-Bet"
54 New-Item -ItemType Directory -Force -Path $installDir | Out-Null
55 $target = Join-Path $installDir "zagan-bet-gui.exe"
56 Copy-Item -LiteralPath $sourceFile -Destination $target -Force
57
58 $startMenu = Join-Path $env:APPDATA "Microsoft\Windows\Start Menu\Programs"
59 New-Item -ItemType Directory -Force -Path $startMenu | Out-Null
60 $shortcutPath = Join-Path $startMenu "Zagan-Bet.lnk"
61 $shell = New-Object -ComObject WScript.Shell
62 $shortcut = $shell.CreateShortcut($shortcutPath)
63 $shortcut.TargetPath = $target
64 $shortcut.WorkingDirectory = $installDir
65 $shortcut.IconLocation = "$target,0"
66 $shortcut.Description = "Slots, roulette, blackjack and crash"
67 $shortcut.Save()
68
69 Write-Host "Installed Zagan-Bet $Version to $target"
70 Write-Host "A Start-menu shortcut was created."
71} finally {
72 if ($temporary -and (Test-Path -LiteralPath $temporary)) {
73 Remove-Item -LiteralPath $temporary -Force
74 }
75}