#!/bin/bash # Drift CLI Installer - Hosted on godrift.ai # Download URLs are resolved server-side to avoid GitHub API rate limits set -e # Pre-resolved release info (injected by Cloud Function) RELEASE_VERSION="1.0.20" DEB_URL_AMD64="https://github.com/godrift-ai/drift-releases/releases/download/1.0.20/drift-cli_1.0.20_amd64.deb" DEB_URL_ARM64="" ANALYTICS_ENDPOINT="https://analytics-service-267976266267.us-central1.run.app" # Colors GREEN='\033[0;32m' YELLOW='\033[1;33m' RED='\033[0;31m' NC='\033[0m' # Generate or read persistent device ID (same file the CLI uses: ~/.drift/user_id) # This ensures install events are stitched to the same user in Mixpanel DRIFT_DIR="$HOME/.drift" DEVICE_ID_FILE="$DRIFT_DIR/user_id" if [ -f "$DEVICE_ID_FILE" ] && [ -s "$DEVICE_ID_FILE" ]; then DEVICE_ID=$(cat "$DEVICE_ID_FILE") else mkdir -p "$DRIFT_DIR" DEVICE_ID=$(cat /proc/sys/kernel/random/uuid 2>/dev/null || python3 -c "import uuid; print(uuid.uuid4())" 2>/dev/null || echo "install_$(date +%s%N)_$RANDOM") echo -n "$DEVICE_ID" > "$DEVICE_ID_FILE" fi # Function to track analytics events (non-blocking, silent) # Uses Mixpanel Simplified ID Merge: $device_id in properties, empty distinct_id track_event() { local event_name="$1" local success="$2" local error_msg="$3" local extra_props="" if [ -n "$success" ] && [ -n "$error_msg" ]; then extra_props=", \"success\": $success, \"error\": \"$error_msg\"" elif [ -n "$success" ]; then extra_props=", \"success\": $success" fi local payload="{\"action\": \"track\", \"distinct_id\": \"\", \"event\": \"$event_name\", \"properties\": {\"\$device_id\": \"$DEVICE_ID\", \"os\": \"Linux\", \"arch\": \"${ARCH_DEB:-unknown}\", \"version\": \"${RELEASE_VERSION:-unknown}\"$extra_props}}" # Send to analytics endpoint (fire and forget) (curl -s -X POST "$ANALYTICS_ENDPOINT" \ -H "Content-Type: application/json" \ -d "$payload" \ >/dev/null 2>&1) & } # ASCII Art echo "" echo " ╔══════════════════════════════════════╗" echo " ║ DRIFT CLI INSTALLER ║" echo " ║ AI Copilot for Simulations ║" echo " ║ godrift.ai ║" echo " ╚══════════════════════════════════════╝" echo "" echo "Installing Drift CLI..." # Track installation started track_event "install_started" "" "" # Check if Linux if [ "$(uname)" != "Linux" ]; then echo -e "${RED}Error: This installer is only for Linux systems${NC}" echo "For other platforms, visit: https://godrift.ai" track_event "install_incomplete" "false" "not_linux" exit 1 fi # Detect architecture ARCH=$(uname -m) case $ARCH in x86_64) ARCH_DEB="amd64" DEB_URL="$DEB_URL_AMD64" ;; aarch64|arm64) ARCH_DEB="arm64" DEB_URL="$DEB_URL_ARM64" ;; *) echo -e "${RED}Error: Unsupported architecture: $ARCH${NC}" echo "Supported: x64, arm64" track_event "install_incomplete" "false" "unsupported_arch" exit 1 ;; esac echo "Detected: Linux $ARCH_DEB" # Check for curl or wget if command -v curl >/dev/null 2>&1; then DOWNLOAD_CMD="curl -fsSL" DOWNLOAD_OUTPUT="-o" elif command -v wget >/dev/null 2>&1; then DOWNLOAD_CMD="wget -q" DOWNLOAD_OUTPUT="-O" else echo -e "${RED}Error: curl or wget is required${NC}" echo "Install with: sudo apt-get install curl" track_event "install_incomplete" "false" "no_curl_wget" exit 1 fi # Check that we have a download URL for this architecture if [ -z "$DEB_URL" ]; then echo -e "${RED}Error: No .deb package available for $ARCH_DEB${NC}" echo "Available releases: https://github.com/godrift-ai/drift-releases/releases" track_event "install_incomplete" "false" "no_deb_package" exit 1 fi echo "Latest version: $RELEASE_VERSION" # Download the .deb package echo "Downloading Drift CLI $RELEASE_VERSION..." TMP_DEB="/tmp/drift_${RELEASE_VERSION}_${ARCH_DEB}.deb" $DOWNLOAD_CMD "$DEB_URL" $DOWNLOAD_OUTPUT "$TMP_DEB" if [ ! -f "$TMP_DEB" ]; then echo -e "${RED}Error: Download failed${NC}" track_event "install_incomplete" "false" "download_failed" exit 1 fi # Install the package echo "Installing package..." if command -v dpkg >/dev/null 2>&1; then # Debian/Ubuntu sudo dpkg -i "$TMP_DEB" 2>/dev/null || { echo "Installing dependencies..." sudo apt-get update >/dev/null 2>&1 sudo apt-get install -f -y >/dev/null 2>&1 sudo dpkg -i "$TMP_DEB" } elif command -v apt >/dev/null 2>&1; then # Modern Debian/Ubuntu sudo apt install "$TMP_DEB" -y else echo -e "${RED}Error: No supported package manager found${NC}" echo "Manual installation required: sudo dpkg -i $TMP_DEB" track_event "install_incomplete" "false" "no_package_manager" exit 1 fi # Cleanup rm -f "$TMP_DEB" # Refresh shell command cache hash -r 2>/dev/null || true # Verify installation if command -v drift >/dev/null 2>&1; then INSTALLED_VERSION=$(drift --version 2>/dev/null || echo "unknown") echo "" echo -e "${GREEN}╔════════════════════════════════════════╗${NC}" echo -e "${GREEN}║ Drift CLI installed successfully! ║${NC}" echo -e "${GREEN}╚════════════════════════════════════════╝${NC}" echo "" echo "Version: $INSTALLED_VERSION" echo "Location: $(which drift)" echo "" echo -e "${GREEN}Drift is ready to use!${NC}" echo "" echo "Get started with:" echo " drift --help Show help" echo " drift Start interactive mode" echo "" # Track successful installation track_event "install_completed" "true" "" else echo -e "${YELLOW}Drift installed but not detected in current shell${NC}" echo "" echo "To use drift in this terminal session, run one of:" echo -e " ${GREEN}hash -r${NC} (refresh command cache)" echo -e " ${GREEN}exec \$SHELL${NC} (restart shell)" echo -e " ${GREEN}source ~/.bashrc${NC} (reload shell config)" echo "" echo "Or simply open a new terminal - drift will work automatically!" echo "" # Track installation (success but not detected in shell) track_event "install_completed" "true" "not_in_path" fi