#!/usr/bin/env bash if [ -n "${NO_COLOR+x}" ] || [ ! -t 1 ]; then RED='' NC='' else RED='\033[0;31m' NC='\033[0m' fi # curl draws its progress bar on stderr if [ -t 1 ] && [ -t 2 ]; then CLEAR_LINE='\033[1A\033[2K' else CLEAR_LINE='' fi print_error() { echo -e "${RED}Error:${NC} ${1}" >&2 } OS="$(uname -s)" case "${OS}" in Linux*) OS="linux";; Darwin*) OS="darwin";; *) print_error "Unsupported operating system: ${OS}" exit 1 ;; esac ARCH="$(uname -m)" case "${ARCH}" in x86_64|amd64) ARCH="x64";; arm64|aarch64) ARCH="arm64";; *) print_error "Unsupported architecture: ${ARCH}" exit 1 ;; esac echo "Installing Cursor CLI 2026.12.02-8b70b6c..." # Download into the versions folder first, so the move into place is atomic TEMP_EXTRACT_DIR="$HOME/.local/share/cursor-agent/versions/.tmp-2026.12.02-8b70b6c-$(date +%s)" mkdir -p "${TEMP_EXTRACT_DIR}" DOWNLOAD_URL="https://downloads.cursor.com/lab/2026.12.02-8b70b6c/${OS}/${ARCH}/agent-cli-package.tar.gz" cleanup() { command rm -rf "${TEMP_EXTRACT_DIR}" } trap cleanup EXIT if curl -fSL --progress-bar "${DOWNLOAD_URL}" \ | tar --strip-components=1 -xzf - -C "${TEMP_EXTRACT_DIR}"; then # Clear the finished progress bar echo -ne "${CLEAR_LINE}" else print_error "Download failed. Please check your internet connection and try again." print_error "If the problem persists, the package might not be available for ${OS}/${ARCH}." cleanup exit 1 fi FINAL_DIR="$HOME/.local/share/cursor-agent/versions/2026.12.02-8b70b6c" command rm -rf "${FINAL_DIR}" if ! mv "${TEMP_EXTRACT_DIR}" "${FINAL_DIR}"; then print_error "Failed to install package. Please check permissions." cleanup exit 1 fi mkdir -p ~/.local/bin command rm -f ~/.local/bin/agent ~/.local/bin/cursor-agent # agent is the primary command; cursor-agent is the legacy name ln -s ~/.local/share/cursor-agent/versions/2026.12.02-8b70b6c/cursor-agent ~/.local/bin/agent ln -s ~/.local/share/cursor-agent/versions/2026.12.02-8b70b6c/cursor-agent ~/.local/bin/cursor-agent if [ -n "${CURSOR_CONFIG_DIR//[[:space:]]/}" ]; then AGENT_HOST_SWITCH_RECORD="${CURSOR_CONFIG_DIR}/grok-switch.json" elif [ -n "${XDG_CONFIG_HOME//[[:space:]]/}" ]; then AGENT_HOST_SWITCH_RECORD="${XDG_CONFIG_HOME}/cursor/grok-switch.json" else AGENT_HOST_SWITCH_RECORD="${HOME}/.cursor/grok-switch.json" fi if [ -e "${AGENT_HOST_SWITCH_RECORD}" ] || [ -L "${AGENT_HOST_SWITCH_RECORD}" ]; then # A record left behind is ended by the next cursor-agent start. "${HOME}/.local/bin/cursor-agent" --version >/dev/null || true fi if [[ ":${PATH}:" == *":${HOME}/.local/bin:"* ]]; then echo "Cursor CLI 2026.12.02-8b70b6c installed. Run 'agent' to get started." else case "$(basename "${SHELL:-}")" in bash) PATH_COMMAND="echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.bashrc && source ~/.bashrc" ;; zsh) PATH_COMMAND="echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ~/.zshrc && source ~/.zshrc" ;; fish) PATH_COMMAND="mkdir -p ~/.config/fish && echo 'fish_add_path \$HOME/.local/bin' >> ~/.config/fish/config.fish && source ~/.config/fish/config.fish" ;; *) PATH_COMMAND="export PATH=\"\$HOME/.local/bin:\$PATH\"" ;; esac echo "Cursor CLI 2026.12.02-8b70b6c installed. Add ~/.local/bin to your PATH, then run 'agent':" echo " ${PATH_COMMAND}" fi