#!/bin/sh # Install PGoblin on macOS, Linux or WSL2. # # curl -fsSL https://pgremlin.com/install.sh | sh # the published release # scripts/install.sh /path/to/pgoblin-0.6.0-py3-none-any.whl # PGOBLIN_WHEEL=https://.../pgoblin-0.6.0-py3-none-any.whl scripts/install.sh # # With no wheel given, the published copy of this script installs the release it was # stamped with (scripts/release.py fills DEFAULT_WHEEL and DEFAULT_SHA256 below), and the # download must match that SHA-256. The copy in the repository has no default. The script # installs uv when it is missing (Astral's installer, over HTTPS only), installs PGoblin as a # uv tool, then runs `goblin doctor`. It never uses sudo and is safe to run again. # # Everything is in functions and the last line calls main, so a download cut short runs # nothing. # # Environment: # PGOBLIN_WHEEL the wheel, when no argument is given # PGOBLIN_WHEEL_SHA256 refuse an https wheel unless it has this SHA-256 # PGOBLIN_KEYCHAIN 1 adds `keyring` (secrets in the OS keychain), 0 leaves it # out (secrets in a 0600 file). Default: 1 on macOS, 0 on Linux. # PGOBLIN_UV_VERSION install this uv version instead of the latest # PGOBLIN_UV_INSTALLER_SHA256 refuse Astral's installer script unless it has this SHA-256 # PGOBLIN_ALLOW_ROOT 1 allows running as root (containers); otherwise refused set -eu # Stamped by scripts/release.py in the published copy; empty here. DEFAULT_WHEEL="https://pgremlin.com/download/pgoblin-0.8.0-py3-none-any.whl" DEFAULT_SHA256="f11150fb19e3beabe64d16380aea01b146bd2f7c0c738cc71c5655402d176334" say() { printf '%s\n' "$*"; } die() { printf 'install.sh: %s\n' "$*" >&2; exit "${2:-1}"; } sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 else shasum -a 256 "$1" | cut -d' ' -f1 fi } install_uv() { command -v curl >/dev/null 2>&1 || die "uv is missing and so is curl; install uv by hand: https://docs.astral.sh/uv/" if [ -n "${PGOBLIN_UV_VERSION:-}" ]; then url="https://astral.sh/uv/${PGOBLIN_UV_VERSION}/install.sh" else url="https://astral.sh/uv/install.sh" fi uvtmp=$(mktemp -d) say "uv is missing; downloading Astral's installer from $url" curl --proto '=https' --tlsv1.2 -fsSL "$url" -o "$uvtmp/uv-install.sh" if [ -n "${PGOBLIN_UV_INSTALLER_SHA256:-}" ]; then got=$(sha256 "$uvtmp/uv-install.sh") [ "$got" = "$PGOBLIN_UV_INSTALLER_SHA256" ] || { rm -rf "$uvtmp"; die "uv installer SHA-256 is $got, expected $PGOBLIN_UV_INSTALLER_SHA256"; } say "uv installer SHA-256 matches" fi sh "$uvtmp/uv-install.sh" /dev/null 2>&1 || die "curl is needed to download $wheel" wheeltmp=$(mktemp -d) local_wheel="$wheeltmp/$(basename "$wheel")" curl --proto '=https' --tlsv1.2 -fsSL "$wheel" -o "$local_wheel" /dev/null 2>&1; then say "uv: $(command -v uv)" else install_uv PATH="${XDG_BIN_HOME:-$HOME/.local/bin}:$HOME/.cargo/bin:$PATH" export PATH command -v uv >/dev/null 2>&1 || die "uv was installed but is not on PATH; open a new shell and run this again" fi with="" if [ "${PGOBLIN_KEYCHAIN:-$keychain_default}" = 1 ]; then with="--with keyring" fi say "installing PGoblin from $wheel" # --force makes a second run reinstall instead of stopping at "already installed". # shellcheck disable=SC2086 # $with is empty or two words on purpose uv tool install --force --python 3.12 $with "$wheel"