install.sh

1.5 KB · raw

1#!/bin/sh2# Installs the newest release of @REPO@ for this machine, checked against its SHA-256 (§22.5).3#   curl -fsSL @BASE@/install.sh | sh4# INSTALL_DIR picks the folder (default ~/.local/bin).5set -eu67repo=@REPO@8base=@BASE@/releases910fail() {11	echo "$repo: $*" >&212	exit 113}1415case "$(uname -s)" in16Linux) os=linux ;;17Darwin) os=macos ;;18*) fail "no builds for $(uname -s)" ;;19esac20case "$(uname -m)" in21x86_64 | amd64) arch=x86_64 ;;22arm64 | aarch64) arch=aarch64 ;;23*) fail "no builds for $(uname -m)" ;;24esac25platform=$os-$arch2627command -v curl >/dev/null 2>&1 || fail "installing needs curl"28if command -v sha256sum >/dev/null 2>&1; then29	sha256() { sha256sum "$1" | cut -d ' ' -f 1; }30elif command -v shasum >/dev/null 2>&1; then31	sha256() { shasum -a 256 "$1" | cut -d ' ' -f 1; }32else33	fail "installing needs sha256sum or shasum"34fi3536version=$(curl -fsSL "$base/latest/version.txt") || fail "no release found"37expected=$(curl -fsSL "$base/$version/checksums.txt" |38	awk -v name="$repo-$platform" '$2 == name && sub(/^sha256:/, "", $1) { print $1 }')39[ -n "$expected" ] || fail "$version has no build for $platform"4041dir=${INSTALL_DIR:-$HOME/.local/bin}42mkdir -p "$dir"43tmp=$(mktemp "$dir/.$repo.XXXXXX")44trap 'rm -f "$tmp"' EXIT45curl -fsSL -o "$tmp" "$base/latest/$platform" || fail "download failed"46[ "$(sha256 "$tmp")" = "$expected" ] || fail "checksum mismatch; nothing installed"47chmod 755 "$tmp"48mv "$tmp" "$dir/$repo"49echo "$repo $version installed to $dir/$repo"