#!/usr/bin/env bash
# Danke Suite : télécharge l'archive depuis 710hub.com, vérifie son empreinte SHA-256, puis lance l'installation.
#   curl -fsSL https://www.710hub.com/DankeSuite/downloads/get.sh | bash
#   curl -fsSL https://www.710hub.com/DankeSuite/downloads/get.sh | bash -s -- --with-os
# Les options sont transmises à install.sh (voir install.sh --help).
set -euo pipefail
BASE="${DANKE_BASE:-https://www.710hub.com/DankeSuite/downloads}"
VERSION="1.4.0"
CORE="danke-suite-$VERSION-linux-x86_64.tar.gz"
OS="danke-os-$VERSION-linux-x86_64.tar.xz"
DIR="${DANKE_DOWNLOAD_DIR:-$HOME/.cache/danke-suite/$VERSION}"
mkdir -p "$DIR" && cd "$DIR"

fetch() { echo "» téléchargement de $1"; curl -fSL --progress-bar -o "$1.part" "$BASE/$1" && mv "$1.part" "$1"; }
fetch SHA256SUMS
fetch "$CORE"
case " $* " in *" --with-os "*) fetch "$OS" ;; esac
for f in "$CORE" $([ -f "$OS" ] && echo "$OS"); do
  grep -E "  $f\$" SHA256SUMS | sha256sum -c --quiet - || { echo "✗ empreinte invalide pour $f : installation annulée."; exit 1; }
done
echo "✓ empreintes vérifiées"
rm -rf "danke-suite-$VERSION" && tar -xzf "$CORE"
[ -f "$OS" ] && mv -f "$OS" "danke-suite-$VERSION/"
cd "danke-suite-$VERSION"
if [ -r /dev/tty ] && [ -t 1 ]; then exec bash ./install.sh "$@" < /dev/tty; else exec bash ./install.sh --yes "$@"; fi
