#!/usr/bin/env bash
# One-liner installer for the Print Platform Pro APT repository.
#
# Curl-pipe-bash isn't ideal — but it matches how Slack, Microsoft
# Edge, and Docker tell people to add their repos, and it's the
# only ergonomic option until the apt-repo signing key is published
# to keyring.printplatformpro.com (deferred to v2.2-rc3 alongside
# the RPM repo's GPG key).
#
# Users run:
#   curl -fsSL https://downloads.printplatformpro.com/deb/install-deb-repo.sh | sudo bash
#
# After that, `apt install pppro-browser-linux` works normally,
# auto-updates land via the standard `apt upgrade`, and GNOME
# Software / KDE Discover get the AppStream binding they need
# for working Install + Uninstall buttons.

set -euo pipefail

REPO_URL="https://downloads.printplatformpro.com/deb"
LIST_FILE="/etc/apt/sources.list.d/pppro.list"

if [ "$(id -u)" -ne 0 ]; then
    echo "fatal: run me with sudo so I can write to /etc/apt/sources.list.d/" >&2
    exit 1
fi

# Write the sources.list.d entry. Suite + component match how
# Debian/Ubuntu organise their own repos; we use a single
# "stable" suite + "main" component so users on any Debian-family
# distro point at the same Packages.gz.
#
# trusted=yes silences the "unsigned repository" warning until
# the GPG key is provisioned. v2.2-rc3 will replace this with
# signed-by=/usr/share/keyrings/printplatformpro.gpg.
cat > "$LIST_FILE" <<EOF
deb [arch=amd64 trusted=yes] $REPO_URL stable main
EOF

apt-get update
echo
echo "Print Platform Pro APT repo added. Install with:"
echo "  sudo apt install pppro-browser-linux"
