#!/bin/bash # Drift CLI Installer - Hosted on godrift.ai # This script installs the latest Drift CLI from GitHub releases set -e # Configuration REPO="drift-tech/drift-releases" # Change to your GitHub username/repo CLI_NAME="drift" GITHUB_API="https://api.github.com/repos/\${REPO}/releases/latest" 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 unique session ID for this installation INSTALL_SESSION_ID="install_\$(date +%s%N)_\$RANDOM" # Function to track analytics events (non-blocking, silent) track_event() { local event_name="\$1" local success="\$2" local error_msg="\$3" local payload="" if [ -n "\$success" ] && [ -n "\$error_msg" ]; then payload="{\\"action\\": \\"track\\", \\"distinct_id\\": \\"\$INSTALL_SESSION_ID\\", \\"event\\": \\"\$event_name\\", \\"properties\\": {\\"os\\": \\"Linux\\", \\"arch\\": \\"\${ARCH_DEB:-unknown}\\", \\"version\\": \\"\${VERSION:-unknown}\\", \\"success\\": \$success, \\"error\\": \\"\$error_msg\\"}}" elif [ -n "\$success" ]; then payload="{\\"action\\": \\"track\\", \\"distinct_id\\": \\"\$INSTALL_SESSION_ID\\", \\"event\\": \\"\$event_name\\", \\"properties\\": {\\"os\\": \\"Linux\\", \\"arch\\": \\"\${ARCH_DEB:-unknown}\\", \\"version\\": \\"\${VERSION:-unknown}\\", \\"success\\": \$success}}" else payload="{\\"action\\": \\"track\\", \\"distinct_id\\": \\"\$INSTALL_SESSION_ID\\", \\"event\\": \\"\$event_name\\", \\"properties\\": {\\"os\\": \\"Linux\\", \\"arch\\": \\"\${ARCH_DEB:-unknown}\\", \\"version\\": \\"\${VERSION:-unknown}\\"}}" fi # 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" ;; aarch64|arm64) ARCH_DEB="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 # Get latest release from GitHub echo "Fetching latest version..." if command -v curl >/dev/null 2>&1; then RELEASE_DATA=\$(curl -s "\$GITHUB_API") else RELEASE_DATA=\$(wget -qO- "\$GITHUB_API") fi # Parse version VERSION=\$(echo "\$RELEASE_DATA" | grep -oP '"tag_name": "\\K[^"]*' | head -1) if [ -z "\$VERSION" ]; then echo -e "\${RED}Error: Could not fetch latest version\${NC}" echo "Please check: https://github.com/\$REPO/releases" track_event "install_incomplete" "false" "version_fetch_failed" exit 1 fi echo "Latest version: \$VERSION" # Find the correct .deb file URL DEB_URL=\$(echo "\$RELEASE_DATA" | grep -oP '"browser_download_url": "\\K[^"]*\\.deb' | grep "\$ARCH_DEB" | head -1) if [ -z "\$DEB_URL" ]; then echo -e "\${RED}Error: No .deb package found for \$ARCH_DEB\${NC}" echo "Available releases: https://github.com/\$REPO/releases" track_event "install_incomplete" "false" "no_deb_package" exit 1 fi # Download the .deb package echo "Downloading Drift CLI \$VERSION..." TMP_DEB="/tmp/drift_\${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 immediately!\${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