diff --git a/cyberpanel.sh b/cyberpanel.sh index 1e4ace599..4856ca8ad 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -4,8 +4,6 @@ #set -x #set -u -<<<<<<< HEAD -======= # Logging setup LOG_DIR="/var/log/cyberpanel" LOG_FILE="$LOG_DIR/cyberpanel_install_$(date +%Y%m%d_%H%M%S).log" @@ -49,13 +47,13 @@ log_command() { local command="$1" local timestamp=$(date '+%Y-%m-%d %H:%M:%S') echo "[$timestamp] [COMMAND] Executing: $command" >> "$DEBUG_LOG_FILE" - + # Execute command and capture output local output local exit_code output=$($command 2>&1) exit_code=$? - + if [ $exit_code -eq 0 ]; then echo "[$timestamp] [COMMAND] Success: $command" >> "$DEBUG_LOG_FILE" [ -n "$output" ] && echo "[$timestamp] [OUTPUT] $output" >> "$DEBUG_LOG_FILE" @@ -63,7 +61,7 @@ log_command() { echo "[$timestamp] [COMMAND] Failed (exit code: $exit_code): $command" >> "$DEBUG_LOG_FILE" [ -n "$output" ] && echo "[$timestamp] [ERROR OUTPUT] $output" >> "$DEBUG_LOG_FILE" fi - + return $exit_code } @@ -89,7 +87,6 @@ log_function_end() { log_info "CyberPanel installation started" log_info "Log file: $LOG_FILE" log_info "Debug log file: $DEBUG_LOG_FILE" ->>>>>>> stable #CyberPanel installer script for CentOS 7, CentOS 8, CloudLinux 7, AlmaLinux 8, RockyLinux 8, Ubuntu 18.04, Ubuntu 20.04, Ubuntu 20.10, openEuler 20.03 and openEuler 22.03 #For whoever may edit this script, please follow: @@ -131,17 +128,11 @@ Sudo_Test=$(set) #for SUDO check Set_Default_Variables() { -<<<<<<< HEAD - -echo -e "Fetching latest data from CyberPanel server...\n" -echo -e "This may take few seconds..." -======= log_function_start "Set_Default_Variables" echo -e "Fetching latest data from CyberPanel server...\n" echo -e "This may take few seconds..." log_info "Fetching latest data from CyberPanel server" ->>>>>>> stable Silent="Off" Server_Edition="OLS" @@ -170,18 +161,12 @@ Branch_Name="v${Panel_Version}.${Panel_Build}" if [[ $Branch_Name = v*.*.* ]] ; then echo -e "\nBranch name fetched...$Branch_Name" -<<<<<<< HEAD -else - echo -e "\nUnable to fetch Branch name..." - echo -e "\nPlease try again in few moments, if this error still happens, please contact support" -======= log_info "Branch name fetched: $Branch_Name" else echo -e "\nUnable to fetch Branch name..." echo -e "\nPlease try again in few moments, if this error still happens, please contact support" log_error "Unable to fetch branch name from version.txt" log_function_end "Set_Default_Variables" 1 ->>>>>>> stable exit fi @@ -207,11 +192,8 @@ Enterprise_Flag="" License_Key="" Debug_Log2 "Starting installation..,1" -<<<<<<< HEAD -======= log_debug "Default variables set - Server Edition: $Server_Edition, Total RAM: $Total_RAM MB" log_function_end "Set_Default_Variables" ->>>>>>> stable } # Helper Functions for Package Management @@ -332,13 +314,13 @@ EOF configure_php_timezone() { local php_version="$1" local php_ini_path=$(find "$php_version" -name php.ini) - + # Common configuration "${php_version}/bin/phpize" ./configure --with-php-config="${php_version}/bin/php-config" make make install - + # OS-specific configuration if [[ "$Server_OS" = "CentOS" ]] || [[ "$Server_OS" = "openEuler" ]]; then if [[ ! -d "${php_version}/tmp" ]]; then @@ -350,7 +332,7 @@ configure_php_timezone() { else echo "extension=timezonedb.so" > "/usr/local/lsws/${php_version: 16:7}/etc/php/${php_version: 21:1}.${php_version: 22:1}/mods-available/20-timezone.ini" fi - + make clean sed -i 's|expose_php = On|expose_php = Off|g' "$php_ini_path" sed -i 's|mail.add_x_header = On|mail.add_x_header = Off|g' "$php_ini_path" @@ -405,13 +387,9 @@ fi Check_Return() { #check previous command result , 0 = ok , non-0 = something wrong. # shellcheck disable=SC2181 -<<<<<<< HEAD -if [[ $? != "0" ]]; then -======= local exit_code=$? if [[ $exit_code != "0" ]]; then log_error "Previous command failed with exit code: $exit_code" ->>>>>>> stable if [[ -n "$1" ]] ; then echo -e "\n\n\n$1" fi @@ -428,27 +406,18 @@ fi Retry_Command() { # shellcheck disable=SC2034 -<<<<<<< HEAD -======= local command="$1" log_debug "Starting retry command: $command" ->>>>>>> stable for i in {1..50}; do if [[ "$i" = "50" ]] ; then echo "command $1 failed for 50 times, exit..." -<<<<<<< HEAD -======= log_error "Command failed after 50 retries: $1" ->>>>>>> stable exit 2 else $1 && break || { echo -e "\n$1 has failed for $i times\nWait and try again...\n" -<<<<<<< HEAD -======= log_warning "Command failed, retry $i/50: $1" ->>>>>>> stable # Exponential backoff: 1s, 2s, 4s, 8s, then cap at 10s if [[ $i -le 4 ]]; then sleep $((2**($i-1))) @@ -461,12 +430,6 @@ done } Check_Root() { -<<<<<<< HEAD -echo -e "\nChecking root privileges..." - if echo "$Sudo_Test" | grep SUDO >/dev/null; then - echo -e "\nYou are using SUDO , please run as root user...\n" - echo -e "\nIf you don't have direct access to root user, please run \e[31msudo su -\e[39m command (do NOT miss the \e[31m-\e[39m at end or it will fail) and then run installation command again." -======= log_function_start "Check_Root" echo -e "\nChecking root privileges..." log_info "Checking root privileges" @@ -475,7 +438,6 @@ log_info "Checking root privileges" echo -e "\nIf you don't have direct access to root user, please run \e[31msudo su -\e[39m command (do NOT miss the \e[31m-\e[39m at end or it will fail) and then run installation command again." log_error "Not running as root user - SUDO detected" log_function_end "Check_Root" 1 ->>>>>>> stable exit fi @@ -483,21 +445,6 @@ log_info "Checking root privileges" echo -e "\nYou must run on root user to install CyberPanel...\n" echo -e "or run following command: (do NOT miss the quotes)" echo -e "\e[31msudo su -c \"sh <(curl https://cyberpanel.sh || wget -O - https://cyberpanel.sh)\"\e[39m" -<<<<<<< HEAD - exit 1 - else - echo -e "\nYou are runing as root...\n" - fi -} - -Check_Server_IP() { -Server_IP=$(curl --silent --max-time 30 -4 https://cyberpanel.sh/?ip) - if [[ $Server_IP =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then - echo -e "Valid IP detected..." - else - echo -e "Can not detect IP, exit..." - Debug_Log2 "Can not detect IP. [404]" -======= log_error "Not running as root user - UID is not 0" log_function_end "Check_Root" 1 exit 1 @@ -520,7 +467,6 @@ Server_IP=$(curl --silent --max-time 30 -4 https://cyberpanel.sh/?ip) Debug_Log2 "Can not detect IP. [404]" log_error "Failed to detect valid server IP address" log_function_end "Check_Server_IP" 1 ->>>>>>> stable exit fi @@ -547,14 +493,6 @@ fi if [[ "$Server_Country" = *"CN"* ]] ; then Server_Country="CN" echo -e "Setting up to use mirror server...\n" -<<<<<<< HEAD -fi -} - -Check_OS() { -if [[ ! -f /etc/os-release ]] ; then - echo -e "Unable to detect the operating system...\n" -======= log_info "Server country set to CN - will use mirror servers" fi log_debug "Server location: $Server_Country, IP: $Server_IP" @@ -567,7 +505,6 @@ if [[ ! -f /etc/os-release ]] ; then log_error "Unable to detect the operating system - /etc/os-release not found" echo -e "Unable to detect the operating system...\n" log_function_end "Check_OS" 1 ->>>>>>> stable exit fi @@ -612,10 +549,7 @@ Server_OS_Version=$(grep VERSION_ID /etc/os-release | awk -F[=,] '{print $2}' | #to make 20.04 display as 20, etc. echo -e "System: $Server_OS $Server_OS_Version detected...\n" -<<<<<<< HEAD -======= log_info "Operating system detected: $Server_OS $Server_OS_Version" ->>>>>>> stable if [[ $Server_OS = "CloudLinux" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "RockyLinux" ]] || [[ "$Server_OS" = "RedHat" ]] ; then Server_OS="CentOS" @@ -627,12 +561,6 @@ if [[ "$Debug" = "On" ]] ; then Debug_Log "Server_OS" "$Server_OS $Server_OS_Version" fi -<<<<<<< HEAD -} - -Check_Virtualization() { -echo -e "Checking virtualization type..." -======= log_function_end "Check_OS" } @@ -640,7 +568,6 @@ Check_Virtualization() { log_function_start "Check_Virtualization" echo -e "Checking virtualization type..." log_info "Checking virtualization type" ->>>>>>> stable #if hostnamectl | grep -q "Virtualization: lxc"; then # echo -e "\nLXC detected..." # echo -e "CyberPanel does not support LXC" @@ -652,10 +579,7 @@ log_info "Checking virtualization type" if hostnamectl | grep -q "Virtualization: openvz"; then echo -e "OpenVZ detected...\n" -<<<<<<< HEAD -======= log_info "OpenVZ virtualization detected - applying specific configurations" ->>>>>>> stable if [[ ! -d /etc/systemd/system/pure-ftpd.service.d ]]; then mkdir /etc/systemd/system/pure-ftpd.service.d @@ -685,11 +609,8 @@ fi } Check_Panel() { -<<<<<<< HEAD -======= log_function_start "Check_Panel" log_info "Checking for existing control panels" ->>>>>>> stable if [[ -d /usr/local/cpanel ]]; then echo -e "\ncPanel detected...\n" Debug_Log2 "cPanel detected...exit... [404]" @@ -710,26 +631,16 @@ fi } Check_Process() { -<<<<<<< HEAD -======= log_function_start "Check_Process" log_info "Checking for conflicting processes" ->>>>>>> stable local services=("httpd" "apache2" "named" "exim") - + for service in "${services[@]}"; do if systemctl is-active --quiet "$service"; then manage_service "$service" "stop" manage_service "$service" "disable" manage_service "$service" "mask" echo -e "\n$service process detected, disabling...\n" -<<<<<<< HEAD - fi - done -} - -Check_Provider() { -======= log_warning "$service process detected and disabled" fi done @@ -739,7 +650,6 @@ Check_Provider() { Check_Provider() { log_function_start "Check_Provider" log_info "Detecting server provider" ->>>>>>> stable if hash dmidecode >/dev/null 2>&1; then if [[ "$(dmidecode -s bios-vendor)" = "Google" ]]; then Server_Provider="Google Cloud Platform" @@ -795,10 +705,7 @@ echo -e "\nThis will install LiteSpeed Enterise , replace LICENSE_KEY to actual } Check_Argument() { -<<<<<<< HEAD -======= log_function_start "Check_Argument" "$@" ->>>>>>> stable if [[ "$#" = "0" ]] || [[ "$#" = "1" && "$1" = "--debug" ]] || [[ "$#" = "1" && "$1" = "--mirror" ]]; then echo -e "\nInitialized...\n" else @@ -1188,14 +1095,10 @@ License_Check "$License_Key" } Pre_Install_Setup_Repository() { -<<<<<<< HEAD -if [[ $Server_OS = "CentOS" ]] ; then -======= log_function_start "Pre_Install_Setup_Repository" log_info "Setting up package repositories for $Server_OS $Server_OS_Version" if [[ $Server_OS = "CentOS" ]] ; then log_debug "Importing LiteSpeed GPG key" ->>>>>>> stable rpm --import https://cyberpanel.sh/rpms.litespeedtech.com/centos/RPM-GPG-KEY-litespeed #import the LiteSpeed GPG key @@ -1203,10 +1106,10 @@ if [[ $Server_OS = "CentOS" ]] ; then yum autoremove -y epel-release rm -f /etc/yum.repos.d/epel.repo rm -f /etc/yum.repos.d/epel.repo.rpmsave - + # Setup EPEL repository based on version setup_epel_repo - + # Setup MariaDB repository setup_mariadb_repo @@ -1244,7 +1147,7 @@ if [[ $Server_OS = "CentOS" ]] ; then dnf config-manager --set-enabled PowerTools > /dev/null 2>&1 dnf config-manager --set-enabled powertools > /dev/null 2>&1 - + # cat </etc/yum.repos.d/CentOS-PowerTools-CyberPanel.repo #[powertools-for-cyberpanel] #name=CentOS Linux \$releasever - PowerTools @@ -1292,10 +1195,7 @@ EOF fi if [[ $Server_OS = "openEuler" ]]; then -<<<<<<< HEAD -======= log_debug "Importing LiteSpeed GPG key" ->>>>>>> stable rpm --import https://cyberpanel.sh/rpms.litespeedtech.com/centos/RPM-GPG-KEY-litespeed #import the LiteSpeed GPG key yum clean all @@ -1402,14 +1302,9 @@ done } Pre_Install_Required_Components() { -<<<<<<< HEAD - -Debug_Log2 "Installing necessary components..,3" -======= log_function_start "Pre_Install_Required_Components" Debug_Log2 "Installing necessary components..,3" log_info "Installing required system components and dependencies" ->>>>>>> stable if [[ "$Server_OS" = "CentOS" ]] || [[ "$Server_OS" = "openEuler" ]] ; then # System-wide update - consider making this optional for faster installs @@ -1458,7 +1353,7 @@ else ln -s /usr/bin/pip3 /usr/bin/pip3.6 ln -s /usr/bin/pip3.6 /usr/bin/pip -# Oracle Ubuntu ARM misses ping and cron +# Oracle Ubuntu ARM misses ping and cron DEBIAN_FRONTEND=noninteractive apt install -y locales locale-gen "en_US.UTF-8" @@ -1534,13 +1429,9 @@ Debug_Log2 "Necessary components installed..,5" } Pre_Install_System_Tweak() { -<<<<<<< HEAD -Debug_Log2 "Setting up system tweak...,20" -======= log_function_start "Pre_Install_System_Tweak" Debug_Log2 "Setting up system tweak...,20" log_info "Applying system tweaks and optimizations" ->>>>>>> stable Line_Number=$(grep -n "127.0.0.1" /etc/hosts | cut -d: -f 1) My_Hostname=$(hostname) @@ -1595,11 +1486,11 @@ if ! grep -q "pid_max" /etc/rc.local 2>/dev/null ; then echo 1 > /sys/kernel/mm/ksm/run" >>/etc/rc.d/rc.local chmod +x /etc/rc.d/rc.local else - if [[ -f /etc/rc.local ]] ; then + if [[ -f /etc/rc.local ]] ; then echo -e "#!/bin/bash\n$(cat /etc/rc.local)" > /etc/rc.local - else + else echo "#!/bin/bash" > /etc/rc.local - fi + fi echo "echo 1000000 > /proc/sys/kernel/pid_max echo 1 > /sys/kernel/mm/ksm/run" >>/etc/rc.local chmod +x /etc/rc.local @@ -1718,12 +1609,6 @@ if [[ -n "$Line1" ]] && [[ "$Line1" =~ ^[0-9]+$ ]]; then else echo "Warning: Could not find 'nameserver 8.8.8.8' pattern in installCyberPanel.py - skipping resolv.conf modification" fi -<<<<<<< HEAD -} - -License_Validation() { -Debug_Log2 "Validating LiteSpeed license...,40" -======= log_debug "System tweaks completed - SWAP, limits, and DNS configured" log_function_end "Pre_Install_System_Tweak" @@ -1733,7 +1618,6 @@ License_Validation() { log_function_start "License_Validation" Debug_Log2 "Validating LiteSpeed license...,40" log_info "Validating LiteSpeed Enterprise license" ->>>>>>> stable Current_Dir=$(pwd) if [ -f /root/cyberpanel-tmp ]; then @@ -1767,26 +1651,17 @@ fi if ./lshttpd -V |& grep "ERROR" || ./lshttpd -V |& grep "expire in 0 days" ; then echo -e "\n\nThere appears to be an issue with license , please check above result..." Debug_Log2 "There appears to be an issue with LiteSpeed License, make sure you are using correct serial key. [404]" -<<<<<<< HEAD -======= log_error "LiteSpeed license validation failed" log_function_end "License_Validation" 1 ->>>>>>> stable exit fi echo -e "\nLicense seems valid..." -<<<<<<< HEAD -cd "$Current_Dir" || exit -rm -rf /root/cyberpanel-tmp - #clean up the temp files -======= log_info "LiteSpeed license validated successfully" cd "$Current_Dir" || exit rm -rf /root/cyberpanel-tmp #clean up the temp files log_function_end "License_Validation" ->>>>>>> stable } Pre_Install_CN_Replacement() { @@ -1849,13 +1724,9 @@ Retry_Command "/root/.acme.sh/acme.sh --upgrade --auto-upgrade" } Main_Installation() { -<<<<<<< HEAD -Debug_Log2 "Starting main installation..,30" -======= log_function_start "Main_Installation" Debug_Log2 "Starting main installation..,30" log_info "Starting main CyberPanel installation" ->>>>>>> stable if [[ -d /usr/local/CyberCP ]] ; then echo -e "\n CyberPanel already installed, exiting..." Debug_Log2 "CyberPanel already installed, exiting... [404]" @@ -1943,7 +1814,7 @@ fi Post_Install_Addon_Mecached_LSMCD() { install_dev_tools - + wget -O lsmcd-master.zip https://cyberpanel.sh/codeload.github.com/litespeedtech/lsmcd/zip/master unzip lsmcd-master.zip Current_Dir=$(pwd) @@ -1953,14 +1824,9 @@ Post_Install_Addon_Mecached_LSMCD() { make make install cd "$Current_Dir" || exit - + manage_service "lsmcd" "enable" manage_service "lsmcd" "start" -<<<<<<< HEAD -} - -Post_Install_Addon_Memcached() { -======= log_info "LSMCD installation completed" log_function_end "Post_Install_Addon_Mecached_LSMCD" } @@ -1968,9 +1834,8 @@ Post_Install_Addon_Memcached() { Post_Install_Addon_Memcached() { log_function_start "Post_Install_Addon_Memcached" log_info "Installing Memcached and PHP extension" ->>>>>>> stable install_php_packages "memcached" - + if [[ $Total_RAM -ge 2048 ]]; then Post_Install_Addon_Mecached_LSMCD else @@ -1990,14 +1855,11 @@ Post_Install_Addon_Memcached() { } Post_Install_Addon_Redis() { -<<<<<<< HEAD -======= log_function_start "Post_Install_Addon_Redis" log_info "Installing Redis server and PHP extension" ->>>>>>> stable # Install PHP Redis extension install_php_packages "redis" - + # Install Redis server if [[ "$Server_OS" = "CentOS" ]]; then if [[ "$Server_OS_Version" = "8" || "$Server_OS_Version" = "9" ]]; then @@ -2040,13 +1902,9 @@ Post_Install_Addon_Redis() { } Post_Install_PHP_Session_Setup() { -<<<<<<< HEAD -echo -e "\nSetting up PHP session storage path...\n" -======= log_function_start "Post_Install_PHP_Session_Setup" echo -e "\nSetting up PHP session storage path...\n" log_info "Setting up PHP session storage configuration" ->>>>>>> stable #wget -O /root/php_session_script.sh "${Git_Content_URL}/stable/CPScripts/setup_php_sessions.sh" chmod +x /usr/local/CyberCP/CPScripts/setup_php_sessions.sh bash /usr/local/CyberCP/CPScripts/setup_php_sessions.sh @@ -2055,11 +1913,8 @@ Debug_Log2 "Setting up PHP session conf...,90" } Post_Install_PHP_TimezoneDB() { -<<<<<<< HEAD -======= log_function_start "Post_Install_PHP_TimezoneDB" log_info "Installing PHP TimezoneDB extension" ->>>>>>> stable Current_Dir="$(pwd)" rm -f /usr/local/lsws/cyberpanel-tmp mkdir /usr/local/lsws/cyberpanel-tmp @@ -2087,11 +1942,8 @@ Debug_Log2 "Installing timezoneDB...,95" } Post_Install_Regenerate_Webadmin_Console_Passwd() { -<<<<<<< HEAD -======= log_function_start "Post_Install_Regenerate_Webadmin_Console_Passwd" log_info "Regenerating WebAdmin console password" ->>>>>>> stable if [[ "$Server_Edition" = "OLS" ]]; then PHP_Command="admin_php" else @@ -2110,12 +1962,6 @@ chown lsadm:lsadm /usr/local/lsws/admin/conf/htpasswd chmod 600 /usr/local/lsws/admin/conf/htpasswd echo "${Webadmin_Pass}" >/etc/cyberpanel/webadmin_passwd chmod 600 /etc/cyberpanel/webadmin_passwd -<<<<<<< HEAD -} - -Post_Install_Setup_Watchdog() { -if [[ "$Watchdog" = "On" ]]; then -======= log_info "WebAdmin console password regenerated" log_function_end "Post_Install_Regenerate_Webadmin_Console_Passwd" } @@ -2124,7 +1970,6 @@ Post_Install_Setup_Watchdog() { log_function_start "Post_Install_Setup_Watchdog" if [[ "$Watchdog" = "On" ]]; then log_info "Setting up watchdog monitoring service" ->>>>>>> stable wget -O /etc/cyberpanel/watchdog.sh "${Git_Content_URL}/stable/CPScripts/watchdog.sh" chmod 700 /etc/cyberpanel/watchdog.sh ln -s /etc/cyberpanel/watchdog.sh /usr/local/bin/watchdog @@ -2159,11 +2004,8 @@ fi } Post_Install_Display_Final_Info() { -<<<<<<< HEAD -======= log_function_start "Post_Install_Display_Final_Info" log_info "Preparing final installation information" ->>>>>>> stable snappymailAdminPass=$(grep SetPassword /usr/local/CyberCP/public/snappymail.php| sed -e 's|$oConfig->SetPassword(||g' -e "s|');||g" -e "s|'||g") Elapsed_Time="$((Time_Count / 3600)) hrs $(((SECONDS / 60) % 60)) min $((Time_Count % 60)) sec" echo "###################################################################" @@ -2235,11 +2077,8 @@ fi Post_Install_Regenerate_Cert() { -<<<<<<< HEAD -======= log_function_start "Post_Install_Regenerate_Cert" log_info "Regenerating SSL certificates for control panel" ->>>>>>> stable cat </root/cyberpanel/cert_conf [req] prompt=no @@ -2360,11 +2199,8 @@ fi } Post_Install_Tweak() { -<<<<<<< HEAD -======= log_function_start "Post_Install_Tweak" log_info "Applying post-installation tweaks and configurations" ->>>>>>> stable if [[ -d /etc/pure-ftpd/conf ]]; then echo "yes" >/etc/pure-ftpd/conf/ChrootEveryone systemctl restart pure-ftpd-mysql @@ -2475,10 +2311,7 @@ systemctl stop lsws >/dev/null 2>&1 systemctl start lsws >/dev/null 2>&1 echo -e "\nFinalizing...\n" echo -e "Cleaning up...\n" -<<<<<<< HEAD -======= log_info "Cleaning up temporary installation files" ->>>>>>> stable rm -rf /root/cyberpanel if [[ "$Server_Country" = "CN" ]] ; then @@ -2501,14 +2334,11 @@ sed -i 's|http://license.litespeedtech.com/|https://cyberpanel.sh/license.litesp } echo -e "\nInitializing...\n" -<<<<<<< HEAD -======= log_info "=============================================" log_info "CyberPanel installation script started" log_info "Script version: $Panel_Version.$Panel_Build" log_info "Script arguments: $*" log_info "=============================================" ->>>>>>> stable if [[ "$*" = *"--debug"* ]] ; then Debug="On"