#!/usr/bin/env bash
set -euo pipefail
CONFIG="$HOME/.local/share/gothbot/config"
[[ -f "$CONFIG" ]] || { echo "GothBot is not installed." >&2; exit 1; }
# shellcheck source=/dev/null
source "$CONFIG"
tmp="$(mktemp -d)"
trap 'rm -rf -- "$tmp"' EXIT
curl --fail --location --retry 3 "$GOTHBOT_API_BASE/api/updates/linux" -o "$tmp/gothbot-linux.tar.gz"
tar -xzf "$tmp/gothbot-linux.tar.gz" -C "$tmp"
bash "$tmp/gothbot-linux/install.sh" --game-dir "$GOTHBOT_GAME_DIR" --wine-prefix "$WINEPREFIX"
