#!/bin/sh # Installs the latest stackalarm release. # curl -sSL https://raw.githubusercontent.com/yoanbernabeu/stackalarm/main/install.sh | sh # Set STACKALARM_VERSION (v0.1.0) to pick a version, INSTALL_DIR to pick where. set -eu repo="yoanbernabeu/stackalarm" fail() { echo "stackalarm install: $*" >&2; exit 1; } need() { command -v "$1" >/dev/null 2>&1 || fail "$1 is required"; } need curl need tar need uname case "$(uname -s)" in Linux) os=linux ;; Darwin) os=darwin ;; *) fail "unsupported system $(uname -s); on Windows, download the zip from https://github.com/$repo/releases" ;; esac case "$(uname -m)" in x86_64 | amd64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "unsupported architecture $(uname -m)" ;; esac version="${STACKALARM_VERSION:-}" if [ -z "$version" ]; then version=$(curl -fsSL "https://api.github.com/repos/$repo/releases/latest" | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' | head -n 1) [ -n "$version" ] || fail "cannot find the latest release" fi archive="stackalarm_${version#v}_${os}_${arch}.tar.gz" base="https://github.com/$repo/releases/download/$version" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT echo "Downloading stackalarm $version ($os/$arch)…" curl -fsSL "$base/$archive" -o "$tmp/$archive" || fail "download failed: $base/$archive" curl -fsSL "$base/checksums.txt" -o "$tmp/checksums.txt" || fail "cannot download checksums.txt" expected=$(grep " $archive\$" "$tmp/checksums.txt" | cut -d ' ' -f 1) [ -n "$expected" ] || fail "$archive is not listed in checksums.txt" if command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmp/$archive" | cut -d ' ' -f 1) else actual=$(shasum -a 256 "$tmp/$archive" | cut -d ' ' -f 1) fi [ "$actual" = "$expected" ] || fail "checksum mismatch for $archive" tar -xzf "$tmp/$archive" -C "$tmp" stackalarm dir="${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" install -m 0755 "$tmp/stackalarm" "$dir/stackalarm" echo "Installed $("$dir/stackalarm" --version) in $dir" case ":$PATH:" in *":$dir:"*) ;; *) echo "Add $dir to your PATH to run stackalarm." ;; esac