#!/bin/sh
# Configure only the repository; application installation is a separate step.
set -eu
test "$(id -u)" = 0 || { echo 'Execute com sudo ou como root.' >&2; exit 1; }
. /etc/os-release
test "${ID:-}" = debian && test "${VERSION_CODENAME:-}" = 'trixie' || {
    echo 'Este repositório atende Debian 13 (trixie).' >&2; exit 1;
}
test "$(dpkg --print-architecture)" = 'amd64' || { echo 'Arquitetura não suportada.' >&2; exit 1; }
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT HUP INT TERM
curl -fsSLo "$tmp/key.asc" 'https://deb.schip.com.br/schip-archive-keyring.asc'
printf '%s  %s\n' '5d90582203c5ba6dba973c3a1bd3c6542f52e4705a346f9fa228cb66dd0c6fe1' "$tmp/key.asc" | sha256sum -c - > /dev/null
install -d -m 755 /etc/apt/keyrings
install -m 644 "$tmp/key.asc" /etc/apt/keyrings/schip-archive-keyring.asc
cat > "$tmp/schip.sources" <<'SOURCES'
Types: deb
URIs: https://deb.schip.com.br
Suites: trixie
Components: main
Architectures: amd64
Signed-By: /etc/apt/keyrings/schip-archive-keyring.asc
SOURCES
install -m 644 "$tmp/schip.sources" /etc/apt/sources.list.d/schip.sources
apt-get update
echo 'Repositório configurado. Exemplo: apt install schipmyserver'
