#!/usr/bin/env bash # Installs (or upgrades) the swea console game from the Pitan RPM registry. # # curl -fsSL https://swea.pitan.net/install.sh | bash # # Supports dnf-based distros (Fedora, RHEL, Rocky, Alma, ...) on x86_64. # Everything runs inside main(), so a truncated download never runs half a script. set -euo pipefail REPO_ID="gitea-klas" REPO_FILE="/etc/yum.repos.d/${REPO_ID}.repo" REGISTRY="https://git.pitan.net/api/packages/klas" KEY_URL="${REGISTRY}/generic/swea-rpm-key/1/RPM-GPG-KEY-swea" KEY_FINGERPRINT="C35D14ADA0D513C8234B29B7CB485D14E185D4F8" info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } fail() { printf '\033[1;31merror:\033[0m %s\n' "$*" >&2; exit 1; } main() { command -v dnf >/dev/null || fail "dnf not found. This installer supports Fedora and other dnf-based distros only." command -v gpg >/dev/null || fail "gpg not found (install gnupg2), needed to verify the signing key." [[ "$(uname -m)" == x86_64 ]] || fail "only x86_64 is packaged (this machine is $(uname -m))." local sudo="" if [[ $EUID -ne 0 ]]; then command -v sudo >/dev/null || fail "run as root or install sudo." sudo="sudo" info "Some steps need root; sudo may ask for your password." fi local tmp tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT info "Fetching and verifying the package signing key" curl -fsSL "$KEY_URL" -o "$tmp/RPM-GPG-KEY-swea" local fingerprint fingerprint="$(gpg --show-keys --with-colons "$tmp/RPM-GPG-KEY-swea" 2>/dev/null | awk -F: '/^fpr:/ { print $10; exit }')" [[ "$fingerprint" == "$KEY_FINGERPRINT" ]] \ || fail "signing key fingerprint mismatch (got '${fingerprint:-none}', expected $KEY_FINGERPRINT). Aborting." $sudo rpm --import "$tmp/RPM-GPG-KEY-swea" # A repo added earlier via `dnf config-manager addrepo` lands in another # file with the same [gitea-klas] id; dnf rejects duplicate ids. local f for f in /etc/yum.repos.d/*.repo; do [[ -e "$f" && "$f" != "$REPO_FILE" ]] || continue if grep -q "^\[${REPO_ID}\]" "$f"; then info "Moving duplicate [${REPO_ID}] definition $f aside to $f.bak" $sudo mv "$f" "$f.bak" fi done info "Writing $REPO_FILE" $sudo tee "$REPO_FILE" >/dev/null </dev/null 2>&1; then info "Upgrading swea" $sudo dnf upgrade -y --refresh swea else info "Installing swea" $sudo dnf install -y --refresh swea fi info "Done: $(rpm -q swea). Run 'swea' to play." } main "$@"