#!/bin/bash set -euo pipefail fail() { printf '%s\n' "$*" >&2; exit 1; } [[ "$(uname -s)" == Linux ]] || fail 'This installer requires Linux.' [[ "$(uname -m)" == x86_64 ]] || fail 'Linux builds currently support x86_64 only.' command -v curl >/dev/null || fail 'Install curl using your package manager, then try again.' # Keep this installation entirely within the current user's home directory. install_dir="$HOME/.local/opt/pickware-games" data_dir="${XDG_DATA_HOME:-$HOME/.local/share}" [[ "$data_dir" == /* ]] || fail 'XDG_DATA_HOME must be an absolute path.' mkdir -p "$install_dir" "$data_dir/applications" "$data_dir/icons/hicolor/256x256/apps" work=$(mktemp -d "$install_dir/.install.XXXXXX") trap 'rm -rf "$work"' EXIT trap 'exit 130' INT trap 'exit 143' TERM printf '%s\n' 'Downloading Pickware Games for Linux (x86_64)…' curl --fail --show-error --location --proto '=https' --proto-redir '=https' --retry 2 \ https://games.pickware.com/api/downloads/launcher/linux-x64 -o "$work/Pickware-Games.AppImage" # Reject error pages and non-AppImage downloads before replacing an existing app. [[ "$(od -An -tx1 -N4 "$work/Pickware-Games.AppImage" | tr -d ' \n')" == 7f454c46 ]] || fail 'The download is not an ELF executable.' [[ "$(od -An -tx1 -j8 -N3 "$work/Pickware-Games.AppImage" | tr -d ' \n')" == 414902 ]] || fail 'The download is not a type-2 AppImage.' curl --fail --show-error --location --proto '=https' --proto-redir '=https' --retry 2 \ https://games.pickware.com/assets/app-icon.png -o "$work/icon.png" chmod 755 "$work/Pickware-Games.AppImage" # Desktop-entry escaping: two parsing layers (string values, then Exec quoting). exec_path="$install_dir/Pickware-Games.AppImage" exec_path=${exec_path//\\/\\\\\\\\} exec_path=${exec_path//\"/\\\\\"} exec_path=${exec_path//\$/\\\\\$} exec_path=${exec_path//\`/\\\\\`} exec_path=${exec_path//%/%%} [[ "$exec_path" != *$'\n'* && "$exec_path" != *$'\r'* ]] || fail 'The home directory contains an unsupported newline.' cat > "$work/pickware-games.desktop" </dev/null; then update-desktop-database "$data_dir/applications" || true; fi printf '%s\n' 'Installed. Open Pickware Games from your applications menu.' printf 'App location: %s\n' "$install_dir/Pickware-Games.AppImage"