minor changes

This commit is contained in:
allan 2025-05-28 14:10:26 +02:00
parent e6e9d86139
commit 47d8d4d9b7

View File

@ -12,12 +12,11 @@ if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo
# Are we in the right directory
#
scriptdir="zabbix-install" && whereami=$(pwd |awk -F'/' '{print $NF}')
if [ $whereami != $scriptdir ]; then printf "\nWrong directory! Script must be run from $scriptdir\n\n" ; exit ; fi
if [ "$whereami" != "$scriptdir" ]; then printf "\nWrong directory! Script must be run from %s\n\n" "$scriptdir"; exit 1; fi
#
# Define variables and functions
#
red='\033[0;31m' ; bred='\033[1;31m' ; green='\033[0;92m' ; blue='\033[0;36m' ; bold='\033[1m' ; normal='\033[0m'
line (){ for i in {1..50}; do echo -n "$1"; done && printf "\n"; }
line () { printf -- '-%.0s' {1..50}; printf '\n'; }
version=$(tail -1 version)
ubuntuversion=$(lsb_release -rs |tail -1)
downloadurl="https://repo.zabbix.com/zabbix/$version/ubuntu/pool/main/z/zabbix-release/"
@ -31,24 +30,24 @@ title () { printf "\nZabbix install script V1.0\n\n"; }
# Function usage
#
usage () { clear ; printf -- "\n"
printf -- "${bold}zabbixinstall${normal} \n\n"
printf -- "${bold}Usage:${normal} \n"
printf -- "zabbixinstall \n\n"
printf -- "Usage: \n"
printf -- "./zabbixinstall [-n] <zabbix domain> \n"
printf -- " [-p] <zabbix database password> \n"
printf -- " [-help] <this screen> \n\n"
printf -- "${bold}Examples:${normal} \n"
printf -- "Examples: \n"
printf -- "./zabbixinstall -n zabbix.something.xyz -p zabbixdatabsepwd\n\n"; }
#
# Function installation check for success
#
serviceno () { printf "\n$service is not running cannot continue...\n\n"; }
serviceno () { printf "\n%s" $service ; printf " is not running cannot continue...\n\n"; }
servicedead () { status=$(systemctl is-active $service); if [[ "$status" != "active" ]]; then serviceno ; exit; fi; }
#
# Function to check if a service is already running or not
#
inputcheck () {
if [[ -z "$hostname" ]]; then usage ; printf "${bold}Error! ${normal}Hostname Empty...\n\n" ; exit; fi
if [[ -z "$zabbixpwd" ]]; then usage ; printf "${bold}Error! ${normal}Database Password Empty...\n\n" ; exit; fi; }
if [[ -z "$hostname" ]]; then usage ; printf "Error! Hostname Empty...\n\n" ; exit; fi
if [[ -z "$zabbixpwd" ]]; then usage ; printf "Error! Database Password Empty...\n\n" ; exit; fi; }
#
# If Nginx and MariaDB is not running then die
#
@ -60,7 +59,9 @@ clear ; title
#
# Configure command line options
#
if [[ ! $@ =~ ^\-.+ ]]; then usage; fi
# Removed due to SC2199 and not really needed start
# if [[ ! $@ =~ ^\-.+ ]]; then usage; fi
# Removed due to SC2199 and not really needed stop
while getopts "n:p:h:" option; do
case $option in
@ -75,13 +76,13 @@ while getopts "n:p:h:" option; do
usage ; exit;;
\?) # invalid option
printf "Type $0 -help for help\n\n" ; exit;;
printf "\nType sudo " ; printf "%s" "$0" ; printf " -help for help\n\n" ; exit;;
esac
done
#
# Check if input conditions are met
#
inputcheck $hostname $zabbixpwd
inputcheck "$hostname" "$zabbixpwd"
#
# Install the Zabbix repository
#
@ -126,9 +127,9 @@ mysql < notrustsql.sql
#
# Configure Nxinx
#
curl --silent https://git.x-files.dk/ubuntu-web-server/nginx-install/raw/branch/main/cfg-apps/zabbix.80.conf > /etc/nginx/conf.d/$hostname.conf
curl --silent https://git.x-files.dk/ubuntu-web-server/nginx-install/raw/branch/main/cfg-apps/zabbix.80.conf > /etc/nginx/conf.d/"$hostname".conf
sed -i "s/# DBPassword=/DBPassword=$zabbixpwd/" /etc/zabbix/zabbix_server.conf
sed -i "s/DOMAIN/$hostname/" /etc/nginx/conf.d/$hostname.conf
sed -i "s/DOMAIN/$hostname/" /etc/nginx/conf.d/"$hostname.conf"
rm /etc/nginx/conf.d/zabbix.conf
#
# Enable and start Zabbix