#!/bin/sh # Public HTTPS bootstrap. Keep invocation last so an incomplete download cannot install. palacehub_install() ( set -eu fail() { printf '%s\n' "palacehub: $*" >&2; exit 1; } prefix=/usr/local case "${1:-}" in --help|-h) printf '%s\n' 'Usage: sudo sh install.sh [--prefix /absolute/path]'; exit 0 ;; --prefix) [ "$#" -eq 2 ] || fail 'Expected --prefix /absolute/path'; prefix=$2 ;; '') [ "$#" -eq 0 ] || fail 'Unexpected argument' ;; *) fail 'Usage: sudo sh install.sh [--prefix /absolute/path]' ;; esac case "$prefix" in /*) ;; *) fail 'Prefix must be absolute' ;; esac if [ "$prefix" = /usr/local ] && command -v dpkg-query >/dev/null 2>&1 && [ "$(dpkg-query -W -f='${Status}' palacehub 2>/dev/null || true)" = 'install ok installed' ]; then fail 'PalaceHub is managed by APT. Use: sudo apt update && sudo apt install --only-upgrade palacehub' fi [ "$(uname -s)" = Linux ] || fail 'This installer requires Linux' case "$(uname -m)" in x86_64|amd64) target=linux-x64 version=0.2.8 checksum=ee7aba0e2ebc5dbe287643a451f5997b5da7f604b563e018672d2d550045f9af ;; *) fail 'The hosted release currently supports Linux x64 only' ;; esac for tool in curl sha256sum install mktemp mv getconf; do command -v "$tool" >/dev/null 2>&1 || fail "Missing prerequisite: $tool" done getconf GNU_LIBC_VERSION >/dev/null 2>&1 || fail 'A glibc Linux distribution is required (Alpine/musl is unsupported)' destination=$prefix/bin mkdir -p -- "$destination" || fail 'Use sudo or --prefix "$HOME/.local"' staged=$(mktemp "$destination/.palacehub-download.XXXXXXXX") trap 'rm -f -- "$staged"' EXIT HUP INT TERM url="https://updates.palace-hub.net/palacehub-cli/files/$version/$target/$checksum/palacehub" printf '%s\n' "Downloading PalaceHub CLI $version ($target)..." curl --fail --silent --show-error --proto '=https' --tlsv1.2 --connect-timeout 20 --max-time 600 --retry 2 --output "$staged" "$url" printf '%s %s\n' "$checksum" "$staged" | sha256sum -c - || fail 'Download checksum mismatch; existing installation preserved' chmod 0755 "$staged" mv -f -- "$staged" "$destination/palacehub" printf '%s\n' "Installed $destination/palacehub" 'Run palacehub as your normal user, without sudo.' case ":$PATH:" in *":$destination:"*) ;; *) printf '%s\n' "Add $destination to your PATH." ;; esac ) palacehub_install "$@"