logic changes

This commit is contained in:
2025-10-31 09:02:28 +01:00
parent f89936a0fb
commit c8d52e2ee3

View File

@@ -10,10 +10,33 @@
# #
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit 1 ; fi if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit 1 ; fi
#
# Get php-fpm version
#
phpfpm=$(systemctl list-unit-files --type=service | awk '/php[0-9]+\.[0-9]+-fpm/ {sub(".service",""); print; exit}')
if [[ -z "$phpfpm" ]]; then printf "\nUnable to detect php-fpm version. Is PHP-FPM installed?\n\n" ; exit 1 ; fi
#
# Check if required services are running or not
#
for svc in nginx mariadb "$phpfpm"; do systemctl is-active --quiet "$svc" || { printf "\n%s is not running, cannot continue...\n\n" "${svc^}" ; exit 1 ; }; done
#
# Check MariaDB authentication method (socket or not)
#
if mysql -u root -e ";" 2>/dev/null; then
socket="SOCKET DETECTED — no need for -a or -m"
socketusage="SOCKET DETECTED — this flag is not needed"
socketauth="yes"
else
socket="NO SOCKET DETECTED — you must use -a and -m"
socketusage="NO SOCKET DETECTED — these flags are required"
socketauth="no"
fi
# #
# Define variables and functions # Define variables and functions
# #
phpver=$(php -r 'echo PHP_MAJOR_VERSION.".".PHP_MINOR_VERSION;' 2>/dev/null || echo "8.3") ; phpfpm="php$phpver-fpm"
ubuntuversion="24.04" ubuntuversion="24.04"
fallbackversion="7.0" fallbackversion="7.0"
@@ -34,38 +57,17 @@ usage () {
printf -- " sudo ./zabbixinstall -n zabbix.something.xyz -p zabbixdbpwd -a admin -m adminpwd\n\n" printf -- " sudo ./zabbixinstall -n zabbix.something.xyz -p zabbixdbpwd -a admin -m adminpwd\n\n"
} }
#
# Function to check if a service is already running or not
#
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 1 ; fi; }
# #
# Function inputcheck # Function inputcheck
# #
inputcheck () { inputcheck () {
[[ -z "$hostname" ]] && { usage; echo ""; echo "Error! Hostname empty."; echo ""; exit 1; } [[ -z "$hostname" ]] && { usage; echo ""; echo "Error! Hostname empty."; echo ""; exit 1; }
[[ "$hostname" =~ [[:space:]/] ]] && { echo "ERROR: DOMAIN INVALID (no spaces or slashes allowed)"; exit 1; }
[[ -z "$dbname" ]] && { usage; echo ""; echo "Error! Database name empty."; echo ""; exit 1; }
[[ -z "$dbuser" ]] && { usage; echo ""; echo "Error! Database user empty."; echo ""; exit 1; }
[[ -z "$dbpass" ]] && { usage; echo ""; echo "Error! Database password empty."; echo ""; exit 1; } [[ -z "$dbpass" ]] && { usage; echo ""; echo "Error! Database password empty."; echo ""; exit 1; }
} }
#
# If Nginx and MariaDB is not running then die
#
service="mariadb" ; servicedead ; service="nginx" ; servicedead
#
# Check MariaDB authentication method (socket or not)
#
if mysql -u root -e ";" 2>/dev/null; then
socket="SOCKET DETECTED — no need for -a or -m"
socketusage="SOCKET DETECTED — this flag is not needed"
socketauth="yes"
else
socket="NO SOCKET DETECTED — you must use -a and -m"
socketusage="NO SOCKET DETECTED — these flags are required"
socketauth="no"
fi
# #
# Let's go # Let's go
# #
@@ -199,7 +201,7 @@ esac
# #
cp "$nginxsnippets/hostfiles/zabbix.80.conf" /etc/nginx/conf.d/"$hostname".conf cp "$nginxsnippets/hostfiles/zabbix.80.conf" /etc/nginx/conf.d/"$hostname".conf
sed -i "s/^# DBPassword=.*/DBPassword=$dbpass/" /etc/zabbix/zabbix_server.conf sed -i "s/^# DBPassword=.*/DBPassword=$dbpass/" /etc/zabbix/zabbix_server.conf
sed -i "s/DOMAIN/$hostname/" /etc/nginx/conf.d/"$hostname".conf sed -i -- "s/DOMAIN/$hostname/g" /etc/nginx/conf.d/"$hostname".conf
rm -f /etc/nginx/conf.d/zabbix.conf rm -f /etc/nginx/conf.d/zabbix.conf
# #
@@ -207,7 +209,8 @@ rm -f /etc/nginx/conf.d/zabbix.conf
# #
systemctl enable zabbix-server zabbix-agent systemctl enable zabbix-server zabbix-agent
systemctl restart zabbix-server zabbix-agent systemctl restart zabbix-server zabbix-agent
systemctl restart "$phpfpm" && systemctl restart nginx systemctl restart "$phpfpm"
systemctl restart nginx
# #
# Zabbix postinstall notice # Zabbix postinstall notice