diff options
Diffstat (limited to '')
| -rw-r--r-- | web/install.sh (renamed from scripts/installers/linux.sh.in) | 50 |
1 files changed, 35 insertions, 15 deletions
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:"*) ;; |
