Skip to content

Instantly share code, notes, and snippets.

@smithj33
Last active June 18, 2024 11:31
Show Gist options
  • Save smithj33/ecefa67b906370cb758d88fe2e808a42 to your computer and use it in GitHub Desktop.
Save smithj33/ecefa67b906370cb758d88fe2e808a42 to your computer and use it in GitHub Desktop.
This script is only for use with Ubuntu LTS 20.04 / 22.04 / 24.04, Debian 11-13 and Raspbian 9-12. It will install Zabbix Agent2 v6.4. The script will determine the correct package to download and install based on your disto, version and architecture. ***Remove references to "sudo" if you will be running this as root.
#!/bin/bash
yellow='\033[1;33m'
# Variables to determine which distro, version and arch you are using.
# As of 5/25/2024, Zabbix does not have a Raspian Bookworm version, so Debian 12 ARM version will be installed.
distro=$(cat /etc/os-release | grep -w 'ID' | cut -b 4-)
ver=$(cat /etc/os-release | grep -w VERSION_ID | cut -b 13- | sed 's/.$//')
name=$(cat /etc/os-release | grep 'VERSION_CODENAME' | cut -b 18-)
arch=$(uname -a | grep -c -F 'aarch64')
urlver=""
dpkgREL=""
rpi=""
# Determine if host is a Raspberry Pi.
rpi=$(ls /etc/default | grep "raspberrypi-kernel")
if [[ $rpi == "raspberrypi-kernel" ]]; then
rpi=true
else
rpi=false
fi
# Debian to ubuntu version conversion. Zabbix does not have debian arm packages, so we use ubuntu.
if [[ "$name" == "bullseye" ]]; then
urlver=20.04
elif [[ "$name" == "bookworm" ]]; then
urlver=22.04
elif [[ "$name" == "trixie" ]]; then
urlver=24.04
else
echo
echo -e "$yellow Your distro must be ubuntu and not debian"
echo
fi
# Zabbix url
armURL="https://repo.zabbix.com/zabbix/6.4/ubuntu-arm64/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu${urlver}_all.deb"
rpiURL="https://repo.zabbix.com/zabbix/6.4/raspbian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian${ver}_all.deb"
debURL="https://repo.zabbix.com/zabbix/6.4/debian/pool/main/z/zabbix-release/zabbix-release_6.4-1+debian${ver}_all.deb"
ubuURL="https://repo.zabbix.com/zabbix/6.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_6.4-1+ubuntu${ver}_all.deb"
# Determining which version of Zabbix Agent2 to download.
if [[ $rpi == "true" ]] && [[ $ver -lt 12 ]]; then
arch='ARM64'
echo -e "$yellow Downloading Zabbix Agent2 6.4 for RaspberryPi $distro $ver on $arch"
echo
wget $rpiURL
dpkgREL=$(echo $rpiURL | awk 'BEGIN { FS = "/" } ; { print $11 }')
elif [ $arch -eq 1 ]; then
arch='ARM64'
echo -e "$yellow Downloading Zabbix Agent2 6.4 for $distro $ver on $arch"
echo
wget $armURL
dpkgREL=$(echo $armURL | awk 'BEGIN { FS = "/" } ; { print $11 }')
elif [[ "$distro" == "debian" ]]; then
arch='x86'
echo -e "$yellow Downloading Zabbix Agent2 6.4 for $distro $ver on $arch"
echo
wget $debURL
dpkgREL=$(echo $debURL | awk 'BEGIN { FS = "/" } ; { print $11 }')
elif [[ "$distro" == "ubuntu" ]]; then
arch='x86'
echo -e"$yellow Downloading Zabbix Agent2 6.4 for $distro $ver on $arch"
echo
wget $ubuURL
dpkgREL=$(echo $ubuURL | awk 'BEGIN { FS = "/" } ; { print $11 }')
else
echo -e "$yellow Disto, version or arch not compatible with this script"
exit
fi
# Installing Zabbix Agent2.
sudo dpkg -i $dpkgREL
sudo apt update
sudo apt install zabbix-agent2 zabbix-agent2-plugin-* -y
sudo systemctl restart zabbix-agent2
sudo systemctl enable zabbix-agent2
echo
echo -e "$yellow *** Zabbix Agent2 is installed. Edit /etc/zabbix/zabbix_agent2.conf to update your Zabbix server IP. ***"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment