#!/usr/bin/env bash


## available versions as of Tue  7 Oct 18:34:05 BST 2025

# https://github.com/asciinema/asciinema/releases/download/v3.0.0/asciinema-aarch64-apple-darwin
# https://github.com/asciinema/asciinema/releases/download/v3.0.0/asciinema-aarch64-unknown-linux-gnu
# https://github.com/asciinema/asciinema/releases/download/v3.0.0/asciinema-x86_64-apple-darwin
# https://github.com/asciinema/asciinema/releases/download/v3.0.0/asciinema-x86_64-unknown-linux-gnu
# https://github.com/asciinema/asciinema/releases/download/v3.0.0/asciinema-x86_64-unknown-linux-musl

VERSION="3.0.0"
LINK="https://github.com/asciinema/asciinema/releases/download/v${VERSION}/asciinema-"

unameOut="$(uname -s)"
archOut="$(uname -m)"

case "${unameOut}" in
    Linux)
        if ldd --version 2>&1 | grep -q musl; then
            platform="x86_64-unknown-linux-musl"
        else
            platform="x86_64-unknown-linux-gnu"
        fi
        if [[ "${archOut}" == "aarch64" ]]; then
            platform="aarch64-unknown-linux-gnu"
        fi
        ;;
    Darwin)
        if [[ "${archOut}" == "arm64" ]]; then
            platform="aarch64-apple-darwin"
        else
            platform="x86_64-apple-darwin"
        fi
        ;;
    *)
        echo "Unsupported platform: ${unameOut} ${archOut}"
        exit 1
        ;;
esac

echo "Detected platform: $platform"
echo "installing asciinema version ${VERSION} for ${platform}"
sudo curl -sL "${LINK}${platform}" -o /usr/local/bin/asciinema
sudo chmod +x /usr/local/bin/asciinema
asciinema --version