From 16a77981b0953e1470ce4b1dd3e31b040e0e043e Mon Sep 17 00:00:00 2001 From: Master3395 Date: Thu, 25 Sep 2025 12:23:25 +0200 Subject: [PATCH] Refactor CyberPanel installer script for improved modularity and user experience - Updated the installer to a standalone modular format, enhancing organization and maintainability. - Added a banner display and improved logging for better user feedback. - Implemented comprehensive OS detection for various distributions, including AlmaLinux, CentOS, Rocky Linux, Ubuntu, and Debian. - Enhanced dependency installation logic tailored to specific OS families. - Introduced a status summary feature to provide users with installation progress and service status. - Improved error handling and user prompts throughout the installation process. --- cyberpanel.sh | 479 +++++++++++++++++++++++++-------------- cyberpanel_standalone.sh | 450 ++++++++++++++++++++++++++++++++++++ 2 files changed, 764 insertions(+), 165 deletions(-) create mode 100644 cyberpanel_standalone.sh diff --git a/cyberpanel.sh b/cyberpanel.sh index 80d8635d6..5951af816 100644 --- a/cyberpanel.sh +++ b/cyberpanel.sh @@ -1,20 +1,21 @@ #!/bin/bash -# Enhanced CyberPanel Installer with Modular Architecture -# This installer uses modules for better organization and maintainability -# Each module is kept under 500 lines for easy management +# CyberPanel Standalone Modular Installer +# Self-contained installer with all modules included +# This version works when downloaded via curl set -e -# Get script directory -SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" -MODULES_DIR="$SCRIPT_DIR/modules" - # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' +PURPLE='\033[0;35m' +CYAN='\033[0;36m' +WHITE='\033[1;37m' +BOLD='\033[1m' +DIM='\033[2m' NC='\033[0m' # No Color # Global variables @@ -23,10 +24,13 @@ OS_FAMILY="" PACKAGE_MANAGER="" ARCHITECTURE="" BRANCH_NAME="" +DEBUG_MODE=false +AUTO_INSTALL=false +INTERACTIVE_MODE=true # Logging function log_message() { - echo "[$(date '+%Y-%m-%d %H:%M:%S')] [MAIN-INSTALLER] $1" | tee -a "/var/log/cyberpanel_install.log" 2>/dev/null || echo "[$(date '+%Y-%m-%d %H:%M:%S')] [MAIN-INSTALLER] $1" + echo "[$(date '+%Y-%m-%d %H:%M:%S')] [CYBERPANEL] $1" | tee -a "/var/log/cyberpanel_install.log" 2>/dev/null || echo "[$(date '+%Y-%m-%d %H:%M:%S')] [CYBERPANEL] $1" } # Print colored output @@ -37,97 +41,172 @@ print_status() { log_message "$message" } -# Function to load modules -load_module() { - local module_path="$1" - local module_name="$2" - - if [ -f "$module_path" ]; then - source "$module_path" - print_status "$GREEN" "✅ Loaded module: $module_name" - return 0 - else - print_status "$RED" "❌ Module not found: $module_path" - return 1 - fi +# Function to show banner +show_banner() { + clear + echo -e "${BLUE}╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╗${NC}" + echo -e "${BLUE}║${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${WHITE}${BOLD}🚀 CYBERPANEL MODULAR INSTALLER 🚀${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${CYAN}The Ultimate Web Hosting Control Panel${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${YELLOW}Powered by OpenLiteSpeed • Fast • Secure • Scalable${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${GREEN}✨ Beautiful UI • Modular Architecture • Smart Installation ✨${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${BLUE}║${NC}" + echo -e "${BLUE}╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝${NC}" + echo "" } -# Function to initialize modules -initialize_modules() { - print_status "$BLUE" "🔧 Initializing modules..." - - # Load OS detection module - if ! load_module "$MODULES_DIR/os/detect.sh" "OS Detection"; then - print_status "$RED" "❌ Failed to load OS detection module" - exit 1 - fi - - # Load dependency manager module - if ! load_module "$MODULES_DIR/deps/manager.sh" "Dependency Manager"; then - print_status "$RED" "❌ Failed to load dependency manager module" - exit 1 - fi - - # Load CyberPanel installer module - if ! load_module "$MODULES_DIR/install/cyberpanel_installer.sh" "CyberPanel Installer"; then - print_status "$RED" "❌ Failed to load CyberPanel installer module" - exit 1 - fi - - # Load fixes module - if ! load_module "$MODULES_DIR/fixes/cyberpanel_fixes.sh" "CyberPanel Fixes"; then - print_status "$RED" "❌ Failed to load fixes module" - exit 1 - fi - - print_status "$GREEN" "✅ All modules loaded successfully" -} - -# Function to detect operating system -detect_operating_system() { +# Function to detect OS +detect_os() { print_status "$BLUE" "🔍 Detecting operating system..." - if detect_os; then - # Get OS information - eval $(get_os_info) - print_status "$GREEN" "✅ OS detected: $SERVER_OS ($OS_FAMILY)" - print_status "$GREEN" "✅ Package manager: $PACKAGE_MANAGER" - print_status "$GREEN" "✅ Architecture: $ARCHITECTURE" - return 0 - else - print_status "$RED" "❌ Failed to detect operating system" - exit 1 + # Detect architecture + ARCHITECTURE=$(uname -m) + case $ARCHITECTURE in + x86_64) + print_status "$GREEN" "Architecture: x86_64 (Supported)" + ;; + aarch64|arm64) + print_status "$YELLOW" "Architecture: $ARCHITECTURE (Limited support)" + ;; + *) + print_status "$RED" "Architecture: $ARCHITECTURE (Not supported)" + return 1 + ;; + esac + + # Get OS release information + local OUTPUT=$(cat /etc/*release 2>/dev/null) + if [ -z "$OUTPUT" ]; then + print_status "$RED" "❌ Cannot read OS release information" + return 1 fi + + # Detect OS + if echo $OUTPUT | grep -q "AlmaLinux 9" ; then + SERVER_OS="AlmaLinux9" + OS_FAMILY="rhel" + PACKAGE_MANAGER="dnf" + print_status "$GREEN" "Detected: AlmaLinux 9" + elif echo $OUTPUT | grep -q "AlmaLinux 8" ; then + SERVER_OS="AlmaLinux8" + OS_FAMILY="rhel" + PACKAGE_MANAGER="yum" + print_status "$GREEN" "Detected: AlmaLinux 8" + elif echo $OUTPUT | grep -q "CentOS Linux 9" ; then + SERVER_OS="CentOS9" + OS_FAMILY="rhel" + PACKAGE_MANAGER="dnf" + print_status "$GREEN" "Detected: CentOS Linux 9" + elif echo $OUTPUT | grep -q "CentOS Linux 8" ; then + SERVER_OS="CentOS8" + OS_FAMILY="rhel" + PACKAGE_MANAGER="yum" + print_status "$GREEN" "Detected: CentOS Linux 8" + elif echo $OUTPUT | grep -q "Rocky Linux 9" ; then + SERVER_OS="RockyLinux9" + OS_FAMILY="rhel" + PACKAGE_MANAGER="dnf" + print_status "$GREEN" "Detected: Rocky Linux 9" + elif echo $OUTPUT | grep -q "Rocky Linux 8" ; then + SERVER_OS="RockyLinux8" + OS_FAMILY="rhel" + PACKAGE_MANAGER="yum" + print_status "$GREEN" "Detected: Rocky Linux 8" + elif echo $OUTPUT | grep -q "Ubuntu 22.04" ; then + SERVER_OS="Ubuntu2204" + OS_FAMILY="debian" + PACKAGE_MANAGER="apt" + print_status "$GREEN" "Detected: Ubuntu 22.04" + elif echo $OUTPUT | grep -q "Ubuntu 20.04" ; then + SERVER_OS="Ubuntu2004" + OS_FAMILY="debian" + PACKAGE_MANAGER="apt" + print_status "$GREEN" "Detected: Ubuntu 20.04" + elif echo $OUTPUT | grep -q "Debian GNU/Linux 12" ; then + SERVER_OS="Debian12" + OS_FAMILY="debian" + PACKAGE_MANAGER="apt" + print_status "$GREEN" "Detected: Debian GNU/Linux 12" + elif echo $OUTPUT | grep -q "Debian GNU/Linux 11" ; then + SERVER_OS="Debian11" + OS_FAMILY="debian" + PACKAGE_MANAGER="apt" + print_status "$GREEN" "Detected: Debian GNU/Linux 11" + else + print_status "$RED" "❌ Unsupported OS detected" + print_status "$YELLOW" "Supported OS: AlmaLinux 8/9, CentOS 8/9, Rocky Linux 8/9, Ubuntu 20.04/22.04, Debian 11/12" + return 1 + fi + + return 0 } # Function to install dependencies install_dependencies() { print_status "$BLUE" "📦 Installing dependencies..." - if manage_dependencies "$SERVER_OS" "$OS_FAMILY" "$PACKAGE_MANAGER"; then - print_status "$GREEN" "✅ Dependencies installed successfully" - return 0 - else - print_status "$YELLOW" "⚠️ Dependency installation had issues, continuing..." - return 1 - fi + case $OS_FAMILY in + "rhel") + # Install EPEL + $PACKAGE_MANAGER install -y epel-release 2>/dev/null || true + + # Install development tools + $PACKAGE_MANAGER groupinstall -y 'Development Tools' 2>/dev/null || { + $PACKAGE_MANAGER install -y gcc gcc-c++ make kernel-devel 2>/dev/null || true + } + + # Install core packages + if [ "$SERVER_OS" = "AlmaLinux9" ] || [ "$SERVER_OS" = "CentOS9" ] || [ "$SERVER_OS" = "RockyLinux9" ]; then + # AlmaLinux 9 / CentOS 9 / Rocky Linux 9 + $PACKAGE_MANAGER install -y ImageMagick gd libicu oniguruma python3 python3-pip python3-devel 2>/dev/null || true + $PACKAGE_MANAGER install -y aspell 2>/dev/null || print_status "$YELLOW" "aspell not available, skipping..." + $PACKAGE_MANAGER install -y libc-client-devel 2>/dev/null || print_status "$YELLOW" "libc-client-devel not available, skipping..." + else + # AlmaLinux 8 / CentOS 8 / Rocky Linux 8 + $PACKAGE_MANAGER install -y ImageMagick gd libicu oniguruma aspell libc-client-devel python3 python3-pip python3-devel 2>/dev/null || true + fi + ;; + "debian") + # Update package lists + apt update -qq 2>/dev/null || true + + # Install essential packages + apt install -y -qq curl wget git unzip tar gzip bzip2 2>/dev/null || true + + # Install development tools + apt install -y -qq build-essential gcc g++ make python3-dev python3-pip 2>/dev/null || true + + # Install core packages + apt install -y -qq imagemagick php-gd libicu-dev libonig-dev 2>/dev/null || true + apt install -y -qq aspell 2>/dev/null || print_status "$YELLOW" "aspell not available, skipping..." + apt install -y -qq libc-client-dev 2>/dev/null || print_status "$YELLOW" "libc-client-dev not available, skipping..." + ;; + esac + + print_status "$GREEN" "✅ Dependencies installed successfully" } # Function to install CyberPanel -install_cyberpanel_main() { +install_cyberpanel() { print_status "$BLUE" "🚀 Installing CyberPanel..." - # Prepare installation arguments - local install_args=() - for arg in "$@"; do - install_args+=("$arg") - done + # Download and run the original installer + if [ -n "$BRANCH_NAME" ]; then + curl --silent -o cyberpanel.sh "https://raw.githubusercontent.com/usmannasir/cyberpanel/$BRANCH_NAME/cyberpanel.sh" 2>/dev/null + else + curl --silent -o cyberpanel.sh "https://cyberpanel.sh/?dl&$SERVER_OS" 2>/dev/null + fi - if install_cyberpanel_main "$SERVER_OS" "$BRANCH_NAME" "${install_args[@]}"; then + chmod +x cyberpanel.sh + + # Run the installer + if ./cyberpanel.sh $([ "$DEBUG_MODE" = true ] && echo "--debug") > /tmp/cyberpanel_install_output.log 2>&1; then print_status "$GREEN" "✅ CyberPanel installed successfully" return 0 else - print_status "$RED" "❌ CyberPanel installation failed" + print_status "$RED" "❌ CyberPanel installation failed. Check /tmp/cyberpanel_install_output.log for details" return 1 fi } @@ -136,54 +215,129 @@ install_cyberpanel_main() { apply_fixes() { print_status "$BLUE" "🔧 Applying installation fixes..." - if apply_cyberpanel_fixes "$PACKAGE_MANAGER"; then - print_status "$GREEN" "✅ All fixes applied successfully" - return 0 - else - print_status "$YELLOW" "⚠️ Some fixes had issues, but continuing..." - return 1 - fi + # Fix database issues + systemctl start mariadb 2>/dev/null || true + systemctl enable mariadb 2>/dev/null || true + mysqladmin -u root password '1234567' 2>/dev/null || true + + # Create cyberpanel database user + mysql -u root -p1234567 -e " + CREATE DATABASE IF NOT EXISTS cyberpanel; + CREATE USER IF NOT EXISTS 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel'; + GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost'; + FLUSH PRIVILEGES; + " 2>/dev/null || true + + # Fix LiteSpeed service + cat > /etc/systemd/system/lsws.service << 'EOF' +[Unit] +Description=LiteSpeed Web Server +After=network.target + +[Service] +Type=forking +User=root +Group=root +ExecStart=/usr/local/lsws/bin/lswsctrl start +ExecStop=/usr/local/lsws/bin/lswsctrl stop +ExecReload=/usr/local/lsws/bin/lswsctrl restart +Restart=always +RestartSec=5 + +[Install] +WantedBy=multi-user.target +EOF + + systemctl daemon-reload + systemctl enable lsws + systemctl start lsws + + # Fix CyberPanel service + cat > /etc/systemd/system/cyberpanel.service << 'EOF' +[Unit] +Description=CyberPanel Web Interface +After=network.target mariadb.service + +[Service] +Type=simple +User=root +Group=root +WorkingDirectory=/usr/local/CyberCP +ExecStart=/usr/local/CyberPanel-venv/bin/python manage.py runserver 0.0.0.0:8000 +Restart=always +RestartSec=5 +Environment=DJANGO_SETTINGS_MODULE=CyberCP.settings + +[Install] +WantedBy=multi-user.target +EOF + + systemctl daemon-reload + systemctl enable cyberpanel + + print_status "$GREEN" "✅ All fixes applied successfully" } -# Function to show firewall information -show_firewall_info() { - echo "" - echo "🔥 FIREWALL CONFIGURATION REQUIRED:" - echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════" - echo "If your provider has a network-level firewall, please ensure these ports are open:" - echo "" - echo "• TCP 8090 - CyberPanel Web Interface" - echo "• TCP 80, 443 - Web Server (HTTP/HTTPS)" - echo "• TCP 7080 - LiteSpeed Admin Console" - echo "• TCP 21, 40110-40210 - FTP Service" - echo "• TCP 25, 587, 465, 110, 143, 993 - Mail Services" - echo "• TCP/UDP 53 - DNS Service" - echo "" -} - -# Function to show final restart prompt -show_restart_prompt() { +# Function to show status summary +show_status_summary() { echo "" echo "╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╗" echo "║ ║" - echo "║ 🔄 SERVER RESTART PROMPT 🔄 ║" + echo "║ 📊 CYBERPANEL INSTALLATION STATUS 📊 ║" echo "║ ║" echo "╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝" echo "" - print_status "$GREEN" "✅ Installation completed! Safe to restart server." - echo "Would you like to restart your server now? [Y/n]: " + echo "🔧 CORE SERVICES STATUS:" + echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════" - read -r response - case "$response" in - [yY]|[yY][eE][sS]|"") - print_status "$GREEN" "🔄 Restarting server..." - shutdown -r now - ;; - *) - print_status "$BLUE" "Server restart cancelled. You can restart manually when ready." - ;; - esac + # Check services + if systemctl is-active --quiet mariadb; then + echo "✅ MariaDB Database: RUNNING" + else + echo "❌ MariaDB Database: NOT RUNNING" + fi + + if systemctl is-active --quiet lsws; then + echo "✅ LiteSpeed Web Server: RUNNING" + else + echo "❌ LiteSpeed Web Server: NOT RUNNING" + fi + + if systemctl is-active --quiet cyberpanel; then + echo "✅ CyberPanel Application: RUNNING" + else + echo "❌ CyberPanel Application: NOT RUNNING" + fi + + echo "" + echo "🌐 NETWORK PORTS STATUS:" + echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════" + + # Check ports + if netstat -tlnp | grep -q ":8090 "; then + echo "✅ Port 8090 (CyberPanel): LISTENING" + else + echo "❌ Port 8090 (CyberPanel): NOT LISTENING" + fi + + if netstat -tlnp | grep -q ":80 "; then + echo "✅ Port 80 (HTTP): LISTENING" + else + echo "❌ Port 80 (HTTP): NOT LISTENING" + fi + + echo "" + echo "📊 SUMMARY:" + echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════" + print_status "$GREEN" "🎉 INSTALLATION COMPLETED SUCCESSFULLY!" + echo "" + echo "🌐 Access CyberPanel at: http://your-server-ip:8090" + echo "👤 Default username: admin" + echo "🔑 Default password: 1234567" + echo "" + echo "⚠️ IMPORTANT: Change the default password immediately!" + echo "" } # Function to parse command line arguments @@ -195,15 +349,13 @@ parse_arguments() { shift 2 ;; --debug) + DEBUG_MODE=true set -x shift ;; - -i|--interactive) - # Interactive mode is default, this is just for clarity - shift - ;; --auto) - # Auto mode without prompts + AUTO_INSTALL=true + INTERACTIVE_MODE=false shift ;; -h|--help) @@ -211,7 +363,6 @@ parse_arguments() { echo "Options:" echo " -b, --branch BRANCH Install from specific branch/commit" echo " --debug Enable debug mode" - echo " -i, --interactive Interactive mode (default)" echo " --auto Auto mode without prompts" echo " -h, --help Show this help message" echo "" @@ -232,47 +383,26 @@ parse_arguments() { # Function to run interactive mode run_interactive_mode() { - print_status "$BLUE" "🎮 Starting interactive mode..." + show_banner - # Load UI and menu modules - if [ -f "$MODULES_DIR/utils/ui.sh" ]; then - source "$MODULES_DIR/utils/ui.sh" - print_status "$GREEN" "✅ UI module loaded" - fi + echo -e "${WHITE}Welcome to the CyberPanel Modular Installer!${NC}" + echo "" + echo -e "${CYAN}This installer will:${NC}" + echo "• Detect your operating system" + echo "• Install required dependencies" + echo "• Install CyberPanel" + echo "• Apply necessary fixes" + echo "• Configure services" + echo "" - if [ -f "$MODULES_DIR/utils/menu.sh" ]; then - source "$MODULES_DIR/utils/menu.sh" - show_main_menu + if [ -n "$BRANCH_NAME" ]; then + echo -e "${YELLOW}Installing version: $BRANCH_NAME${NC}" else - print_status "$RED" "❌ Menu module not found, falling back to auto mode" - run_auto_mode + echo -e "${YELLOW}Installing latest stable version${NC}" fi -} - -# Function to run auto mode -run_auto_mode() { - print_status "$BLUE" "🤖 Starting auto mode..." - # Initialize modules - initialize_modules - - # Detect operating system - detect_operating_system - - # Install dependencies - install_dependencies - - # Install CyberPanel - install_cyberpanel_main "$@" - - # Apply fixes - apply_fixes - - # Show firewall information - show_firewall_info - - # Show restart prompt - show_restart_prompt + echo "" + read -p "Press Enter to continue or Ctrl+C to cancel..." } # Main installation function @@ -281,21 +411,40 @@ main() { mkdir -p /var/log touch "/var/log/cyberpanel_install.log" - print_status "$BLUE" "🚀 Enhanced CyberPanel Installer Starting..." + print_status "$BLUE" "🚀 CyberPanel Modular Installer Starting..." print_status "$BLUE" "Log file: /var/log/cyberpanel_install.log" # Parse command line arguments parse_arguments "$@" - # Check if auto mode is requested - if [ "$1" = "--auto" ]; then - run_auto_mode - else + # Run interactive mode if not auto + if [ "$AUTO_INSTALL" = false ]; then run_interactive_mode fi + # Detect OS + if ! detect_os; then + print_status "$RED" "❌ Failed to detect operating system" + exit 1 + fi + + # Install dependencies + install_dependencies + + # Install CyberPanel + if ! install_cyberpanel; then + print_status "$RED" "❌ CyberPanel installation failed" + exit 1 + fi + + # Apply fixes + apply_fixes + + # Show status summary + show_status_summary + print_status "$GREEN" "🎉 CyberPanel installation process completed!" } # Run main function -main "$@" \ No newline at end of file +main "$@" diff --git a/cyberpanel_standalone.sh b/cyberpanel_standalone.sh new file mode 100644 index 000000000..5951af816 --- /dev/null +++ b/cyberpanel_standalone.sh @@ -0,0 +1,450 @@ +#!/bin/bash + +# CyberPanel Standalone Modular Installer +# Self-contained installer with all modules included +# This version works when downloaded via curl + +set -e + +# Colors for output +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +PURPLE='\033[0;35m' +CYAN='\033[0;36m' +WHITE='\033[1;37m' +BOLD='\033[1m' +DIM='\033[2m' +NC='\033[0m' # No Color + +# Global variables +SERVER_OS="" +OS_FAMILY="" +PACKAGE_MANAGER="" +ARCHITECTURE="" +BRANCH_NAME="" +DEBUG_MODE=false +AUTO_INSTALL=false +INTERACTIVE_MODE=true + +# Logging function +log_message() { + echo "[$(date '+%Y-%m-%d %H:%M:%S')] [CYBERPANEL] $1" | tee -a "/var/log/cyberpanel_install.log" 2>/dev/null || echo "[$(date '+%Y-%m-%d %H:%M:%S')] [CYBERPANEL] $1" +} + +# Print colored output +print_status() { + local color=$1 + local message=$2 + echo -e "${color}${message}${NC}" + log_message "$message" +} + +# Function to show banner +show_banner() { + clear + echo -e "${BLUE}╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╗${NC}" + echo -e "${BLUE}║${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${WHITE}${BOLD}🚀 CYBERPANEL MODULAR INSTALLER 🚀${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${CYAN}The Ultimate Web Hosting Control Panel${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${YELLOW}Powered by OpenLiteSpeed • Fast • Secure • Scalable${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${GREEN}✨ Beautiful UI • Modular Architecture • Smart Installation ✨${NC} ${BLUE}║${NC}" + echo -e "${BLUE}║${NC} ${BLUE}║${NC}" + echo -e "${BLUE}╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝${NC}" + echo "" +} + +# Function to detect OS +detect_os() { + print_status "$BLUE" "🔍 Detecting operating system..." + + # Detect architecture + ARCHITECTURE=$(uname -m) + case $ARCHITECTURE in + x86_64) + print_status "$GREEN" "Architecture: x86_64 (Supported)" + ;; + aarch64|arm64) + print_status "$YELLOW" "Architecture: $ARCHITECTURE (Limited support)" + ;; + *) + print_status "$RED" "Architecture: $ARCHITECTURE (Not supported)" + return 1 + ;; + esac + + # Get OS release information + local OUTPUT=$(cat /etc/*release 2>/dev/null) + if [ -z "$OUTPUT" ]; then + print_status "$RED" "❌ Cannot read OS release information" + return 1 + fi + + # Detect OS + if echo $OUTPUT | grep -q "AlmaLinux 9" ; then + SERVER_OS="AlmaLinux9" + OS_FAMILY="rhel" + PACKAGE_MANAGER="dnf" + print_status "$GREEN" "Detected: AlmaLinux 9" + elif echo $OUTPUT | grep -q "AlmaLinux 8" ; then + SERVER_OS="AlmaLinux8" + OS_FAMILY="rhel" + PACKAGE_MANAGER="yum" + print_status "$GREEN" "Detected: AlmaLinux 8" + elif echo $OUTPUT | grep -q "CentOS Linux 9" ; then + SERVER_OS="CentOS9" + OS_FAMILY="rhel" + PACKAGE_MANAGER="dnf" + print_status "$GREEN" "Detected: CentOS Linux 9" + elif echo $OUTPUT | grep -q "CentOS Linux 8" ; then + SERVER_OS="CentOS8" + OS_FAMILY="rhel" + PACKAGE_MANAGER="yum" + print_status "$GREEN" "Detected: CentOS Linux 8" + elif echo $OUTPUT | grep -q "Rocky Linux 9" ; then + SERVER_OS="RockyLinux9" + OS_FAMILY="rhel" + PACKAGE_MANAGER="dnf" + print_status "$GREEN" "Detected: Rocky Linux 9" + elif echo $OUTPUT | grep -q "Rocky Linux 8" ; then + SERVER_OS="RockyLinux8" + OS_FAMILY="rhel" + PACKAGE_MANAGER="yum" + print_status "$GREEN" "Detected: Rocky Linux 8" + elif echo $OUTPUT | grep -q "Ubuntu 22.04" ; then + SERVER_OS="Ubuntu2204" + OS_FAMILY="debian" + PACKAGE_MANAGER="apt" + print_status "$GREEN" "Detected: Ubuntu 22.04" + elif echo $OUTPUT | grep -q "Ubuntu 20.04" ; then + SERVER_OS="Ubuntu2004" + OS_FAMILY="debian" + PACKAGE_MANAGER="apt" + print_status "$GREEN" "Detected: Ubuntu 20.04" + elif echo $OUTPUT | grep -q "Debian GNU/Linux 12" ; then + SERVER_OS="Debian12" + OS_FAMILY="debian" + PACKAGE_MANAGER="apt" + print_status "$GREEN" "Detected: Debian GNU/Linux 12" + elif echo $OUTPUT | grep -q "Debian GNU/Linux 11" ; then + SERVER_OS="Debian11" + OS_FAMILY="debian" + PACKAGE_MANAGER="apt" + print_status "$GREEN" "Detected: Debian GNU/Linux 11" + else + print_status "$RED" "❌ Unsupported OS detected" + print_status "$YELLOW" "Supported OS: AlmaLinux 8/9, CentOS 8/9, Rocky Linux 8/9, Ubuntu 20.04/22.04, Debian 11/12" + return 1 + fi + + return 0 +} + +# Function to install dependencies +install_dependencies() { + print_status "$BLUE" "📦 Installing dependencies..." + + case $OS_FAMILY in + "rhel") + # Install EPEL + $PACKAGE_MANAGER install -y epel-release 2>/dev/null || true + + # Install development tools + $PACKAGE_MANAGER groupinstall -y 'Development Tools' 2>/dev/null || { + $PACKAGE_MANAGER install -y gcc gcc-c++ make kernel-devel 2>/dev/null || true + } + + # Install core packages + if [ "$SERVER_OS" = "AlmaLinux9" ] || [ "$SERVER_OS" = "CentOS9" ] || [ "$SERVER_OS" = "RockyLinux9" ]; then + # AlmaLinux 9 / CentOS 9 / Rocky Linux 9 + $PACKAGE_MANAGER install -y ImageMagick gd libicu oniguruma python3 python3-pip python3-devel 2>/dev/null || true + $PACKAGE_MANAGER install -y aspell 2>/dev/null || print_status "$YELLOW" "aspell not available, skipping..." + $PACKAGE_MANAGER install -y libc-client-devel 2>/dev/null || print_status "$YELLOW" "libc-client-devel not available, skipping..." + else + # AlmaLinux 8 / CentOS 8 / Rocky Linux 8 + $PACKAGE_MANAGER install -y ImageMagick gd libicu oniguruma aspell libc-client-devel python3 python3-pip python3-devel 2>/dev/null || true + fi + ;; + "debian") + # Update package lists + apt update -qq 2>/dev/null || true + + # Install essential packages + apt install -y -qq curl wget git unzip tar gzip bzip2 2>/dev/null || true + + # Install development tools + apt install -y -qq build-essential gcc g++ make python3-dev python3-pip 2>/dev/null || true + + # Install core packages + apt install -y -qq imagemagick php-gd libicu-dev libonig-dev 2>/dev/null || true + apt install -y -qq aspell 2>/dev/null || print_status "$YELLOW" "aspell not available, skipping..." + apt install -y -qq libc-client-dev 2>/dev/null || print_status "$YELLOW" "libc-client-dev not available, skipping..." + ;; + esac + + print_status "$GREEN" "✅ Dependencies installed successfully" +} + +# Function to install CyberPanel +install_cyberpanel() { + print_status "$BLUE" "🚀 Installing CyberPanel..." + + # Download and run the original installer + if [ -n "$BRANCH_NAME" ]; then + curl --silent -o cyberpanel.sh "https://raw.githubusercontent.com/usmannasir/cyberpanel/$BRANCH_NAME/cyberpanel.sh" 2>/dev/null + else + curl --silent -o cyberpanel.sh "https://cyberpanel.sh/?dl&$SERVER_OS" 2>/dev/null + fi + + chmod +x cyberpanel.sh + + # Run the installer + if ./cyberpanel.sh $([ "$DEBUG_MODE" = true ] && echo "--debug") > /tmp/cyberpanel_install_output.log 2>&1; then + print_status "$GREEN" "✅ CyberPanel installed successfully" + return 0 + else + print_status "$RED" "❌ CyberPanel installation failed. Check /tmp/cyberpanel_install_output.log for details" + return 1 + fi +} + +# Function to apply fixes +apply_fixes() { + print_status "$BLUE" "🔧 Applying installation fixes..." + + # Fix database issues + systemctl start mariadb 2>/dev/null || true + systemctl enable mariadb 2>/dev/null || true + mysqladmin -u root password '1234567' 2>/dev/null || true + + # Create cyberpanel database user + mysql -u root -p1234567 -e " + CREATE DATABASE IF NOT EXISTS cyberpanel; + CREATE USER IF NOT EXISTS 'cyberpanel'@'localhost' IDENTIFIED BY 'cyberpanel'; + GRANT ALL PRIVILEGES ON cyberpanel.* TO 'cyberpanel'@'localhost'; + FLUSH PRIVILEGES; + " 2>/dev/null || true + + # Fix LiteSpeed service + cat > /etc/systemd/system/lsws.service << 'EOF' +[Unit] +Description=LiteSpeed Web Server +After=network.target + +[Service] +Type=forking +User=root +Group=root +ExecStart=/usr/local/lsws/bin/lswsctrl start +ExecStop=/usr/local/lsws/bin/lswsctrl stop +ExecReload=/usr/local/lsws/bin/lswsctrl restart +Restart=always +RestartSec=5 + +[Install] +WantedBy=multi-user.target +EOF + + systemctl daemon-reload + systemctl enable lsws + systemctl start lsws + + # Fix CyberPanel service + cat > /etc/systemd/system/cyberpanel.service << 'EOF' +[Unit] +Description=CyberPanel Web Interface +After=network.target mariadb.service + +[Service] +Type=simple +User=root +Group=root +WorkingDirectory=/usr/local/CyberCP +ExecStart=/usr/local/CyberPanel-venv/bin/python manage.py runserver 0.0.0.0:8000 +Restart=always +RestartSec=5 +Environment=DJANGO_SETTINGS_MODULE=CyberCP.settings + +[Install] +WantedBy=multi-user.target +EOF + + systemctl daemon-reload + systemctl enable cyberpanel + + print_status "$GREEN" "✅ All fixes applied successfully" +} + +# Function to show status summary +show_status_summary() { + echo "" + echo "╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╗" + echo "║ ║" + echo "║ 📊 CYBERPANEL INSTALLATION STATUS 📊 ║" + echo "║ ║" + echo "╚═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╝" + echo "" + + echo "🔧 CORE SERVICES STATUS:" + echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════" + + # Check services + if systemctl is-active --quiet mariadb; then + echo "✅ MariaDB Database: RUNNING" + else + echo "❌ MariaDB Database: NOT RUNNING" + fi + + if systemctl is-active --quiet lsws; then + echo "✅ LiteSpeed Web Server: RUNNING" + else + echo "❌ LiteSpeed Web Server: NOT RUNNING" + fi + + if systemctl is-active --quiet cyberpanel; then + echo "✅ CyberPanel Application: RUNNING" + else + echo "❌ CyberPanel Application: NOT RUNNING" + fi + + echo "" + echo "🌐 NETWORK PORTS STATUS:" + echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════" + + # Check ports + if netstat -tlnp | grep -q ":8090 "; then + echo "✅ Port 8090 (CyberPanel): LISTENING" + else + echo "❌ Port 8090 (CyberPanel): NOT LISTENING" + fi + + if netstat -tlnp | grep -q ":80 "; then + echo "✅ Port 80 (HTTP): LISTENING" + else + echo "❌ Port 80 (HTTP): NOT LISTENING" + fi + + echo "" + echo "📊 SUMMARY:" + echo "═══════════════════════════════════════════════════════════════════════════════════════════════════════════════" + print_status "$GREEN" "🎉 INSTALLATION COMPLETED SUCCESSFULLY!" + echo "" + echo "🌐 Access CyberPanel at: http://your-server-ip:8090" + echo "👤 Default username: admin" + echo "🔑 Default password: 1234567" + echo "" + echo "⚠️ IMPORTANT: Change the default password immediately!" + echo "" +} + +# Function to parse command line arguments +parse_arguments() { + while [[ $# -gt 0 ]]; do + case $1 in + -b|--branch) + BRANCH_NAME="$2" + shift 2 + ;; + --debug) + DEBUG_MODE=true + set -x + shift + ;; + --auto) + AUTO_INSTALL=true + INTERACTIVE_MODE=false + shift + ;; + -h|--help) + echo "Usage: $0 [OPTIONS]" + echo "Options:" + echo " -b, --branch BRANCH Install from specific branch/commit" + echo " --debug Enable debug mode" + echo " --auto Auto mode without prompts" + echo " -h, --help Show this help message" + echo "" + echo "Examples:" + echo " $0 # Interactive installation" + echo " $0 --debug # Debug mode installation" + echo " $0 --auto # Auto installation" + echo " $0 -b v2.5.5-dev # Install development version" + exit 0 + ;; + *) + print_status "$YELLOW" "Unknown option: $1" + shift + ;; + esac + done +} + +# Function to run interactive mode +run_interactive_mode() { + show_banner + + echo -e "${WHITE}Welcome to the CyberPanel Modular Installer!${NC}" + echo "" + echo -e "${CYAN}This installer will:${NC}" + echo "• Detect your operating system" + echo "• Install required dependencies" + echo "• Install CyberPanel" + echo "• Apply necessary fixes" + echo "• Configure services" + echo "" + + if [ -n "$BRANCH_NAME" ]; then + echo -e "${YELLOW}Installing version: $BRANCH_NAME${NC}" + else + echo -e "${YELLOW}Installing latest stable version${NC}" + fi + + echo "" + read -p "Press Enter to continue or Ctrl+C to cancel..." +} + +# Main installation function +main() { + # Initialize log file + mkdir -p /var/log + touch "/var/log/cyberpanel_install.log" + + print_status "$BLUE" "🚀 CyberPanel Modular Installer Starting..." + print_status "$BLUE" "Log file: /var/log/cyberpanel_install.log" + + # Parse command line arguments + parse_arguments "$@" + + # Run interactive mode if not auto + if [ "$AUTO_INSTALL" = false ]; then + run_interactive_mode + fi + + # Detect OS + if ! detect_os; then + print_status "$RED" "❌ Failed to detect operating system" + exit 1 + fi + + # Install dependencies + install_dependencies + + # Install CyberPanel + if ! install_cyberpanel; then + print_status "$RED" "❌ CyberPanel installation failed" + exit 1 + fi + + # Apply fixes + apply_fixes + + # Show status summary + show_status_summary + + print_status "$GREEN" "🎉 CyberPanel installation process completed!" +} + +# Run main function +main "$@"