#!/usr/bin/env bash # # Rebate CLI installer. # # curl -fsSL https://rebates.ai/install | bash # # Pin a specific release by passing its tag: # # curl -fsSL https://rebates.ai/install | bash -s -- @selltraces/rebate-cli@0.1.0 # # Environment overrides: # REBATE_GITHUB base host for downloads (default https://github.com) # REBATE_INSTALL install directory (default $HOME/.rebate) # set -euo pipefail error() { echo "error: $1" >&2; exit 1; } echo "Setting up Rebate..." echo "" command -v curl >/dev/null 2>&1 || error "curl is required to install rebate" 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. rebate prebuilt binaries are available for macOS and Linux on arm64/x64." ;; esac # A darwin-x64 shell running under Rosetta 2 should take the native arm64 build. if [ "$target" = darwin-x64 ] && [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || echo 0)" = 1 ]; then target=darwin-arm64 echo "Rosetta 2 detected; installing the native arm64 build instead." fi # Bun's prebuilt Linux binaries target glibc; musl (Alpine) must build from source. if [ -f /etc/alpine-release ]; then error "Alpine/musl is not supported by the prebuilt binary. Build from source instead." fi github=${REBATE_GITHUB:-https://github.com} repo="$github/Selltraces/rebate-releases" asset="rebate-$target" if [ "$#" -gt 0 ]; then uri="$repo/releases/download/$1/$asset" else uri="$repo/releases/latest/download/$asset" fi install_dir=${REBATE_INSTALL:-$HOME/.rebate} bin_dir="$install_dir/bin" exe="$bin_dir/rebate" tmp="$exe.tmp" mkdir -p "$bin_dir" trap 'rm -f "$tmp"' EXIT echo "Downloading rebate ($target)..." curl --fail --location --progress-bar --output "$tmp" "$uri" \ || error "failed to download from $uri" chmod +x "$tmp" mv "$tmp" "$exe" # Never report success for a binary nobody has seen run. curl --fail catches HTTP # errors but not a truncated or corrupt body, which still chmods and moves # cleanly, then fails at first use and looks like a broken product. "$exe" --version >/dev/null 2>&1 \ || error "the binary downloaded to $exe did not run. Delete it and re-run this installer." tildify() { if [[ "$1" = "$HOME/"* ]]; then local rest="${1#"$HOME"/}" echo "~/$rest" else echo "$1" fi } path_entry="$bin_dir" if [[ "$bin_dir" = "$HOME/"* ]]; then path_entry="\$HOME/${bin_dir#"$HOME"/}" fi path_line='export PATH="'"$path_entry"':$PATH"' current_path_command="$path_line" # Add bin_dir to PATH via the user's shell rc, unless it is already there. case ":$PATH:" in *":$bin_dir:"*) path_ready=1 ;; *) path_ready=0 ;; esac rc_updated=0 rc="" shell_name=$(basename "${SHELL:-}") if [ "$path_ready" = 0 ]; then shell_name=$(basename "${SHELL:-}") case "$shell_name" in # macOS Terminal starts bash as a LOGIN shell, which reads .bash_profile and # never .bashrc. Writing .bashrc there leaves the command missing forever. bash) if [ "$(uname -s)" = Darwin ] && [ ! -f "$HOME/.bashrc" ]; then rc="$HOME/.bash_profile" else rc="$HOME/.bashrc" fi ;; # .zshenv is read by EVERY zsh — including the non-interactive shells that # scripts, CI, and coding agents run commands in. .zshrc covers interactive # shells only, which silently hides the command from all of them. zsh) rc="$HOME/.zshenv" ;; fish) rc="$HOME/.config/fish/config.fish"; path_line="fish_add_path $bin_dir"; current_path_command="set -gx PATH $bin_dir \$PATH" ;; esac if [ -n "$rc" ]; then mkdir -p "$(dirname "$rc")" if [ ! -e "$rc" ] || [ -w "$rc" ]; then if ! { [ -f "$rc" ] && { grep -qF "$bin_dir" "$rc" || grep -qF "$path_entry" "$rc"; }; }; then { echo ""; echo "# rebate"; echo "$path_line"; } >> "$rc" rc_updated=1 fi fi fi fi echo "✔ Rebate successfully installed!" echo "" echo " Location: $(tildify "$exe")" echo "" if [ "$path_ready" = 1 ]; then echo " Next: Run rebate to get started" else echo " Next: Add Rebate to this terminal, then run rebate:" echo "" echo " $current_path_command" echo " rebate" if [ "$rc_updated" = 1 ]; then echo "" echo " Future terminals: $(tildify "$rc") was updated." elif [ -n "$rc" ]; then echo "" echo " Future terminals: add this line to $(tildify "$rc"):" echo "" echo " $path_line" fi fi echo "" echo "Installation complete!" exit 0