#!/bin/bash
# =================================================================================
# CONFIGURATION
# ---------------------------------------------------------------------------------
# IMPORTANT: Replace "YOUR_CUSTOMER_KEY_HERE" with your actual Cloudamize customer key.
customerKey=Your Customer Key
# For Linux, this is the official Cloudamize installer script URL.
linuxInstallerUrl="https://am.cloudamize.com/cxf/downloadFileV3?custkey=$customerKey&filename=installCloudamizeAgentV2.sh"
# =================================================================================
# Function to install the Linux Agent
install_linux_agent() {
    echo "[*] Starting Cloudamize agent installation on Linux..."
    # Check if curl is installed
    if ! command -v curl &> /dev/null; then
        echo "[-] curl is not installed. Please install it to continue."
        exit 1
    fi
    # Set the customer key as an environment variable for the installer script.
    export CLOUDAMIZE_CUSTOMER_KEY="$customerKey"
    echo "[*] Downloading and executing installer from $linuxInstallerUrl"
    # Use curl to download and pipe to sh for execution
    # The -sSL flags mean silent, follow redirects, and fail fast
    if curl -sSL "$linuxInstallerUrl" | sh; then
        echo "[+] Linux agent installation completed successfully."
        echo "[*] No reboot is required after this installation."
        exit 0
    else
        echo "[-] Linux installation failed."
        exit 1
    fi
}
# Run the installation function
install_linux_agent