#!/bin/sh # Downloaded via HTTPS. Trust is restricted to this repository and package. palacehub_setup_apt() ( set -eu fail() { printf 'palacehub: %s\n' "$@" >&2; exit 1; } [ "$(id -u)" = 0 ] || fail 'Run this setup with sudo sh.' [ "$(uname -s)" = Linux ] || fail 'Linux is required.' command -v apt-get >/dev/null 2>&1 || fail 'APT was not found: this setup is for Debian and Ubuntu.' \ 'On other Linux x64 distributions (glibc), use the standalone installer instead:' \ ' curl -fsS https://updates.palace-hub.net/palacehub-cli/install.sh | sudo sh' [ "$(dpkg --print-architecture)" = amd64 ] || fail 'Only amd64 is currently published.' for tool in curl sha256sum mktemp install; do command -v "$tool" >/dev/null 2>&1 || fail "Missing prerequisite: $tool" done [ "$#" = 0 ] || fail 'This setup takes no arguments.' work=$(mktemp -d) trap 'rm -rf -- "$work"' EXIT HUP INT TERM curl --fail --silent --show-error --proto '=https' --tlsv1.2 --connect-timeout 20 --max-time 60 \ https://updates.palace-hub.net/palacehub-cli/apt/palacehub-archive-keyring.gpg -o "$work/key.gpg" printf '%s %s\n' '2dc4ce29f1a7ad1fc774308cfa5b7198e19483186aa0f65d7be842d23a08ab8b' "$work/key.gpg" | sha256sum -c - || fail 'Signing key checksum mismatch.' cat > "$work/palacehub.sources" <<'SOURCES' Types: deb URIs: https://updates.palace-hub.net/palacehub-cli/apt Suites: stable Components: main Architectures: amd64 Signed-By: /etc/apt/keyrings/palacehub.gpg E1686CB36BCEADFC52C53B67210B9ED6CCE1C40F SOURCES cat > "$work/palacehub.pref" <<'PREFERENCES' Package: palacehub Pin: origin updates.palace-hub.net Pin-Priority: 500 Package: * Pin: origin updates.palace-hub.net Pin-Priority: -1 PREFERENCES # Migrate only the exact original public standalone binary. Never delete an unknown file. legacy=/usr/local/bin/palacehub migrate=no if [ -e "$legacy" ] || [ -L "$legacy" ]; then [ -f "$legacy" ] && [ ! -L "$legacy" ] || fail "Existing $legacy is not a regular file; resolve it before APT setup." hash=$(sha256sum "$legacy"); hash=${hash%% *} case "$hash" in 866e43cee61171f18a5c94656d338d99f459c726076816d4ce4cec9d097c0347|ee7aba0e2ebc5dbe287643a451f5997b5da7f604b563e018672d2d550045f9af) migrate=yes ;; *) fail "Existing $legacy would shadow APT. Move it aside manually, then retry; it has been preserved." ;; esac [ ! -e "$legacy.pre-apt" ] && [ ! -L "$legacy.pre-apt" ] || fail 'A pre-APT backup already exists; resolve it first.' fi install -d -m 0755 /etc/apt/keyrings /etc/apt/sources.list.d /etc/apt/preferences.d # Refuse conflicting operator configuration instead of overwriting it. for pair in 'key.gpg:/etc/apt/keyrings/palacehub.gpg' 'palacehub.sources:/etc/apt/sources.list.d/palacehub.sources' 'palacehub.pref:/etc/apt/preferences.d/palacehub'; do source=${pair%%:*}; destination=${pair#*:} if [ -e "$destination" ] || [ -L "$destination" ]; then [ ! -L "$destination" ] && cmp -s "$work/$source" "$destination" || fail "Conflicting configuration preserved: $destination" fi done install -m 0644 "$work/key.gpg" /etc/apt/keyrings/palacehub.gpg install -m 0644 "$work/palacehub.sources" /etc/apt/sources.list.d/palacehub.sources install -m 0644 "$work/palacehub.pref" /etc/apt/preferences.d/palacehub apt-get update -o APT::Update::Error-Mode=any apt-get install -y --no-install-recommends palacehub if [ "$migrate" = yes ]; then current=$(sha256sum "$legacy"); current=${current%% *} [ "$current" = "$hash" ] || fail 'Standalone binary changed during setup; preserved.' mv -n -- "$legacy" "$legacy.pre-apt" fi printf '%s\n' 'PalaceHub installed. Run palacehub without sudo.' 'Future updates: sudo apt update && sudo apt install --only-upgrade palacehub' ) palacehub_setup_apt "$@"