#!/bin/sh # Install the latest clawx release from GitHub. # # curl -fsSL https://raw.githubusercontent.com/debarshibasak/clawx/master/install.sh | sh # # Environment overrides: # CLAWX_VERSION release tag to install (default: latest release) # CLAWX_INSTALL_DIR destination directory (default: /usr/local/bin, falling # back to ~/.local/bin when /usr/local/bin is not writable) set -eu REPO="debarshibasak/clawx" BINARY="clawx" fail() { echo "error: $*" >&2 exit 1 } os=$(uname -s) case "$os" in Darwin) os=darwin ;; Linux) os=linux ;; *) fail "unsupported OS '$os' — download an archive manually from https://github.com/$REPO/releases" ;; esac arch=$(uname -m) case "$arch" in x86_64) arch=amd64 ;; arm64 | aarch64) arch=arm64 ;; *) fail "unsupported architecture '$arch'" ;; esac version=${CLAWX_VERSION:-} if [ -z "$version" ]; then version=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -n 1) [ -n "$version" ] || fail "could not resolve the latest release tag from the GitHub API" fi archive="${BINARY}_${version}_${os}_${arch}.tar.gz" base="https://github.com/$REPO/releases/download/$version" tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT echo "downloading $archive ($version)" curl -fsSL -o "$tmp/$archive" "$base/$archive" curl -fsSL -o "$tmp/checksums.txt" "$base/checksums.txt" grep " $archive\$" "$tmp/checksums.txt" >"$tmp/checksum.txt" || fail "$archive not found in checksums.txt" if command -v sha256sum >/dev/null 2>&1; then (cd "$tmp" && sha256sum -c checksum.txt >/dev/null) || fail "SHA256 verification failed for $archive" else (cd "$tmp" && shasum -a 256 -c checksum.txt >/dev/null) || fail "SHA256 verification failed for $archive" fi tar -xzf "$tmp/$archive" -C "$tmp" dest=${CLAWX_INSTALL_DIR:-} sudo="" if [ -z "$dest" ]; then if [ -w /usr/local/bin ]; then dest=/usr/local/bin elif command -v sudo >/dev/null 2>&1 && [ -t 0 ]; then dest=/usr/local/bin sudo=sudo else dest="$HOME/.local/bin" fi fi mkdir -p "$dest" 2>/dev/null || $sudo mkdir -p "$dest" $sudo install -m 0755 "$tmp/$BINARY" "$dest/$BINARY" echo "installed $BINARY $version to $dest/$BINARY" case ":$PATH:" in *":$dest:"*) ;; *) echo "warning: $dest is not on your PATH" >&2 ;; esac