From 07cb786f0168d35d88f1b48b7aa075a6e926fd18 Mon Sep 17 00:00:00 2001 From: KraoESPfan1n <136997481+KraoESPfan1n@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:26:22 +0000 Subject: [PATCH] fix: add installer/upgrade logging --- cyberpanel_upgrade.sh | 17 ++++++++++++++++- install.sh | 33 ++++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/cyberpanel_upgrade.sh b/cyberpanel_upgrade.sh index d4356e500..a38ce81cb 100755 --- a/cyberpanel_upgrade.sh +++ b/cyberpanel_upgrade.sh @@ -14,16 +14,24 @@ Sudo_Test=$(set) #for SUDO check +# Logging setup +LOG_FILE="/var/log/installer.log" +mkdir -p /var/log 2>/dev/null || true +touch "$LOG_FILE" 2>/dev/null || true +exec >>"$LOG_FILE" 2>&1 +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Upgrade started: $0 $*" + # Re-exec with elevation if not running as root if [[ $(id -u) != 0 ]]; then SCRIPT_PATH="$(readlink -f "$0" 2>/dev/null || echo "$0")" for elevate in sudo doas run0 pkexec; do if command -v "$elevate" >/dev/null 2>&1; then - echo "Elevating with $elevate" + echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Elevating with $elevate" "$elevate" env "XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-}" "SUDO_USER=$(whoami)" "$SCRIPT_PATH" "$@" exit $? fi done + echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] ERROR: No elevation tool found." echo "Please install sudo, doas, run0 (systemd), or pkexec (polkit) to continue." exit 1 fi @@ -41,6 +49,7 @@ echo -e "\n\n========================================" > /var/log/cyberpanel_upg echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Starting CyberPanel Upgrade Script" >> /var/log/cyberpanel_upgrade_debug.log echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Old log files have been cleared" >> /var/log/cyberpanel_upgrade_debug.log echo -e "========================================\n" >> /var/log/cyberpanel_upgrade_debug.log +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Logging to ${LOG_FILE}" >> /var/log/cyberpanel_upgrade_debug.log #### this is temp code for csf @@ -372,6 +381,7 @@ mysql -uroot -p"$MySQL_Password" -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'loca Pre_Upgrade_Setup_Repository() { echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Pre_Upgrade_Setup_Repository started for OS: $Server_OS" | tee -a /var/log/cyberpanel_upgrade_debug.log +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Pre_Upgrade_Setup_Repository started for OS: $Server_OS" if [[ "$Server_OS" = "CentOS" ]] || [[ "$Server_OS" = "AlmaLinux9" ]] ; then echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Setting up repositories for $Server_OS..." | tee -a /var/log/cyberpanel_upgrade_debug.log @@ -606,6 +616,7 @@ fi Download_Requirement() { echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Starting Download_Requirement function..." | tee -a /var/log/cyberpanel_upgrade_debug.log +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Download_Requirement started" for i in {1..50}; do if [[ "$Server_OS_Version" = "22" ]] || [[ "$Server_OS_Version" = "24" ]] || [[ "$Server_OS_Version" = "9" ]] || [[ "$Server_OS_Version" = "10" ]]; then @@ -639,6 +650,7 @@ Pre_Upgrade_Required_Components() { # Check if CyberCP directory exists but is incomplete/damaged echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Checking CyberCP directory integrity..." | tee -a /var/log/cyberpanel_upgrade_debug.log +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Pre_Upgrade_Required_Components started" # Define essential CyberCP components CYBERCP_ESSENTIAL_DIRS=( @@ -884,6 +896,7 @@ Pre_Upgrade_Branch_Input() { Main_Upgrade() { echo -e "\n[$(date +"%Y-%m-%d %H:%M:%S")] Starting Main_Upgrade function..." | tee -a /var/log/cyberpanel_upgrade_debug.log echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Running: /usr/local/CyberPanel/bin/python upgrade.py $Branch_Name" | tee -a /var/log/cyberpanel_upgrade_debug.log +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Main_Upgrade started for branch ${Branch_Name}" # Run upgrade.py and capture output upgrade_output=$(/usr/local/CyberPanel/bin/python upgrade.py "$Branch_Name" 2>&1) @@ -1191,6 +1204,7 @@ echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Main_Upgrade function completed" | tee - } Post_Upgrade_System_Tweak() { + echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Post_Upgrade_System_Tweak started" if [[ "$Server_OS" = "CentOS" ]] ; then #for cenots 7/8 @@ -1510,6 +1524,7 @@ systemctl restart lscpd } Post_Install_Display_Final_Info() { +echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Post_Install_Display_Final_Info started" echo -e "\n" echo "╔═══════════════════════════════════════════════════════════════════════════════════════════════════════════════╗" echo "║ ║" diff --git a/install.sh b/install.sh index 649c5eb45..4d792e71f 100755 --- a/install.sh +++ b/install.sh @@ -3,17 +3,25 @@ # CyberPanel v2.5.5-dev Installer # Simplified approach similar to stable branch +# Logging setup +LOG_FILE="/var/log/installer.log" +mkdir -p /var/log 2>/dev/null || true +touch "$LOG_FILE" 2>/dev/null || true +exec >>"$LOG_FILE" 2>&1 +echo "[$(date +"%Y-%m-%d %H:%M:%S")] Installer started: $0 $*" + # Re-exec with elevation if not running as root if [ "$(id -u)" -ne 0 ]; then SCRIPT_PATH="$(readlink -f "$0" 2>/dev/null || echo "$0")" for elevate in sudo doas run0 pkexec; do if command -v "$elevate" >/dev/null 2>&1; then - echo "Elevating with $elevate" + echo "[$(date +"%Y-%m-%d %H:%M:%S")] Elevating with $elevate" "$elevate" env "XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-}" "SUDO_USER=$(whoami)" "$SCRIPT_PATH" "$@" exit $? fi done + echo "[$(date +"%Y-%m-%d %H:%M:%S")] ERROR: No elevation tool found." echo "Please install sudo, doas, run0 (systemd), or pkexec (polkit) to continue." exit 1 fi @@ -45,9 +53,9 @@ check_disk_space() { available_gb=$(df / 2>/dev/null | awk 'NR==2 {print $4}' | awk '{printf "%.0f", $1/1024/1024}') fi if [[ "$available_gb" =~ ^[0-9]+$ ]]; then - echo "💾 Disk space: ${available_gb}GB available (10GB minimum required)" + echo "[$(date +"%Y-%m-%d %H:%M:%S")] Disk space: ${available_gb}GB available (10GB minimum required)" if [ "$available_gb" -lt 10 ]; then - echo "⚠️ Warning: Less than 10GB available. Installation may fail." + echo "[$(date +"%Y-%m-%d %H:%M:%S")] WARNING: Less than 10GB available. Installation may fail." fi fi fi @@ -55,6 +63,8 @@ check_disk_space() { # Detect OS and set SERVER_OS (similar to stable branch) OUTPUT=$(cat /etc/*release 2>/dev/null || echo "") +echo "[$(date +"%Y-%m-%d %H:%M:%S")] Detected release info:" +echo "$OUTPUT" if echo "$OUTPUT" | grep -q "CentOS Linux 7" ; then echo "Checking and installing curl and wget" @@ -119,11 +129,14 @@ else exit 1 fi +# Check disk space +echo "[$(date +"%Y-%m-%d %H:%M:%S")] SERVER_OS=$SERVER_OS BRANCH_NAME=$BRANCH_NAME" + # Check disk space check_disk_space # Download and execute cyberpanel.sh for the specified branch -echo "Downloading CyberPanel installer for branch: $BRANCH_NAME" +echo "[$(date +"%Y-%m-%d %H:%M:%S")] Downloading CyberPanel installer for branch: $BRANCH_NAME" # Use absolute path for downloaded script in a writable directory TEMP_DIR="/tmp" @@ -142,14 +155,15 @@ if [ "$BRANCH_NAME" = "v2.5.5-dev" ] || [ "$BRANCH_NAME" = "stable" ]; then chmod 755 "$SCRIPT_PATH" 2>/dev/null || true # Verify it's executable if [ -x "$SCRIPT_PATH" ]; then - echo "✅ Downloaded cyberpanel.sh from branch $BRANCH_NAME" + echo "[$(date +"%Y-%m-%d %H:%M:%S")] Downloaded cyberpanel.sh from branch $BRANCH_NAME" # Change to temp directory and execute with bash # Use absolute path to avoid any relative path issues cd "$TEMP_DIR" || cd /tmp || cd / + echo "[$(date +"%Y-%m-%d %H:%M:%S")] Executing $SCRIPT_PATH" bash "$SCRIPT_PATH" "$@" exit $? else - echo "⚠️ Warning: Could not make script executable, trying alternative method..." + echo "[$(date +"%Y-%m-%d %H:%M:%S")] WARNING: Could not make script executable, trying alternative method..." cd "$TEMP_DIR" || cd /tmp || cd / bash -c "bash '$SCRIPT_PATH' $*" exit $? @@ -166,14 +180,15 @@ if curl --silent -o "$SCRIPT_PATH" "https://cyberpanel.sh/?dl&$SERVER_OS" 2>/dev chmod 755 "$SCRIPT_PATH" 2>/dev/null || true # Verify it's executable if [ -x "$SCRIPT_PATH" ]; then - echo "✅ Downloaded cyberpanel.sh from standard source" + echo "[$(date +"%Y-%m-%d %H:%M:%S")] Downloaded cyberpanel.sh from standard source" # Change to temp directory and execute with bash # Use absolute path to avoid any relative path issues cd "$TEMP_DIR" || cd /tmp || cd / + echo "[$(date +"%Y-%m-%d %H:%M:%S")] Executing $SCRIPT_PATH" bash "$SCRIPT_PATH" "$@" exit $? else - echo "⚠️ Warning: Could not make script executable, trying alternative method..." + echo "[$(date +"%Y-%m-%d %H:%M:%S")] WARNING: Could not make script executable, trying alternative method..." cd "$TEMP_DIR" || cd /tmp || cd / bash -c "bash '$SCRIPT_PATH' $*" exit $? @@ -182,6 +197,6 @@ if curl --silent -o "$SCRIPT_PATH" "https://cyberpanel.sh/?dl&$SERVER_OS" 2>/dev fi # If we get here, download failed -echo "❌ Failed to download cyberpanel.sh" +echo "[$(date +"%Y-%m-%d %H:%M:%S")] ERROR: Failed to download cyberpanel.sh" echo "Please check your internet connection and try again" exit 1