Good : full update
This commit is contained in:
155
modules/glpi_agent.sh
Normal file
155
modules/glpi_agent.sh
Normal file
@@ -0,0 +1,155 @@
|
||||
#!/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"
|
||||
|
||||
# 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 libfusioninventory-agent-task-network-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)
|
||||
|
||||
# Prepare GLPI agent installation
|
||||
TEMP_DIR=$(mktemp -d)
|
||||
cd "$TEMP_DIR" || return 1
|
||||
|
||||
# Download the latest GLPI agent package
|
||||
if [ "$ARCH" = "amd64" ]; then
|
||||
DOWNLOAD_URL="https://github.com/glpi-project/glpi-agent/releases/download/1.4/glpi-agent_1.4-1_all.deb"
|
||||
else
|
||||
DOWNLOAD_URL="https://github.com/glpi-project/glpi-agent/releases/download/1.4/glpi-agent_1.4-1_all.deb"
|
||||
fi
|
||||
|
||||
log_message "INFO" "Downloading GLPI agent from $DOWNLOAD_URL"
|
||||
wget "$DOWNLOAD_URL" -O glpi-agent.deb
|
||||
|
||||
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.deb
|
||||
|
||||
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.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 = http://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 = 0
|
||||
scan-profiles = 0
|
||||
# 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
|
||||
}
|
||||
|
||||
# Main execution for GLPI agent
|
||||
install_glpi_agent
|
||||
|
||||
log_message "SUCCESS" "GLPI agent installation completed"
|
||||
Reference in New Issue
Block a user