summaryrefslogtreecommitdiffstats
path: root/web/install.sh
diff options
context:
space:
mode:
Diffstat (limited to 'web/install.sh')
-rw-r--r--web/install.sh98
1 files changed, 98 insertions, 0 deletions
diff --git a/web/install.sh b/web/install.sh
new file mode 100644
index 0000000..998b262
--- /dev/null
+++ b/web/install.sh
@@ -0,0 +1,98 @@
1#!/usr/bin/env bash
2# Zagan-Bet installer for Linux.
3#
4# Asks the site which build is newest, verifies its SHA-256, installs it for
5# the current user and adds a launcher. Point it at a staging site with
6# ZAGAN_SITE=http://127.0.0.1:8899.
7set -euo pipefail
8
9SITE=${ZAGAN_SITE:-https://zagan.2137697.xyz}
10PLATFORM=linux
11ARCH=x86_64
12
13say() { printf '%s\n' "$*"; }
14die() { printf 'install: %s\n' "$*" >&2; exit 1; }
15
16command -v curl >/dev/null 2>&1 || die "curl is required"
17command -v sha256sum >/dev/null 2>&1 || die "sha256sum is required"
18
19latest=$(curl -fsSL --max-time 30 "$SITE/latest.php") \
20 || die "could not read $SITE/latest.php"
21line=$(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
25version=$(printf '%s\n' "$line" | awk '{print $4}')
26binary=$(printf '%s\n' "$line" | awk '{print $5}')
27sha=$(printf '%s\n' "$line" | awk '{print $6}')
28[ -n "$version" ] && [ -n "$binary" ] && [ -n "$sha" ] \
29 || die "the latest-build file is malformed"
30
31say "Newest Zagan-Bet is $version."
32
33here=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
34source_file=""
35for candidate in "$here/$binary" "./$binary" "$HOME/Downloads/$binary"; do
36 if [ -f "$candidate" ]; then
37 source_file=$candidate
38 break
39 fi
40done
41
42cleanup=""
43if [ -z "$source_file" ]; then
44 cleanup=$(mktemp) || die "cannot create a temporary file"
45 say "Downloading $binary..."
46 curl -fsSL --max-time 300 "$SITE/bin/gui/$binary" -o "$cleanup" \
47 || die "download failed"
48 source_file=$cleanup
49fi
50trap 'if [ -n "$cleanup" ]; then rm -f "$cleanup"; fi' EXIT
51
52actual=$(sha256sum "$source_file" | awk '{print $1}')
53[ "$actual" = "$sha" ] \
54 || die "checksum mismatch: expected $sha, got $actual"
55
56bin_dir="${XDG_BIN_HOME:-$HOME/.local/bin}"
57data_dir="${XDG_DATA_HOME:-$HOME/.local/share}"
58app="$bin_dir/zagan-bet-gui"
59desktop_dir="$data_dir/applications"
60icon_dir="$data_dir/icons/hicolor/scalable/apps"
61
62mkdir -p "$bin_dir" "$desktop_dir" "$icon_dir"
63install -m 0755 "$source_file" "$app"
64
65cat > "$icon_dir/zagan-bet.svg" <<'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>
72ICON
73
74cat > "$desktop_dir/zagan-bet.desktop" <<DESKTOP
75[Desktop Entry]
76Type=Application
77Name=Zagan-Bet
78Comment=Slots, roulette, blackjack and crash
79Exec=$app
80Icon=zagan-bet
81Terminal=false
82Categories=Game;
83DESKTOP
84chmod 0644 "$desktop_dir/zagan-bet.desktop" "$icon_dir/zagan-bet.svg"
85
86if command -v update-desktop-database >/dev/null 2>&1; then
87 update-desktop-database "$desktop_dir" >/dev/null 2>&1 || true
88fi
89if command -v gtk-update-icon-cache >/dev/null 2>&1; then
90 gtk-update-icon-cache -q "$data_dir/icons/hicolor" >/dev/null 2>&1 || true
91fi
92
93say "Installed Zagan-Bet $version to $app"
94say "A launcher was added to your applications menu."
95case ":$PATH:" in
96 *":$bin_dir:"*) ;;
97 *) say "Add $bin_dir to PATH to start it as 'zagan-bet-gui'." ;;
98esac