Enhance OS detection and package management in installation scripts: Updated install.sh to improve OS detection logic for various CentOS, AlmaLinux, CloudLinux, Ubuntu, Debian, and openEuler versions. Refined package installation commands and added error handling for unsupported OS scenarios. Improved service name mapping in install.py for better compatibility across distributions.

This commit is contained in:
Master3395
2025-09-23 23:33:05 +02:00
parent cc9a6ad31b
commit 30cb78d0ef
3 changed files with 257 additions and 106 deletions

View File

@@ -253,16 +253,30 @@ log_function_end "Set_Default_Variables"
install_package() {
local package="$1"
case "$Server_OS" in
"CentOS"|"openEuler")
if [[ "$Server_OS_Version" -ge 8 ]]; then
dnf install -y "$package"
else
"CentOS7")
yum install -y "$package"
fi
;;
"Ubuntu")
"CentOS8"|"CentOS9"|"CentOSStream8"|"CentOSStream9"|"RHEL8"|"RHEL9"|"AlmaLinux8"|"AlmaLinux9"|"AlmaLinux10"|"RockyLinux8"|"RockyLinux9")
dnf install -y "$package"
;;
"CloudLinux7"|"CloudLinux8"|"CloudLinux9")
yum install -y "$package"
;;
"Ubuntu1804"|"Ubuntu2004"|"Ubuntu2010"|"Ubuntu2204"|"Ubuntu2404"|"Ubuntu24043"|"Debian11"|"Debian12"|"Debian13")
DEBIAN_FRONTEND=noninteractive apt install -y "$package"
;;
"openEuler2003"|"openEuler2203"|"openEuler2403")
dnf install -y "$package"
;;
*)
echo -e "Unknown OS: $Server_OS, attempting package installation..."
# Try different package managers in order of likelihood
if [[ "$Server_OS" =~ ^(CentOS|RHEL|AlmaLinux|RockyLinux|CloudLinux|openEuler) ]]; then
dnf install -y "$package" 2>/dev/null || yum install -y "$package" 2>/dev/null || echo -e "Failed to install $package"
else
DEBIAN_FRONTEND=noninteractive apt install -y "$package" 2>/dev/null || echo -e "Failed to install $package"
fi
;;
esac
}
@@ -270,19 +284,54 @@ install_package() {
manage_service() {
local service="$1"
local action="$2"
# Check if service exists before trying to manage it
if ! systemctl list-unit-files | grep -q "${service}.service"; then
echo -e "Service $service not found, skipping $action"
return 0
fi
# Handle platform-specific service names
case "$service" in
"pdns")
if [[ "$Server_OS" =~ ^(Ubuntu|Debian) ]]; then
service="pdns-server"
fi
;;
"pure-ftpd")
if [[ "$Server_OS" =~ ^(Ubuntu|Debian) ]]; then
service="pure-ftpd"
elif [[ "$Server_OS" =~ ^(CentOS|AlmaLinux|RockyLinux|RHEL|CloudLinux) ]]; then
service="pure-ftpd"
fi
;;
esac
systemctl "$action" "$service"
}
# Helper Function for Development Tools Installation
install_dev_tools() {
case "$Server_OS" in
"CentOS"|"openEuler")
"CentOS7"|"CloudLinux7"|"CloudLinux8"|"CloudLinux9")
yum groupinstall "Development Tools" -y
yum install autoconf automake zlib-devel openssl-devel expat-devel pcre-devel libmemcached-devel cyrus-sasl* -y
;;
"Ubuntu")
"CentOS8"|"CentOS9"|"CentOSStream8"|"CentOSStream9"|"RHEL8"|"RHEL9"|"AlmaLinux8"|"AlmaLinux9"|"AlmaLinux10"|"RockyLinux8"|"RockyLinux9"|"openEuler2003"|"openEuler2203"|"openEuler2403")
dnf groupinstall "Development Tools" -y
dnf install autoconf automake zlib-devel openssl-devel expat-devel pcre-devel libmemcached-devel cyrus-sasl* -y
;;
"Ubuntu1804"|"Ubuntu2004"|"Ubuntu2010"|"Ubuntu2204"|"Ubuntu2404"|"Ubuntu24043"|"Debian11"|"Debian12"|"Debian13")
DEBIAN_FRONTEND=noninteractive apt install build-essential zlib1g-dev libexpat1-dev openssl libssl-dev libsasl2-dev libpcre3-dev git -y
;;
*)
echo -e "Unknown OS: $Server_OS, attempting to install development tools..."
if [[ "$Server_OS" =~ ^(CentOS|RHEL|AlmaLinux|RockyLinux|CloudLinux|openEuler) ]]; then
dnf groupinstall "Development Tools" -y 2>/dev/null || yum groupinstall "Development Tools" -y 2>/dev/null || echo -e "Failed to install development tools"
else
DEBIAN_FRONTEND=noninteractive apt install build-essential -y 2>/dev/null || echo -e "Failed to install development tools"
fi
;;
esac
}
@@ -290,7 +339,7 @@ install_dev_tools() {
install_php_packages() {
local php_extension="$1"
case "$Server_OS" in
"CentOS"|"openEuler")
"CentOS7"|"CloudLinux7"|"CloudLinux8"|"CloudLinux9")
# Find available PHP versions first
available_php_versions=$(ls /usr/local/lsws/lsphp* 2>/dev/null | grep -o 'lsphp[0-9]*' | sort -u)
if [[ -z "$available_php_versions" ]]; then
@@ -316,7 +365,33 @@ install_php_packages() {
log_warning "No matching ${php_extension} packages found for available PHP versions"
fi
;;
"Ubuntu")
"CentOS8"|"CentOS9"|"CentOSStream8"|"CentOSStream9"|"RHEL8"|"RHEL9"|"AlmaLinux8"|"AlmaLinux9"|"AlmaLinux10"|"RockyLinux8"|"RockyLinux9"|"openEuler2003"|"openEuler2203"|"openEuler2403")
# Find available PHP versions first
available_php_versions=$(ls /usr/local/lsws/lsphp* 2>/dev/null | grep -o 'lsphp[0-9]*' | sort -u)
if [[ -z "$available_php_versions" ]]; then
log_warning "No PHP versions found, skipping ${php_extension} installation"
return 0
fi
# Try to install packages for each available PHP version
packages_to_install=""
for php_version in $available_php_versions; do
# Check if package exists before adding to install list
if dnf search ${php_version}-${php_extension} 2>/dev/null | grep -q "${php_version}-${php_extension}"; then
packages_to_install="${packages_to_install} ${php_version}-${php_extension}"
fi
if dnf search ${php_version}-pecl-${php_extension} 2>/dev/null | grep -q "${php_version}-pecl-${php_extension}"; then
packages_to_install="${packages_to_install} ${php_version}-pecl-${php_extension}"
fi
done
if [[ -n "$packages_to_install" ]]; then
install_package "$packages_to_install"
else
log_warning "No matching ${php_extension} packages found for available PHP versions"
fi
;;
"Ubuntu1804"|"Ubuntu2004"|"Ubuntu2010"|"Ubuntu2204"|"Ubuntu2404"|"Ubuntu24043"|"Debian11"|"Debian12"|"Debian13")
# Find available PHP versions first
available_php_versions=$(ls /usr/local/lsws/lsphp* 2>/dev/null | grep -o 'lsphp[0-9]*' | sort -u)
if [[ -z "$available_php_versions" ]]; then
@@ -629,26 +704,60 @@ if ! uname -m | grep -qE 'x86_64|aarch64' ; then
exit
fi
if grep -q -E "CentOS Linux 7|CentOS Linux 8|CentOS Stream" /etc/os-release ; then
Server_OS="CentOS"
elif grep -q "Red Hat Enterprise Linux" /etc/os-release ; then
Server_OS="RedHat"
if grep -q "CentOS Linux 7" /etc/os-release ; then
Server_OS="CentOS7"
elif grep -q "CentOS Linux 8" /etc/os-release ; then
Server_OS="CentOS8"
elif grep -q "CentOS Linux 9" /etc/os-release ; then
Server_OS="CentOS9"
elif grep -q "CentOS Stream 8" /etc/os-release ; then
Server_OS="CentOSStream8"
elif grep -q "CentOS Stream 9" /etc/os-release ; then
Server_OS="CentOSStream9"
elif grep -q "Red Hat Enterprise Linux 8" /etc/os-release ; then
Server_OS="RHEL8"
elif grep -q "Red Hat Enterprise Linux 9" /etc/os-release ; then
Server_OS="RHEL9"
elif grep -q "AlmaLinux-8" /etc/os-release ; then
Server_OS="AlmaLinux"
Server_OS="AlmaLinux8"
elif grep -q "AlmaLinux-9" /etc/os-release ; then
Server_OS="AlmaLinux"
Server_OS="AlmaLinux9"
elif grep -q "AlmaLinux-10" /etc/os-release ; then
Server_OS="AlmaLinux"
elif grep -q -E "CloudLinux 7|CloudLinux 8|CloudLinux 9" /etc/os-release ; then
Server_OS="CloudLinux"
elif grep -q -E "Rocky Linux" /etc/os-release ; then
Server_OS="RockyLinux"
elif grep -q -E "Ubuntu 18.04|Ubuntu 20.04|Ubuntu 20.10|Ubuntu 22.04|Ubuntu 24.04|Ubuntu 24.04.3" /etc/os-release ; then
Server_OS="Ubuntu"
elif grep -q -E "Debian GNU/Linux 11|Debian GNU/Linux 12|Debian GNU/Linux 13" /etc/os-release ; then
Server_OS="Debian"
elif grep -q -E "openEuler 20.03|openEuler 22.03" /etc/os-release ; then
Server_OS="openEuler"
Server_OS="AlmaLinux10"
elif grep -q "Rocky Linux 8" /etc/os-release ; then
Server_OS="RockyLinux8"
elif grep -q "Rocky Linux 9" /etc/os-release ; then
Server_OS="RockyLinux9"
elif grep -q "CloudLinux 7" /etc/os-release ; then
Server_OS="CloudLinux7"
elif grep -q "CloudLinux 8" /etc/os-release ; then
Server_OS="CloudLinux8"
elif grep -q "CloudLinux 9" /etc/os-release ; then
Server_OS="CloudLinux9"
elif grep -q "Ubuntu 18.04" /etc/os-release ; then
Server_OS="Ubuntu1804"
elif grep -q "Ubuntu 20.04" /etc/os-release ; then
Server_OS="Ubuntu2004"
elif grep -q "Ubuntu 20.10" /etc/os-release ; then
Server_OS="Ubuntu2010"
elif grep -q "Ubuntu 22.04" /etc/os-release ; then
Server_OS="Ubuntu2204"
elif grep -q "Ubuntu 24.04" /etc/os-release ; then
Server_OS="Ubuntu2404"
elif grep -q "Ubuntu 24.04.3" /etc/os-release ; then
Server_OS="Ubuntu24043"
elif grep -q "Debian GNU/Linux 11" /etc/os-release ; then
Server_OS="Debian11"
elif grep -q "Debian GNU/Linux 12" /etc/os-release ; then
Server_OS="Debian12"
elif grep -q "Debian GNU/Linux 13" /etc/os-release ; then
Server_OS="Debian13"
elif grep -q "openEuler 20.03" /etc/os-release ; then
Server_OS="openEuler2003"
elif grep -q "openEuler 22.03" /etc/os-release ; then
Server_OS="openEuler2203"
elif grep -q "openEuler 24.03" /etc/os-release ; then
Server_OS="openEuler2403"
else
echo -e "Unable to detect your system..."
echo -e "\nCyberPanel is supported on x86_64 based Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, Ubuntu 22.04, Ubuntu 24.04, Ubuntu 24.04.3, Debian 11, Debian 12, Debian 13, CentOS 7, CentOS 8, CentOS 9, RHEL 8, RHEL 9, AlmaLinux 8, AlmaLinux 9, AlmaLinux 10, RockyLinux 8, RockyLinux 9, CloudLinux 7, CloudLinux 8, CloudLinux 9, openEuler 20.03, openEuler 22.03...\n"

