#!/bin/bash # ============================================================================= # GLPI agent installation module # ============================================================================= # Set script directory SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" # Source common functions and variables source "./common.sh" source "./custom/custom_glpi" # Function to install GLPI agent install_glpi_agent() { log_message "INFO" "Installing GLPI agent" # Check if GLPI agent is already installed if command_exists glpi-agent; then log_message "INFO" "GLPI agent is already installed" return 0 fi # Install dependencies # log_message "INFO" "Installing dependencies for GLPI agent" # apt-get install -y dmidecode hwdata ucf hdparm perl libuniversal-require-perl \ # libxml-treepp-perl libyaml-perl libnet-cups-perl libnet-ip-perl libwww-perl \ # libparse-edid-perl libproc-daemon-perl libfile-which-perl libhttp-daemon-perl \ # libio-socket-ssl-perl libnet-snmp-perl libcrypt-des-perl libnet-nbname-perl \ # libdigest-hmac-perl # if [ $? -ne 0 ]; then # log_message "ERROR" "Failed to install dependencies for GLPI agent" # return 1 # fi # Determine the latest GLPI agent version and download URL for Debian/Ubuntu log_message "INFO" "Determining latest GLPI agent version" # Determine system architecture ARCH=$(dpkg --print-architecture) # URL URL="https://github.com/glpi-project/glpi-agent/releases" # latest version LATEST_VERSION=$(curl -s "$URL" | grep -oP '(?<=/glpi-project/glpi-agent/releases/tag/)[^"]*' | head -1) # check if [ -z "$LATEST_VERSION" ]; then log_message "ERROR" "Failed to version GLPI agent" fi # Prepare GLPI agent installation TEMP_DIR=$(mktemp -d) cd "$TEMP_DIR" || return 1 # Download the latest GLPI agent package DOWNLOAD_URL="https://github.com/glpi-project/glpi-agent/releases/download/$LATEST_VERSION/glpi-agent-$LATEST_VERSION-linux-installer.pl" log_message "INFO" "Downloading GLPI agent from $DOWNLOAD_URL" # wget "$DOWNLOAD_URL" -O "glpi-agent-$LATEST_VERSION.pl" if [ $? -ne 0 ]; then log_message "ERROR" "Failed to download GLPI agent" rm -rf "$TEMP_DIR" return 1 fi # Install the GLPI agent package log_message "INFO" "Installing GLPI agent package" #dpkg -i glpi-agent_$LATEST_VERSION.deb perl glpi-agent-$LATEST_VERSION-linux-installer.pl --reinstall --type=all -v >> /dev/null if [ $? -ne 0 ]; then log_message "ERROR" "Failed to install GLPI agent package" apt-get install -f -y # Try to fix broken dependencies dpkg -i glpi-agent_$LATEST_VERSION.deb if [ $? -ne 0 ]; then log_message "ERROR" "Failed to install GLPI agent package after fixing dependencies" rm -rf "$TEMP_DIR" return 1 fi fi # Cleanup cd - > /dev/null rm -rf "$TEMP_DIR" # Configure GLPI agent log_message "INFO" "Configuring GLPI agent" local glpi_conf="/etc/glpi-agent/agent.cfg" # Backup existing configuration if it exists if [ -f "$glpi_conf" ]; then backup_file "$glpi_conf" fi # Create configuration file cat > "$glpi_conf" << EOF # GLPI Agent Configuration # Generated by security hardening script # Server URL - Replace with your actual GLPI server URL server = https://"$GLPI_SERVER"/glpi/api/inventory # Disable SSL certificate validation for testing (set to 1 for production) no-ssl-check = 0 # Run as daemon (0 = no, 1 = yes) daemon = 1 # Logger configuration logger = File logfile = /var/log/glpi-agent/glpi-agent.log # Scan local network scan-homedirs = 1 scan-profiles = 1 # Inventory frequency (in hours) delaytime = 24 # Tag for the agent tag = SecuredServer EOF log_message "SUCCESS" "GLPI agent configuration created at $glpi_conf" # Create GLPI agent systemd service if not already created by package if [ ! -f "/etc/systemd/system/glpi-agent.service" ]; then log_message "INFO" "Creating GLPI agent service" cat > "/etc/systemd/system/glpi-agent.service" << EOF [Unit] Description=GLPI Agent Documentation=https://glpi-agent.readthedocs.io/ After=network.target [Service] ExecStart=/usr/bin/glpi-agent --daemon Restart=always RestartSec=60 [Install] WantedBy=multi-user.target EOF log_message "SUCCESS" "GLPI agent service created" fi # Enable and start GLPI agent service log_message "INFO" "Enabling and starting GLPI agent service" systemctl daemon-reload service enable glpi-agent service restart glpi-agent if [ $? -eq 0 ]; then log_message "SUCCESS" "GLPI agent service enabled and started" else log_message "ERROR" "Failed to enable or start GLPI agent service" return 1 fi } # log_message "SCRIPT" "glpi_agent.sh" # Main execution for GLPI agent install_glpi_agent log_message "SUCCESS" "GLPI agent installation completed"