#!/bin/sh # Installs Superscribe for Linux from its package repository: # # curl -fsSL https://dl.superscribe.io/linux/install.sh | sh # # Debian, Ubuntu and their relatives get the APT repository, Arch and its relatives (Omarchy, EndeavourOS, CachyOS, # Manjaro) the [superscribe] pacman repository, so updates come with the system's own updates. Other distributions # are shown the tarball. Run it as yourself: it asks for sudo when it needs it. Running it again changes nothing that # is already in place. Published as https://dl.superscribe.io/linux/install.sh by apps/linux/build-linux.sh, which # fills in the repository key's SHA-256 and fingerprint below; the key is checked against them before it is trusted. # # SUPERSCRIBE_TEST_BASE_URL points it at a local copy of https://dl.superscribe.io/linux, for tests only. set -eu key_sha256=2ee48ccadd4590424d1d411516e4b0b4cbd9bccfa189698db5cd0eb29a625546 key_fingerprint=358C69B744560203BCC58FE65E4DDEB2AA308C58 say() { printf '%s\n' "$*"; } die() { printf 'Superscribe: %s\n' "$*" >&2; exit 1; } fetch() { if command -v curl >/dev/null 2>&1; then curl -fsSL --proto "$protocols" --retry 2 -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1" else die "install curl or wget first." fi } sha256_of() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d ' ' -f 1 else shasum -a 256 "$1" | cut -d ' ' -f 1 fi } # Downloads the repository key and refuses it unless it is the key this script was built with. fetch_key() { fetch "$base/superscribe-archive-keyring.pgp" "$temporary/key.pgp" [ "$(sha256_of "$temporary/key.pgp")" = "$key_sha256" ] || die "the repository key at $base does not match this installer. Nothing was changed. Try again in a few minutes." } # Commands that ask (pacman's prompt) read the terminal, not this script, which arrives on standard input. interactive() { [ -t 1 ] && { : < /dev/tty; } 2>/dev/null; } install_apt() { architecture=$(dpkg --print-architecture) case $architecture in amd64 | arm64) ;; *) die "there are packages for amd64 and arm64, not $architecture." ;; esac keyring=/usr/share/keyrings/superscribe-archive-keyring.pgp sources=/etc/apt/sources.list.d/superscribe.sources address=${base#*://}/apt fetch_key if ! cmp -s "$temporary/key.pgp" "$keyring" 2>/dev/null; then as_root install -m 644 "$temporary/key.pgp" "$keyring" fi existing= for file in /etc/apt/sources.list /etc/apt/sources.list.d/*.list /etc/apt/sources.list.d/*.sources; do if [ -f "$file" ] && grep -qF "$address" "$file"; then existing=$file; break; fi done if [ -n "$existing" ]; then say "Using the Superscribe repository already in $existing." else cat > "$temporary/superscribe.sources" </dev/null | grep -q '^sec'; then as_root pacman-key --init as_root pacman-key --populate >/dev/null fi as_root pacman-key --add "$temporary/key.pgp" >/dev/null as_root pacman-key --lsign-key "$key_fingerprint" >/dev/null cat > "$temporary/superscribe.conf" </dev/null; then as_root install -m 644 "$temporary/superscribe.conf" "$snippet" fi if grep -qxF "$include" /etc/pacman.conf; then : elif grep -q '^\[superscribe\]' /etc/pacman.conf; then say "Using the [superscribe] repository already in /etc/pacman.conf." else printf '\n%s\n' "$include" | as_root tee -a /etc/pacman.conf >/dev/null say "Added the [superscribe] repository to /etc/pacman.conf." fi # Omarchy rewrites /etc/pacman.conf on "omarchy refresh pacman"; its hook puts the Include line back. config=${XDG_CONFIG_HOME:-$HOME/.config} if [ "$(id -u)" != 0 ] && [ -d "$config/omarchy" ]; then hook="$config/omarchy/hooks/pre-refresh-pacman.d/superscribe" mkdir -p "${hook%/*}" cat > "$hook" </dev/null EOF chmod 755 "$hook" fi # A full upgrade, as Arch requires: installing from a refreshed database without one is a partial upgrade. if interactive; then as_root pacman -Syu --needed superscribe < /dev/tty else as_root pacman -Syu --needed --noconfirm superscribe < /dev/null fi } tarball_route() { case $(uname -m) in x86_64 | amd64) architecture=x86_64 ;; aarch64 | arm64) architecture=aarch64 ;; *) die "Superscribe for Linux runs on x86_64 and aarch64, not $(uname -m)." ;; esac say "This system has neither apt nor pacman. Install Superscribe from the tarball, without root:" say "" say " curl -fLO $base/superscribe-latest-$architecture.tar.xz" say " tar -xJf superscribe-latest-$architecture.tar.xz" say " superscribe/install.sh" say "" say "It installs to ~/.local and does not update itself. The checksums are in $base/SHA256SUMS." } main() { base=https://dl.superscribe.io/linux protocols='=https' if [ -n "${SUPERSCRIBE_TEST_BASE_URL:-}" ]; then base=${SUPERSCRIBE_TEST_BASE_URL%/} protocols='=https,http' say "Test mode: using $base instead of https://dl.superscribe.io/linux." fi case $key_sha256$key_fingerprint in *@*) die "this copy of install.sh was not built for a release (no repository key)." ;; esac [ "$(uname -s)" = Linux ] || die "this installer is for Linux." if [ "$(id -u)" = 0 ]; then if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != root ]; then die "run it as yourself, without sudo: curl -fsSL $base/install.sh | sh It asks for your password when it needs it." fi as_root() { "$@"; } else command -v sudo >/dev/null 2>&1 || die "this needs sudo, or run it as root." as_root() { sudo "$@"; } fi temporary=$(mktemp -d) trap 'rm -rf "$temporary"' EXIT trap 'exit 1' INT TERM if command -v apt-get >/dev/null 2>&1 && command -v dpkg >/dev/null 2>&1; then install_apt elif command -v pacman >/dev/null 2>&1; then install_pacman else tarball_route return 0 fi say "" say "Superscribe is installed. Open it from your applications, or run: superscribe" say "Updates come with your system's updates." } # Last line: a download cut short runs nothing. main "$@"