#!/bin/sh # Install tunzip from GitHub Releases (served at https://tun.zip/install.sh). # # Usage: # curl -fsSL https://tun.zip/install.sh | sh # TUNZIP_VERSION=0.1.0 curl -fsSL https://tun.zip/install.sh | sh # # Environment: # TUNZIP_VERSION Version to install (e.g. 0.1.0 or v0.1.0; default: latest) # TUNZIP_INSTALL_DIR Destination directory (default: ~/.local/bin) # TUNZIP_REPO GitHub repo slug (default: BaseDatum/tunzip) # TUNZIP_MINISIGN_PUBKEY Override embedded minisign public key set -eu REPO="${TUNZIP_REPO:-BaseDatum/tunzip}" INSTALL_DIR="${TUNZIP_INSTALL_DIR:-${HOME}/.local/bin}" # Embedded minisign public key (RW...) for BaseDatum/tunzip releases. # Populate this value once the production release signing keypair is provisioned. EMBEDDED_MINISIGN_PUBKEY="RWR+wcIcy/XydbJUwRjiS5LwQIalC+as4l4FWqBqQaHnrxvcgP0QSVwh" MINISIGN_PUBKEY="${TUNZIP_MINISIGN_PUBKEY:-$EMBEDDED_MINISIGN_PUBKEY}" say() { printf '%s\n' "$*" } err() { printf 'error: %s\n' "$*" >&2 exit 1 } need_cmd() { if ! command -v "$1" >/dev/null 2>&1; then err "required command not found: $1" fi } fetch_to_file() { _url="$1" _out="$2" if command -v curl >/dev/null 2>&1; then curl -fsSL --retry 3 --proto '=https' --tlsv1.2 -o "$_out" "$_url" elif command -v wget >/dev/null 2>&1; then wget -qO "$_out" "$_url" else err "curl or wget is required to download tunzip" fi } fetch_stdout() { _url="$1" if command -v curl >/dev/null 2>&1; then curl -fsSL --retry 3 --proto '=https' --tlsv1.2 "$_url" elif command -v wget >/dev/null 2>&1; then wget -qO- "$_url" else err "curl or wget is required to download tunzip" fi } detect_target() { _os="$(uname -s)" _arch="$(uname -m)" case "$_os" in Darwin) if [ "$_arch" = "x86_64" ]; then if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || printf '0')" = "1" ]; then _arch="arm64" fi fi case "$_arch" in arm64|aarch64) printf 'aarch64-apple-darwin' ;; x86_64|amd64) printf 'x86_64-apple-darwin' ;; *) err "unsupported macOS architecture: $_arch" ;; esac ;; Linux) case "$_arch" in x86_64|amd64) printf 'x86_64-unknown-linux-musl' ;; aarch64|arm64) printf 'aarch64-unknown-linux-musl' ;; *) err "unsupported Linux architecture: $_arch" ;; esac ;; MINGW*|MSYS*|CYGWIN*) err "Windows detected; run install.ps1 instead: irm https://tun.zip/install.ps1 | iex" ;; *) err "unsupported operating system: $_os" ;; esac } resolve_latest_tag() { _api_url="https://api.github.com/repos/${REPO}/releases/latest" _tag="" if _json="$(fetch_stdout "$_api_url" 2>/dev/null)"; then _tag="$(printf '%s\n' "$_json" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1)" fi if [ -z "$_tag" ] && command -v curl >/dev/null 2>&1; then _effective="$(curl -fsSL -o /dev/null -w '%{url_effective}' --proto '=https' --tlsv1.2 "https://github.com/${REPO}/releases/latest" 2>/dev/null || true)" case "$_effective" in */releases/tag/*) _tag="${_effective##*/releases/tag/}" ;; esac fi if [ -z "$_tag" ]; then err "could not determine latest release tag from https://github.com/${REPO}/releases" fi printf '%s' "$_tag" } sha256_file() { _file="$1" if command -v sha256sum >/dev/null 2>&1; then sha256sum "$_file" | awk '{print tolower($1)}' elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$_file" | awk '{print tolower($1)}' elif command -v openssl >/dev/null 2>&1; then openssl dgst -sha256 "$_file" | awk '{print tolower($NF)}' else err "no SHA-256 tool found (need sha256sum, shasum, or openssl)" fi } main() { case "${1:-}" in -h|--help) say "Install tunzip from GitHub Releases (https://github.com/${REPO}/releases)." say "Env: TUNZIP_VERSION, TUNZIP_INSTALL_DIR (default ~/.local/bin), TUNZIP_REPO, TUNZIP_MINISIGN_PUBKEY" exit 0 ;; esac need_cmd tar need_cmd awk need_cmd mktemp TARGET="$(detect_target)" if [ -n "${TUNZIP_VERSION:-}" ]; then VERSION="${TUNZIP_VERSION#v}" TAG="v${VERSION}" else TAG="$(resolve_latest_tag)" VERSION="${TAG#v}" fi ARCHIVE="tunzip-${VERSION}-${TARGET}.tar.gz" BASE_URL="https://github.com/${REPO}/releases/download/${TAG}" WORK_DIR="$(mktemp -d)" trap 'rm -rf "$WORK_DIR"' EXIT INT TERM HUP ARCHIVE_PATH="${WORK_DIR}/${ARCHIVE}" SUMS_PATH="${WORK_DIR}/SHA256SUMS" say "Downloading tunzip ${VERSION} (${TARGET})..." fetch_to_file "${BASE_URL}/${ARCHIVE}" "$ARCHIVE_PATH" fetch_to_file "${BASE_URL}/SHA256SUMS" "$SUMS_PATH" EXPECTED_SHA="$(awk -v f="$ARCHIVE" '{ name = $2; sub(/^\*/, "", name); if (name == f) { print tolower($1); exit } }' "$SUMS_PATH")" if [ -z "$EXPECTED_SHA" ]; then err "checksum for ${ARCHIVE} not found in SHA256SUMS" fi ACTUAL_SHA="$(sha256_file "$ARCHIVE_PATH")" if [ "$ACTUAL_SHA" != "$EXPECTED_SHA" ]; then err "SHA-256 mismatch for ${ARCHIVE}: expected ${EXPECTED_SHA}, got ${ACTUAL_SHA}" fi say "Verified SHA-256 checksum." if [ -n "$MINISIGN_PUBKEY" ]; then if command -v minisign >/dev/null 2>&1; then SIG_PATH="${WORK_DIR}/${ARCHIVE}.minisig" if fetch_to_file "${BASE_URL}/${ARCHIVE}.minisig" "$SIG_PATH" 2>/dev/null; then minisign -Vq -P "$MINISIGN_PUBKEY" -m "$ARCHIVE_PATH" -x "$SIG_PATH" \ || err "minisign signature verification failed for ${ARCHIVE}" say "Verified minisign signature." else err "could not download ${ARCHIVE}.minisig for signature verification" fi else say "Note: install minisign to also verify release signatures." fi fi UNPACK_DIR="${WORK_DIR}/unpack" mkdir -p "$UNPACK_DIR" tar -xzf "$ARCHIVE_PATH" -C "$UNPACK_DIR" BIN_SRC="${UNPACK_DIR}/tunzip-${VERSION}-${TARGET}/tunzip" if [ ! -f "$BIN_SRC" ]; then BIN_SRC="${UNPACK_DIR}/tunzip" fi if [ ! -f "$BIN_SRC" ]; then err "tunzip binary not found inside ${ARCHIVE}" fi mkdir -p "$INSTALL_DIR" TMP_BIN="${INSTALL_DIR}/.tunzip.tmp.$$" cp "$BIN_SRC" "$TMP_BIN" chmod 0755 "$TMP_BIN" mv -f "$TMP_BIN" "${INSTALL_DIR}/tunzip" say "" say "Installed tunzip ${VERSION} to ${INSTALL_DIR}/tunzip" case ":${PATH:-}:" in *":${INSTALL_DIR}:"*) ;; *) say "" say "Add ${INSTALL_DIR} to your PATH:" say " export PATH=\"${INSTALL_DIR}:\$PATH\"" ;; esac say "" say "Next steps:" say " tunzip init" say " tunzip share 3000" say "" say "MCP setup (Claude Code):" say " claude mcp add tunzip -- tunzip mcp" say "" say "MCP config snippet (Cursor / Codex / stdio clients):" say ' {"mcpServers":{"tunzip":{"command":"tunzip","args":["mcp"]}}}' } main "$@"