#!/bin/sh # Geometer one-line installer (alpha). Served at https://geometer.dev/install.sh: # # curl -fsSL https://geometer.dev/install.sh | sh # curl -fsSL https://geometer.dev/install.sh | sh -s -- --prefix "$HOME/tools" # # What it does, in order: looks at this computer (macOS on Apple silicon, or Linux on x86_64 or arm64), # downloads the matching geo tarball and SHA256SUMS from the GitHub release, checks the tarball's # SHA-256 against SHA256SUMS and stops if it differs, unpacks into a temporary folder and runs the # tarball's own install.sh (which installs for you alone, under ~/.local by default). It never uses # sudo and changes nothing outside the install folder and your Geometer records folder. # # Settings (environment): GEO_VERSION picks another release than the one named below; # GEO_BASE_URL replaces the download address (for a mirror or a test; files are read from # $GEO_BASE_URL/geo---.tar.gz and $GEO_BASE_URL/SHA256SUMS). # The version below is written in when a release is made (tools/release/release.sh). set -eu DEFAULT_VERSION="0.1.0-alpha.2" VERSION="${GEO_VERSION:-$DEFAULT_VERSION}" case "$VERSION" in @*) echo "This copy of the installer has no release version written in. Set GEO_VERSION, for example GEO_VERSION=0.1.0-alpha.2." >&2; exit 2 ;; esac BASE="${GEO_BASE_URL:-https://github.com/GeometerLabs/geometer/releases/download/v$VERSION}" say() { printf '%s\n' "$*"; } die() { printf '%s\n' "$*" >&2; exit 1; } # Show help without doing anything. for a in "$@"; do case "$a" in -h|--help) say "Installs Geometer $VERSION for your user (no administrator rights)." say "Options are passed to the installer: --prefix DIR (default ~/.local), --home DIR." say "Set GEO_VERSION to install another release." exit 0 ;; esac done if [ "$(id -u)" = 0 ]; then die "Please run this as yourself, not as an administrator or with sudo: Geometer installs for one user." fi OS="$(uname -s)" M="$(uname -m)" case "$OS" in Darwin) case "$M" in arm64) PLATFORM="macos-arm64" ;; x86_64) die "This is an Intel Mac, and the alpha is built for Apple silicon only. Nothing was installed." ;; *) die "Geometer does not have a build for this Mac ($M). Nothing was installed." ;; esac ;; Linux) case "$M" in x86_64|amd64) PLATFORM="linux-x86_64" ;; aarch64|arm64) PLATFORM="linux-aarch64" ;; *) die "Geometer does not have a Linux build for this processor ($M); it is built for x86_64 and arm64. Nothing was installed." ;; esac ;; *) die "Geometer does not have a build for $OS; it is built for macOS on Apple silicon and for Linux. Nothing was installed." ;; esac if command -v sha256sum >/dev/null 2>&1; then sha_of() { sha256sum "$1" | awk '{print $1}'; } elif command -v shasum >/dev/null 2>&1; then sha_of() { shasum -a 256 "$1" | awk '{print $1}'; } else die "Neither sha256sum nor shasum is installed, so the download cannot be checked. Nothing was installed." fi if command -v curl >/dev/null 2>&1; then fetch() { curl -fsSL -o "$2" "$1"; } elif command -v wget >/dev/null 2>&1; then fetch() { wget -q -O "$2" "$1"; } else die "Neither curl nor wget is installed, so nothing can be downloaded. Nothing was installed." fi FILE="geo-$VERSION-$PLATFORM.tar.gz" TMP="$(mktemp -d "${TMPDIR:-/tmp}/geometer-install.XXXXXX")" trap 'rm -rf "$TMP"' EXIT INT TERM say "Geometer $VERSION for $PLATFORM" say "Downloading $FILE ..." fetch "$BASE/$FILE" "$TMP/$FILE" || die "Could not download $BASE/$FILE. Check your connection and that release $VERSION exists. Nothing was installed." fetch "$BASE/SHA256SUMS" "$TMP/SHA256SUMS" || die "Could not download $BASE/SHA256SUMS. Nothing was installed." WANT="$(awk -v f="$FILE" '$2 == f || $2 == "*" f {print $1; exit}' "$TMP/SHA256SUMS")" [ -n "$WANT" ] || die "$FILE is not listed in SHA256SUMS. Nothing was installed." GOT="$(sha_of "$TMP/$FILE")" if [ "$GOT" != "$WANT" ]; then die "The download does not match its published checksum (expected $WANT, got $GOT). It may be damaged or altered. Nothing was installed." fi say "Checksum matches ($GOT)." mkdir "$TMP/unpacked" tar -xzf "$TMP/$FILE" -C "$TMP/unpacked" || die "Could not unpack the download. Nothing was installed." DIR="$TMP/unpacked/geo-$VERSION-$PLATFORM" [ -f "$DIR/install.sh" ] || die "The download does not contain an installer. Nothing was installed." say "Running the installer ..." sh "$DIR/install.sh" "$@" || die "The installer stopped (see above). Anything already installed was left as it was." PFX="$HOME/.local" prev="" for a in "$@"; do [ "$prev" = "--prefix" ] && PFX="$a" prev="$a" done say "" say "Done. To see a first result on a practice agent, run: $PFX/bin/geo practice --check" say "To remove Geometer: $PFX/lib/geometer/current/uninstall.sh --prefix $PFX (add --purge-records to delete your records too)" say "To go back to the previous version after an upgrade: run the installer again with --rollback."