#!/bin/sh # Install the Test Icicle terminal client for Silkie and kitty. # # curl -fsSL https://testicle.goblinreactor.com/install.sh | sh # # Installs `testicle` into ~/.local/bin, or into TESTICLE_INSTALL_DIR if set. # Linux builds are static and run on any distribution; macOS builds cover # Apple Silicon and Intel. Every download is checked against the SHA-256 # digest recorded below when this installer was staged. # # scripts/stage-terminal fills in the @...@ fields; do not serve this template. # # Everything runs inside main, at the end, so a truncated download runs nothing. set -eu base=${TESTICLE_BASE_URL:-https://testicle.goblinreactor.com} say() { printf '%s\n' "$*"; } die() { printf 'testicle install: %s\n' "$*" >&2; exit 1; } platform() { os=$(uname -s) arch=$(uname -m) case "$os" in Linux) os=linux ;; Darwin) os=macos # A shell under Rosetta reports x86_64 on Apple Silicon. if [ "$(sysctl -n hw.optional.arm64 2>/dev/null || true)" = 1 ]; then arch=arm64 fi ;; *) die "there is no build for $os; play in the browser at $base/" ;; esac case "$os-$arch" in linux-x86_64 | linux-amd64) echo linux-x86_64 ;; linux-aarch64 | linux-arm64) echo linux-aarch64 ;; macos-arm64 | macos-aarch64) echo macos-arm64 ;; macos-x86_64) echo macos-x86_64 ;; *) die "there is no build for $os on $arch; play in the browser at $base/" ;; esac } digest() { case "$1" in linux-x86_64) echo 95f5745d8b76e1a7f8df6226b69d43d9501f07d1681415925f7817b45ace62e7 ;; linux-aarch64) echo 948367579b3b3149c8cace9b25c5817dbb4e664b9d07645221f1078ff3808160 ;; macos-arm64) echo 9a5e2bdafe6e8a73153f5c0f613cd4f96ee55b1347e29400c41c29f7636924e2 ;; macos-x86_64) echo d5184500ab5a7866de03656fa8feb6e2f097aa8cb7b50dd77d7ee354b2dabc27 ;; esac } sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d ' ' -f 1 elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d ' ' -f 1 else die "neither sha256sum nor shasum is available to check the download" fi } fetch() { # url file if [ -n "${TESTICLE_BASE_URL:-}" ]; then curl -fsSL "$1" -o "$2" else curl --proto '=https' --proto-redir '=https' -fsSL "$1" -o "$2" fi } main() { command -v curl >/dev/null 2>&1 || die "curl is required" command -v gzip >/dev/null 2>&1 || die "gzip is required" target=$(platform) dir=${TESTICLE_INSTALL_DIR:-$HOME/.local/bin} mkdir -p "$dir" || die "cannot create $dir" temporary=$(mktemp -d "${TMPDIR:-/tmp}/testicle.XXXXXX") trap 'rm -rf "$temporary"' EXIT trap 'exit 130' INT trap 'exit 143' TERM say "Downloading Test Icicle 1.0.0 for ${target}..." fetch "$base/terminal/testicle-$target.gz" "$temporary/testicle.gz" || die "download failed from $base/terminal/testicle-$target.gz" [ "$(sha256 "$temporary/testicle.gz")" = "$(digest "$target")" ] || die "the download's SHA-256 digest does not match; nothing was installed" gzip -dc "$temporary/testicle.gz" >"$temporary/testicle" || die "the download is not a valid gzip file" chmod 0755 "$temporary/testicle" "$temporary/testicle" --version >/dev/null 2>&1 || die "the downloaded client does not run on this system" # Replace any previous copy in one step, even while it is running. mv -f "$temporary/testicle" "$dir/testicle.new.$$" && mv -f "$dir/testicle.new.$$" "$dir/testicle" || { rm -f "$dir/testicle.new.$$"; die "cannot write $dir/testicle"; } say "Installed $dir/testicle" case ":$PATH:" in *":$dir:"*) run=testicle ;; *) run="$dir/testicle" say "" say "$dir is not on your PATH. To run plain \`testicle\`, add this to your shell profile:" say " export PATH=\"$dir:\$PATH\"" ;; esac say "" say "Open Silkie or kitty and run: $run" say "Options: --language is|en, --graphics silkie|svg|kitty, --help" } main "$@"