#!/bin/sh
# Chadtopia launcher starter (package chadtopia-launcher). Runs a user-owned copy so the
# launcher can update itself; the packaged copy only seeds it.
set -eu
here=$(dirname "$(readlink -f "$0")")
seed="$here/../lib/chadtopia-launcher/Chad-Launcher-Linux"
dir="${XDG_DATA_HOME:-$HOME/.local/share}/chadtopia/launcher"
exe="$dir/Chad-Launcher-Linux"
mark="$dir/.package-seed"
sum=$(sha256sum "$seed" | cut -d' ' -f1)
if [ ! -x "$exe" ] || [ "$(cat "$mark" 2>/dev/null || true)" != "$sum" ]; then
    mkdir -p "$dir"
    cp "$seed" "$exe.part"
    chmod 755 "$exe.part"
    mv -f "$exe.part" "$exe"
    printf '%s\n' "$sum" > "$mark"
fi
exec "$exe" "$@"
