#!/bin/bash set -e # InfraIQ Installer # Usage: curl -sSL https://install.autonops.io | bash VERSION="${INFRAIQ_VERSION:-latest}" INSTALL_DIR="${INFRAIQ_INSTALL_DIR:-$HOME/.local/bin}" INFRAIQ_HOME="${INFRAIQ_HOME:-$HOME/.infraiq}" # Colors RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color info() { echo -e "${BLUE}[INFO]${NC} $1"; } success() { echo -e "${GREEN}[OK]${NC} $1"; } warn() { echo -e "${YELLOW}[WARN]${NC} $1"; } error() { echo -e "${RED}[ERROR]${NC} $1"; exit 1; } # Detect OS and architecture detect_platform() { OS="$(uname -s)" ARCH="$(uname -m)" case "$OS" in Linux*) OS="linux" ;; Darwin*) OS="darwin" ;; *) error "Unsupported OS: $OS" ;; esac case "$ARCH" in x86_64) ARCH="amd64" ;; aarch64) ARCH="arm64" ;; arm64) ARCH="arm64" ;; *) error "Unsupported architecture: $ARCH" ;; esac PLATFORM="${OS}-${ARCH}" info "Detected platform: $PLATFORM" } # Get latest version from GitHub get_latest_version() { if [ "$VERSION" = "latest" ]; then VERSION=$(curl -sL "https://api.github.com/repos/autonops/infraIQ/releases/latest" | grep '"tag_name"' | sed -E 's/.*"v([^"]+)".*/\1/') if [ -z "$VERSION" ]; then error "Failed to fetch latest version" fi fi info "Installing version: $VERSION" } # Check for Python check_python() { if command -v python3 &> /dev/null; then PYTHON_VERSION=$(python3 --version 2>&1 | cut -d' ' -f2) PYTHON_MAJOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f1) PYTHON_MINOR=$(echo "$PYTHON_VERSION" | cut -d'.' -f2) if [ "$PYTHON_MAJOR" -ge 3 ] && [ "$PYTHON_MINOR" -ge 9 ]; then success "Python $PYTHON_VERSION found" return 0 fi fi error "Python 3.9+ is required. Please install Python first." } # Install InfraIQ via pip install_infraiq() { info "Installing InfraIQ..." # Create install directory mkdir -p "$INSTALL_DIR" mkdir -p "$INFRAIQ_HOME" # Install via pipx if available, otherwise pip if command -v pipx &> /dev/null; then pipx install "infraiq==$VERSION" || pipx install git+https://github.com/autonops/infraIQ.git@v$VERSION else pip3 install --user "infraiq==$VERSION" 2>/dev/null || \ pip3 install --user git+https://github.com/autonops/infraIQ.git@v$VERSION fi success "InfraIQ installed" } # Download and install wraith-daemon install_daemon() { info "Installing wraith-daemon..." DAEMON_URL="https://github.com/autonops/wraith/releases/latest/download/wraith-daemon-${PLATFORM}" DAEMON_PATH="$INSTALL_DIR/wraith-daemon" if curl -fsSL "$DAEMON_URL" -o "$DAEMON_PATH" 2>/dev/null; then chmod +x "$DAEMON_PATH" success "wraith-daemon installed to $DAEMON_PATH" else warn "Could not download wraith-daemon binary. Telemetry will be disabled." warn "This is optional and does not affect InfraIQ functionality." fi } # Setup shell PATH setup_path() { # Add to PATH if not already there case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) info "Adding $INSTALL_DIR to PATH..." SHELL_NAME="$(basename "$SHELL")" case "$SHELL_NAME" in bash) PROFILE="$HOME/.bashrc" ;; zsh) PROFILE="$HOME/.zshrc" ;; *) PROFILE="$HOME/.profile" ;; esac echo "" >> "$PROFILE" echo "# InfraIQ" >> "$PROFILE" echo "export PATH=\"$INSTALL_DIR:\$PATH\"" >> "$PROFILE" success "Added to $PROFILE" warn "Run 'source $PROFILE' or restart your shell" ;; esac } # Verify installation verify_installation() { info "Verifying installation..." # Check if infraiq command exists if command -v infraiq &> /dev/null; then INSTALLED_VERSION=$(infraiq --version 2>&1 | head -1) success "InfraIQ installed: $INSTALLED_VERSION" elif [ -f "$INSTALL_DIR/infraiq" ]; then success "InfraIQ installed to $INSTALL_DIR/infraiq" warn "You may need to restart your shell or run: export PATH=\"$INSTALL_DIR:\$PATH\"" else # Try Python module if python3 -c "import cli.main" 2>/dev/null; then success "InfraIQ installed as Python module" info "Run with: python3 -m cli.main" else error "Installation verification failed" fi fi } # Print success message print_success() { echo "" echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${GREEN} InfraIQ installed successfully!${NC}" echo -e "${GREEN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo "" echo " Quick start:" echo " infraiq --help # Show all commands" echo " infraiq doctor # Check system status" echo " infraiq info # Show tool status" echo "" echo " Documentation:" echo " https://github.com/autonops/infraIQ" echo "" echo " Telemetry:" echo " Anonymous usage data helps improve InfraIQ." echo " Opt-out: export INFRAIQ_TELEMETRY=false" echo "" } # Main main() { echo "" echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${BLUE} InfraIQ Installer${NC}" echo -e "${BLUE}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo "" detect_platform get_latest_version check_python install_infraiq install_daemon setup_path verify_installation print_success } main "$@"