#!/bin/sh # chlift installer (served by chlift.deemwar.com). # Downloads the chlift release binary for this machine, checks it against SHA256SUMS AND against the # checksums pinned in this script, then installs it. Nothing runs unless both checks pass. # curl -fsSL https://chlift.deemwar.com/install.sh | sh # Options (env): CHLIFT_INSTALL_DIR (default /usr/local/bin if writable, else ~/.local/bin) set -eu VERSION="v0.1.0-preview" BASE="https://chlift.deemwar.com/download/${VERSION}" SUM_AMD64="818bb4632240dcc4442f4ce83087bb379d6ef110b02173030f84b22c086a01f7" SUM_ARM64="4155e7eabdbcc75d4f49b9820406fbd3d1c603e70c863ea6026748304de6078d" say() { printf 'chlift: %s\n' "$*"; } die() { printf 'chlift: %s\n' "$*" >&2; exit 1; } [ "$(uname -s)" = "Linux" ] || die "release binaries are for Linux (amd64, arm64). This machine is $(uname -s)." case "$(uname -m)" in x86_64|amd64) ARCH=amd64; PINNED=$SUM_AMD64 ;; aarch64|arm64) ARCH=arm64; PINNED=$SUM_ARM64 ;; *) die "no release binary for $(uname -m) (amd64 and arm64 only)." ;; esac FILE="chlift-linux-${ARCH}" if command -v sha256sum >/dev/null 2>&1; then SHA="sha256sum" elif command -v shasum >/dev/null 2>&1; then SHA="shasum -a 256" else die "need sha256sum or shasum to verify the download."; fi command -v curl >/dev/null 2>&1 || die "need curl." TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT INT TERM say "downloading ${FILE} ${VERSION}" curl -fsSL -o "$TMP/$FILE" "$BASE/$FILE" curl -fsSL -o "$TMP/SHA256SUMS" "$BASE/SHA256SUMS" GOT=$(cd "$TMP" && $SHA "$FILE" | awk '{print $1}') LISTED=$(awk -v f="$FILE" '$2==f {print $1}' "$TMP/SHA256SUMS") [ -n "$LISTED" ] || die "${FILE} is not listed in SHA256SUMS." [ "$GOT" = "$LISTED" ] || die "checksum mismatch against SHA256SUMS (got $GOT). Not installed." [ "$GOT" = "$PINNED" ] || die "checksum mismatch against the checksum pinned in this script (got $GOT). Not installed." say "sha256 ok: $GOT" DIR="${CHLIFT_INSTALL_DIR:-}" if [ -z "$DIR" ]; then if [ -w /usr/local/bin ]; then DIR=/usr/local/bin; else DIR="$HOME/.local/bin"; fi fi mkdir -p "$DIR" chmod 0755 "$TMP/$FILE" mv "$TMP/$FILE" "$DIR/chlift" say "installed $DIR/chlift" case ":$PATH:" in *":$DIR:"*) ;; *) say "add $DIR to your PATH" ;; esac say "next: chlift init --cluster --host ... (see https://chlift.deemwar.com/#install)"