#!/usr/bin/env bash set -euo pipefail error() { printf 'error: %s\n' "$1" >&2; exit 1; } command -v curl >/dev/null 2>&1 || error "curl is required" platform=$(uname -ms) case "$platform" in 'Darwin x86_64') target=darwin-x64 ;; 'Darwin arm64') target=darwin-arm64 ;; 'Linux aarch64' | 'Linux arm64') target=linux-arm64 ;; 'Linux x86_64') target=linux-x64 ;; *) error "unsupported platform: $platform. On Windows run: irm https://sellcodebase.com/install.ps1 | iex" ;; esac if [ "$target" = darwin-x64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || printf 0)" = 1 ]; then target=darwin-arm64 fi if [ -f /etc/alpine-release ]; then error "Alpine/musl is not supported by the prebuilt binary. Use a supported environment or see https://sellcodebase.com/llms.txt for contact information." fi github=${SELLCODEBASE_GITHUB:-https://github.com} repo="$github/Selltraces/sellcodebase-releases" asset="sellcodebase-$target" if [ "$#" -gt 0 ]; then release_base="$repo/releases/download/$1" else release_base="$repo/releases/latest/download" fi install_root=${SELLCODEBASE_INSTALL:-$HOME/.sellcodebase} [ -n "$install_root" ] && [ "$install_root" != / ] || error "refusing unsafe install directory" bin_dir="$install_root/bin" exe="$bin_dir/sellcodebase" tmp_dir=$(mktemp -d) trap 'rm -rf "$tmp_dir"' EXIT printf 'Installing SellCodebase CLI (%s)...\n' "$target" curl --fail --location --progress-bar --output "$tmp_dir/$asset" "$release_base/$asset" \ || error "could not download $asset" curl --fail --location --silent --show-error --output "$tmp_dir/SHA256SUMS" "$release_base/SHA256SUMS" \ || error "could not download release checksums" expected=$(awk -v asset="$asset" '$2 == asset { print $1 }' "$tmp_dir/SHA256SUMS") [ -n "$expected" ] || error "release checksum is missing for $asset" if command -v shasum >/dev/null 2>&1; then actual=$(shasum -a 256 "$tmp_dir/$asset" | awk '{ print $1 }') elif command -v sha256sum >/dev/null 2>&1; then actual=$(sha256sum "$tmp_dir/$asset" | awk '{ print $1 }') else error "shasum or sha256sum is required to verify the download" fi [ "$actual" = "$expected" ] || error "checksum verification failed" mkdir -p "$bin_dir" chmod +x "$tmp_dir/$asset" mv "$tmp_dir/$asset" "$exe" case ":$PATH:" in *":$bin_dir:"*) path_ready=1 ;; *) path_ready=0 ;; esac if [ "$path_ready" = 0 ]; then shell_name=$(basename "${SHELL:-}") rc="" path_line="" case "$shell_name" in zsh) rc="$HOME/.zshrc" ;; bash) rc="$HOME/.bashrc" ;; fish) rc="$HOME/.config/fish/config.fish" ;; esac if [ "$shell_name" = fish ]; then path_line="fish_add_path $bin_dir" else path_line="export PATH=\"$bin_dir:\$PATH\"" fi if [ -n "$rc" ]; then mkdir -p "$(dirname "$rc")" if ! { [ -f "$rc" ] && grep -qF "$bin_dir" "$rc"; }; then { printf '\n# SellCodebase CLI\n'; printf '%s\n' "$path_line"; } >> "$rc" fi fi fi printf '\nSellCodebase CLI installed and checksum verified.\n' printf ' Location: %s\n' "$exe" if [ "$path_ready" = 1 ]; then printf ' Next: sellcodebase .\n' else printf ' Next: PATH="%s:$PATH" sellcodebase .\n' "$bin_dir" [ -z "${rc:-}" ] || printf ' Future terminals: restart your shell or load %s\n' "$rc" fi printf '\nUpdate later by running the same install command:\n' printf ' curl -fsSL https://sellcodebase.com/install | bash\n'