View File

@@ -5,105 +5,131 @@ if echo $OUTPUT | grep -q "CentOS Linux 7" ; then
echo "Checking and installing curl and wget"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
SERVER_OS="CentOS"
elif echo $OUTPUT | grep -q "CentOS Stream 9" ; then
echo -e "\nDetecting Centos Stream 9...\n"
SERVER_OS="CentOSStream9"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "AlmaLinux 8" ; then
echo -e "\nDetecting AlmaLinux 8...\n"
SERVER_OS="CentOS8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "AlmaLinux 9" ; then
echo -e "\nDetecting AlmaLinux 9...\n"
SERVER_OS="CentOS8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "AlmaLinux 10" ; then
echo -e "\nDetecting AlmaLinux 10...\n"
SERVER_OS="CentOS8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "CloudLinux 8" ; then
echo "Checking and installing curl and wget"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
SERVER_OS="CloudLinux"
elif echo $OUTPUT | grep -q "CloudLinux 9" ; then
echo "Checking and installing curl and wget"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
SERVER_OS="CloudLinux"
elif echo $OUTPUT | grep -q "Ubuntu 20.04" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu"
elif echo $OUTPUT | grep -q "Ubuntu 22.04" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu"
elif echo $OUTPUT | grep -q "Ubuntu 24.04" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu"
elif echo $OUTPUT | grep -q "Ubuntu 24.04.3" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu"
elif echo $OUTPUT | grep -q "Debian GNU/Linux 11" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu"
elif echo $OUTPUT | grep -q "Debian GNU/Linux 12" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu"
elif echo $OUTPUT | grep -q "Debian GNU/Linux 13" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu"
elif echo $OUTPUT | grep -q "Rocky Linux 8" ; then
echo -e "\nDetecting Rocky Linux 8...\n"
SERVER_OS="CentOS8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "Rocky Linux 9" ; then
echo -e "\nDetecting Rocky Linux 9...\n"
SERVER_OS="CentOS8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "Red Hat Enterprise Linux 8" ; then
echo -e "\nDetecting RHEL 8...\n"
SERVER_OS="CentOS8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "Red Hat Enterprise Linux 9" ; then
echo -e "\nDetecting RHEL 9...\n"
SERVER_OS="CentOS7"
elif echo $OUTPUT | grep -q "CentOS Linux 8" ; then
echo -e "\nDetecting CentOS 8...\n"
SERVER_OS="CentOS8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "CentOS Linux 9" ; then
echo -e "\nDetecting CentOS 9...\n"
SERVER_OS="CentOS8"
SERVER_OS="CentOS9"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "CentOS Stream 8" ; then
echo -e "\nDetecting CentOS Stream 8...\n"
SERVER_OS="CentOSStream8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "CentOS Stream 9" ; then
echo -e "\nDetecting CentOS Stream 9...\n"
SERVER_OS="CentOSStream9"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "AlmaLinux 8" ; then
echo -e "\nDetecting AlmaLinux 8...\n"
SERVER_OS="AlmaLinux8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "AlmaLinux 9" ; then
echo -e "\nDetecting AlmaLinux 9...\n"
SERVER_OS="AlmaLinux9"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "AlmaLinux 10" ; then
echo -e "\nDetecting AlmaLinux 10...\n"
SERVER_OS="AlmaLinux10"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "CloudLinux 7" ; then
echo "Checking and installing curl and wget"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
SERVER_OS="CloudLinux7"
elif echo $OUTPUT | grep -q "CloudLinux 8" ; then
echo "Checking and installing curl and wget"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
SERVER_OS="CloudLinux8"
elif echo $OUTPUT | grep -q "CloudLinux 9" ; then
echo "Checking and installing curl and wget"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
SERVER_OS="CloudLinux9"
elif echo $OUTPUT | grep -q "Ubuntu 18.04" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu1804"
elif echo $OUTPUT | grep -q "Ubuntu 20.04" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu2004"
elif echo $OUTPUT | grep -q "Ubuntu 20.10" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu2010"
elif echo $OUTPUT | grep -q "Ubuntu 22.04" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu2204"
elif echo $OUTPUT | grep -q "Ubuntu 24.04" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu2404"
elif echo $OUTPUT | grep -q "Ubuntu 24.04.3" ; then
apt install -y -qq wget curl
SERVER_OS="Ubuntu24043"
elif echo $OUTPUT | grep -q "Debian GNU/Linux 11" ; then
apt install -y -qq wget curl
SERVER_OS="Debian11"
elif echo $OUTPUT | grep -q "Debian GNU/Linux 12" ; then
apt install -y -qq wget curl
SERVER_OS="Debian12"
elif echo $OUTPUT | grep -q "Debian GNU/Linux 13" ; then
apt install -y -qq wget curl
SERVER_OS="Debian13"
elif echo $OUTPUT | grep -q "Rocky Linux 8" ; then
echo -e "\nDetecting Rocky Linux 8...\n"
SERVER_OS="RockyLinux8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "Rocky Linux 9" ; then
echo -e "\nDetecting Rocky Linux 9...\n"
SERVER_OS="RockyLinux9"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "Red Hat Enterprise Linux 8" ; then
echo -e "\nDetecting RHEL 8...\n"
SERVER_OS="RHEL8"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "Red Hat Enterprise Linux 9" ; then
echo -e "\nDetecting RHEL 9...\n"
SERVER_OS="RHEL9"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "openEuler 20.03" ; then
echo -e "\nDetecting openEuler 20.03...\n"
SERVER_OS="openEuler"
SERVER_OS="openEuler2003"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "openEuler 22.03" ; then
echo -e "\nDetecting openEuler 22.03...\n"
SERVER_OS="openEuler"
SERVER_OS="openEuler2203"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
elif echo $OUTPUT | grep -q "openEuler 24.03" ; then
echo -e "\nDetecting openEuler 24.03...\n"
SERVER_OS="openEuler2403"
yum install curl wget -y 1> /dev/null
yum update curl wget ca-certificates -y 1> /dev/null
else
echo -e "\nUnable to detect your OS...\n"
echo -e "\nCyberPanel is supported on:\n"
echo -e "Ubuntu: 20.04, 22.04, 24.04, 24.04.3\n"
echo -e "Ubuntu: 18.04, 20.04, 20.10, 22.04, 24.04, 24.04.3\n"
echo -e "Debian: 11, 12, 13\n"
echo -e "AlmaLinux: 8, 9, 10\n"
echo -e "RockyLinux: 8, 9\n"
echo -e "RHEL: 8, 9\n"
echo -e "CentOS: 7, 9, Stream 9\n"
echo -e "CloudLinux: 8, 9\n"
echo -e "openEuler: 20.03, 22.03\n"
echo -e "CentOS: 7, 8, 9, Stream 8, Stream 9\n"
echo -e "CloudLinux: 7, 8, 9\n"
echo -e "openEuler: 20.03, 22.03, 24.03\n"
exit 1
fi

View File

@@ -81,8 +81,24 @@ class preFlightsChecks:
def get_service_name(self, service):
"""Get the correct service name for the current distribution"""
service_map = {
'pdns': 'pdns'
'pdns': 'pdns',
'powerdns': 'pdns',
'pure-ftpd': 'pure-ftpd',
'pureftpd': 'pure-ftpd'
}
# Platform-specific service name mapping
if self.is_debian_family():
if service in ['pdns', 'powerdns']:
return 'pdns-server'
elif service in ['pure-ftpd', 'pureftpd']:
return 'pure-ftpd'
elif self.is_centos_family():
if service in ['pdns', 'powerdns']:
return 'pdns'
elif service in ['pure-ftpd', 'pureftpd']:
return 'pure-ftpd'
return service_map.get(service, service)
def manage_service(self, service_name, action="start"):