Merge pull request #4 from KraoESPfan1n/fix/elevate-install-upgrade

fix: auto-elevate installer/upgrade
This commit is contained in:
Master3395
2026-01-30 23:31:55 +01:00
committed by GitHub
2 changed files with 84 additions and 39 deletions

59
cyberpanel_upgrade.sh Normal file → Executable file
View File

@@ -14,6 +14,28 @@
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 -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
Set_Default_Variables() {
# Clear old log files
@@ -27,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
@@ -91,12 +114,6 @@ echo -e "\n${1}" >> /var/log/upgradeLogs.txt
Check_Root() {
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."
exit
fi
if [[ $(id -u) != 0 ]] >/dev/null; then
echo -e "\nYou must run as root user to install CyberPanel...\n"
echo -e "or run the following command: (do NOT miss the quotes)"
@@ -149,10 +166,10 @@ 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 "AlmaLinux-8|AlmaLinux-9|AlmaLinux-10" /etc/os-release ; then
elif grep -q -E "AlmaLinux( |-)?8|AlmaLinux( |-)?9|AlmaLinux( |-)?10" /etc/os-release ; then
Server_OS="AlmaLinux"
# Set specific version for AlmaLinux 9+ to use dnf instead of yum
if grep -q -E "AlmaLinux-9|AlmaLinux-10" /etc/os-release ; then
if grep -q -E "AlmaLinux( |-)?9|AlmaLinux( |-)?10" /etc/os-release ; then
Server_OS="AlmaLinux9"
fi
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
@@ -364,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
@@ -527,7 +545,7 @@ elif [[ "$Server_OS" = "Ubuntu" ]] ; then
groupadd nobody
fi
apt update -y
apt-get update -y
export DEBIAN_FRONTEND=noninteractive ; apt-get -o Dpkg::Options::="--force-confold" upgrade -y
if [[ "$Server_OS_Version" = "22" ]] || [[ "$Server_OS_Version" = "24" ]] ; then
@@ -577,7 +595,7 @@ elif [[ "$Server_OS" = "Ubuntu" ]] ; then
#fix ubuntu 20 webmail login issue
rm -f /etc/apt/sources.list.d/dovecot.list
apt update
apt-get update -y
DEBIAN_FRONTEND=noninteractive DEBIAN_PRIORITY=critical apt -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade -y
fi
#all pre-upgrade operation for Ubuntu 20
@@ -598,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
@@ -631,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=(
@@ -860,22 +880,6 @@ fi
}
Pre_Upgrade_Setup_Git_URL() {
if [[ $Server_Country != "CN" ]] ; then
Git_User="usmannasir"
Git_Content_URL="https://raw.githubusercontent.com/${Git_User}/cyberpanel"
Git_Clone_URL="https://github.com/${Git_User}/cyberpanel.git"
else
Git_User="qtwrk"
Git_Content_URL="https://gitee.com/${Git_User}/cyberpanel/raw"
Git_Clone_URL="https://gitee.com/${Git_User}/cyberpanel.git"
fi
if [[ "$Debug" = "On" ]] ; then
Debug_Log "Git_URL" "$Git_Content_URL"
fi
}
Pre_Upgrade_Branch_Input() {
echo -e "\nPress the Enter key to continue with latest version, or enter specific version such as: \e[31m2.3.4\e[39m , \e[31m2.4.4\e[39m ...etc"
echo -e "\nIf nothing is input in 10 seconds, script will proceed with the latest stable version. "
@@ -892,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)
@@ -1199,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
@@ -1518,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 "║ ║"

64
install.sh Normal file → Executable file
View File

@@ -1,15 +1,46 @@
#!/bin/sh
#!/usr/bin/env bash
# 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 "[$(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
# Determine branch from arguments or use default
BRANCH_NAME="v2.5.5-dev"
for arg in "$@"; do
case "$arg" in
while [ "$#" -gt 0 ]; do
case "$1" in
-b|--branch)
BRANCH_NAME="$2"
shift 2
if [ -n "${2:-}" ]; then
BRANCH_NAME="$2"
shift 2
else
echo "❌ Missing value for $1"
exit 1
fi
;;
*)
shift
;;
esac
done
@@ -22,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
@@ -32,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"
@@ -96,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"
@@ -119,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 $?
@@ -143,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 $?
@@ -159,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