diff options
Diffstat (limited to '')
| -rw-r--r-- | web/install.ps1 (renamed from scripts/installers/windows.ps1.in) | 45 | ||||
| -rw-r--r-- | web/install.sh (renamed from scripts/installers/linux.sh.in) | 50 |
2 files changed, 68 insertions, 27 deletions
diff --git a/scripts/installers/windows.ps1.in b/web/install.ps1 index 4b8e61d..92eef83 100644 --- a/scripts/installers/windows.ps1.in +++ b/web/install.ps1 | |||
| @@ -1,21 +1,18 @@ | |||
| 1 | # Zagan-Bet desktop installer for Windows. | 1 | # Zagan-Bet installer for Windows. |
| 2 | # | 2 | # |
| 3 | # Verifies the app against its published SHA-256, installs it for the current | 3 | # Asks the site which build is newest, verifies its SHA-256, installs it for |
| 4 | # user and adds a Start-menu shortcut. Put the downloaded app next to this | 4 | # the current user and adds a Start-menu shortcut. Point it at a staging site |
| 5 | # script, or run the script on its own and it will fetch the matching binary. | 5 | # with -Site http://127.0.0.1:8899; add -NoPause for automation. |
| 6 | # | 6 | # |
| 7 | # Run it with: | 7 | # Run it with: |
| 8 | # powershell -ExecutionPolicy Bypass -File .\zagan-bet-gui-*-install.ps1 | 8 | # powershell -ExecutionPolicy Bypass -File .\install.ps1 |
| 9 | # Add -NoPause to run it unattended. | 9 | param( |
| 10 | param([switch]$NoPause) | 10 | [string]$Site = "https://zagan.2137697.xyz", |
| 11 | [switch]$NoPause | ||
| 12 | ) | ||
| 11 | 13 | ||
| 12 | $ErrorActionPreference = "Stop" | 14 | $ErrorActionPreference = "Stop" |
| 13 | 15 | ||
| 14 | $Version = "__VERSION__" | ||
| 15 | $Binary = "__BINARY__" | ||
| 16 | $Sha256 = "__SHA256__" | ||
| 17 | $Url = "__URL__" | ||
| 18 | |||
| 19 | function Finish([int]$Code) { | 16 | function Finish([int]$Code) { |
| 20 | if (-not $NoPause) { | 17 | if (-not $NoPause) { |
| 21 | Read-Host "Press Enter to close" | Out-Null | 18 | Read-Host "Press Enter to close" | Out-Null |
| @@ -28,6 +25,30 @@ function Stop-Install([string]$Message) { | |||
| 28 | Finish 1 | 25 | Finish 1 |
| 29 | } | 26 | } |
| 30 | 27 | ||
| 28 | try { | ||
| 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 | ||
| 37 | if (-not $line) { | ||
| 38 | Stop-Install "no Windows build is published yet" | ||
| 39 | } | ||
| 40 | |||
| 41 | $parts = $line.Trim() -split '\s+' | ||
| 42 | if ($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 | |||
| 50 | Write-Host "Newest Zagan-Bet is $Version." | ||
| 51 | |||
| 31 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path | 52 | $here = Split-Path -Parent $MyInvocation.MyCommand.Path |
| 32 | $candidates = @( | 53 | $candidates = @( |
| 33 | (Join-Path $here $Binary), | 54 | (Join-Path $here $Binary), |
diff --git a/scripts/installers/linux.sh.in b/web/install.sh index 5b53c02..998b262 100644 --- a/scripts/installers/linux.sh.in +++ b/web/install.sh | |||
| @@ -1,24 +1,38 @@ | |||
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | # Zagan-Bet desktop installer for Linux. | 2 | # Zagan-Bet installer for Linux. |
| 3 | # | 3 | # |
| 4 | # Verifies the app against its published SHA-256, installs it for the current | 4 | # Asks the site which build is newest, verifies its SHA-256, installs it for |
| 5 | # user and adds a launcher. Put the downloaded app next to this script, or run | 5 | # the current user and adds a launcher. Point it at a staging site with |
| 6 | # the script on its own and it will fetch the matching binary. | 6 | # ZAGAN_SITE=http://127.0.0.1:8899. |
| 7 | set -euo pipefail | 7 | set -euo pipefail |
| 8 | 8 | ||
| 9 | VERSION="__VERSION__" | 9 | SITE=${ZAGAN_SITE:-https://zagan.2137697.xyz} |
| 10 | BINARY="__BINARY__" | 10 | PLATFORM=linux |
| 11 | SHA256="__SHA256__" | 11 | ARCH=x86_64 |
| 12 | URL="__URL__" | ||
| 13 | 12 | ||
| 14 | say() { printf '%s\n' "$*"; } | 13 | say() { printf '%s\n' "$*"; } |
| 15 | die() { printf 'install: %s\n' "$*" >&2; exit 1; } | 14 | die() { printf 'install: %s\n' "$*" >&2; exit 1; } |
| 16 | 15 | ||
| 16 | command -v curl >/dev/null 2>&1 || die "curl is required" | ||
| 17 | command -v sha256sum >/dev/null 2>&1 || die "sha256sum is required" | 17 | command -v sha256sum >/dev/null 2>&1 || die "sha256sum is required" |
| 18 | 18 | ||
| 19 | latest=$(curl -fsSL --max-time 30 "$SITE/latest.php") \ | ||
| 20 | || die "could not read $SITE/latest.php" | ||
| 21 | line=$(printf '%s\n' "$latest" \ | ||
| 22 | | awk -v p="$PLATFORM" -v a="$ARCH" '$1 == "gui" && $2 == p && $3 == a { print; exit }') | ||
| 23 | [ -n "$line" ] || die "no Linux build is published yet" | ||
| 24 | |||
| 25 | version=$(printf '%s\n' "$line" | awk '{print $4}') | ||
| 26 | binary=$(printf '%s\n' "$line" | awk '{print $5}') | ||
| 27 | sha=$(printf '%s\n' "$line" | awk '{print $6}') | ||
| 28 | [ -n "$version" ] && [ -n "$binary" ] && [ -n "$sha" ] \ | ||
| 29 | || die "the latest-build file is malformed" | ||
| 30 | |||
| 31 | say "Newest Zagan-Bet is $version." | ||
| 32 | |||
| 19 | here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) | 33 | here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 20 | source_file="" | 34 | source_file="" |
| 21 | for candidate in "$here/$BINARY" "./$BINARY" "$HOME/Downloads/$BINARY"; do | 35 | for candidate in "$here/$binary" "./$binary" "$HOME/Downloads/$binary"; do |
| 22 | if [ -f "$candidate" ]; then | 36 | if [ -f "$candidate" ]; then |
| 23 | source_file=$candidate | 37 | source_file=$candidate |
| 24 | break | 38 | break |
| @@ -27,16 +41,17 @@ done | |||
| 27 | 41 | ||
| 28 | cleanup="" | 42 | cleanup="" |
| 29 | if [ -z "$source_file" ]; then | 43 | if [ -z "$source_file" ]; then |
| 30 | command -v curl >/dev/null 2>&1 || die "put $BINARY next to this installer, or install curl" | ||
| 31 | cleanup=$(mktemp) || die "cannot create a temporary file" | 44 | cleanup=$(mktemp) || die "cannot create a temporary file" |
| 32 | say "Downloading $BINARY..." | 45 | say "Downloading $binary..." |
| 33 | curl -fsSL --max-time 300 "$URL" -o "$cleanup" || die "download failed" | 46 | curl -fsSL --max-time 300 "$SITE/bin/gui/$binary" -o "$cleanup" \ |
| 47 | || die "download failed" | ||
| 34 | source_file=$cleanup | 48 | source_file=$cleanup |
| 35 | fi | 49 | fi |
| 36 | trap 'if [ -n "$cleanup" ]; then rm -f "$cleanup"; fi' EXIT | 50 | trap 'if [ -n "$cleanup" ]; then rm -f "$cleanup"; fi' EXIT |
| 37 | 51 | ||
| 38 | actual=$(sha256sum "$source_file" | awk '{print $1}') | 52 | actual=$(sha256sum "$source_file" | awk '{print $1}') |
| 39 | [ "$actual" = "$SHA256" ] || die "checksum mismatch: expected $SHA256, got $actual" | 53 | [ "$actual" = "$sha" ] \ |
| 54 | || die "checksum mismatch: expected $sha, got $actual" | ||
| 40 | 55 | ||
| 41 | bin_dir="${XDG_BIN_HOME:-$HOME/.local/bin}" | 56 | bin_dir="${XDG_BIN_HOME:-$HOME/.local/bin}" |
| 42 | data_dir="${XDG_DATA_HOME:-$HOME/.local/share}" | 57 | data_dir="${XDG_DATA_HOME:-$HOME/.local/share}" |
| @@ -48,7 +63,12 @@ mkdir -p "$bin_dir" "$desktop_dir" "$icon_dir" | |||
| 48 | install -m 0755 "$source_file" "$app" | 63 | install -m 0755 "$source_file" "$app" |
| 49 | 64 | ||
| 50 | cat > "$icon_dir/zagan-bet.svg" <<'ICON' | 65 | cat > "$icon_dir/zagan-bet.svg" <<'ICON' |
| 51 | __ICON__ | 66 | <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" width="64" height="64"> |
| 67 | <rect width="64" height="64" rx="14" fill="#0a0e12"/> | ||
| 68 | <rect x="9" y="9" width="46" height="46" rx="10" fill="#0f1a14" stroke="#1f7d52" stroke-width="2"/> | ||
| 69 | <path d="M22 20h20L22 44h20" fill="none" stroke="#4ec27b" stroke-width="6" | ||
| 70 | stroke-linecap="round" stroke-linejoin="round"/> | ||
| 71 | </svg> | ||
| 52 | ICON | 72 | ICON |
| 53 | 73 | ||
| 54 | cat > "$desktop_dir/zagan-bet.desktop" <<DESKTOP | 74 | cat > "$desktop_dir/zagan-bet.desktop" <<DESKTOP |
| @@ -70,7 +90,7 @@ if command -v gtk-update-icon-cache >/dev/null 2>&1; then | |||
| 70 | gtk-update-icon-cache -q "$data_dir/icons/hicolor" >/dev/null 2>&1 || true | 90 | gtk-update-icon-cache -q "$data_dir/icons/hicolor" >/dev/null 2>&1 || true |
| 71 | fi | 91 | fi |
| 72 | 92 | ||
| 73 | say "Installed Zagan-Bet $VERSION to $app" | 93 | say "Installed Zagan-Bet $version to $app" |
| 74 | say "A launcher was added to your applications menu." | 94 | say "A launcher was added to your applications menu." |
| 75 | case ":$PATH:" in | 95 | case ":$PATH:" in |
| 76 | *":$bin_dir:"*) ;; | 96 | *":$bin_dir:"*) ;; |
