mirror of
https://github.com/usmannasir/cyberpanel.git
synced 2026-01-03 22:29:43 +01:00
potential bug fix in upgrade
This commit is contained in:
@@ -16,9 +16,16 @@ Sudo_Test=$(set)
|
||||
|
||||
Set_Default_Variables() {
|
||||
|
||||
# Initialize debug log
|
||||
# Clear old log files
|
||||
echo -e "Clearing old log files..."
|
||||
rm -f /var/log/cyberpanel_upgrade_debug.log
|
||||
rm -f /var/log/installLogs.txt
|
||||
rm -f /var/log/upgradeLogs.txt
|
||||
|
||||
# Initialize new debug log
|
||||
echo -e "\n\n========================================" > /var/log/cyberpanel_upgrade_debug.log
|
||||
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
|
||||
|
||||
#### this is temp code for csf
|
||||
@@ -764,44 +771,25 @@ rm -rf /usr/local/CyberPanelTemp
|
||||
fi
|
||||
|
||||
echo -e "\n[$(date +"%Y-%m-%d %H:%M:%S")] Starting post-upgrade cleanup..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Removing old CyberCP virtual environment directories..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
# Check if we need to recreate due to Python 2
|
||||
NEEDS_RECREATE=0
|
||||
if [[ -f /usr/local/CyberCP/bin/python2 ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Found Python 2 in CyberCP, will recreate with Python 3..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
NEEDS_RECREATE=1
|
||||
fi
|
||||
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Removing old CyberCP virtual environment directories..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
rm -rf /usr/local/CyberCP/bin
|
||||
rm -rf /usr/local/CyberCP/lib
|
||||
rm -rf /usr/local/CyberCP/lib64
|
||||
rm -rf /usr/local/CyberCP/pyvenv.cfg
|
||||
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Checking CyberCP virtual environment status..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Checking CyberCP virtual environment status after cleanup..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
if [[ -f /usr/local/CyberCP/bin/python2 ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Found Python 2 in CyberCP, recreating with Python 3..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
rm -rf /usr/local/CyberCP/bin
|
||||
|
||||
# Try to create virtualenv, capture both stdout and stderr
|
||||
virtualenv_output=$(virtualenv -p /usr/bin/python3 /usr/local/CyberCP 2>&1)
|
||||
VENV_CODE=$?
|
||||
echo "$virtualenv_output" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
# Check if TypeError occurred
|
||||
if echo "$virtualenv_output" | grep -q "TypeError"; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] WARNING: TypeError detected during virtualenv creation, but checking if environment was created anyway..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
# Check if virtualenv was actually created despite the error
|
||||
if [[ -f /usr/local/CyberCP/bin/activate ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Virtual environment created successfully despite TypeError" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
VENV_CODE=0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Virtualenv creation returned code: $VENV_CODE" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
if [[ $VENV_CODE -ne 0 ]]; then
|
||||
Check_Return "Virtualenv creation failed"
|
||||
fi
|
||||
elif [[ -d /usr/local/CyberCP/bin/ ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] CyberCP virtualenv already exists, skipping recreation" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
echo -e "\nNo need to re-setup virtualenv at /usr/local/CyberCP...\n"
|
||||
else
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Creating new CyberCP virtual environment..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
# After removing directories, we always need to recreate
|
||||
if [[ $NEEDS_RECREATE -eq 1 ]] || [[ ! -d /usr/local/CyberCP/bin ]]; then
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Creating/recreating CyberCP virtual environment with Python 3..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
# First ensure the directory exists
|
||||
mkdir -p /usr/local/CyberCP
|
||||
@@ -826,6 +814,9 @@ else
|
||||
if [[ $VENV_CODE -ne 0 ]]; then
|
||||
Check_Return "Virtualenv creation failed"
|
||||
fi
|
||||
else
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] CyberCP virtualenv already exists, skipping recreation" | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
echo -e "\nNo need to re-setup virtualenv at /usr/local/CyberCP...\n"
|
||||
fi
|
||||
|
||||
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Removing old requirements file..." | tee -a /var/log/cyberpanel_upgrade_debug.log
|
||||
|
||||
@@ -183,6 +183,28 @@ class Upgrade:
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def executioner_silent(command, component, do_exit=0, shell=False):
|
||||
"""Silent version of executioner that suppresses all output"""
|
||||
try:
|
||||
FNULL = open(os.devnull, 'w')
|
||||
count = 0
|
||||
while True:
|
||||
if shell == False:
|
||||
res = subprocess.call(shlex.split(command), stdout=FNULL, stderr=FNULL)
|
||||
else:
|
||||
res = subprocess.call(command, stdout=FNULL, stderr=FNULL, shell=True)
|
||||
if res != 0:
|
||||
count = count + 1
|
||||
if count == 3:
|
||||
FNULL.close()
|
||||
return False
|
||||
else:
|
||||
FNULL.close()
|
||||
return True
|
||||
except:
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def updateRepoURL():
|
||||
@@ -334,17 +356,21 @@ class Upgrade:
|
||||
except:
|
||||
pass
|
||||
|
||||
command = 'wget -O /usr/local/CyberCP/public/phpmyadmin.zip https://github.com/usmannasir/cyberpanel/raw/stable/phpmyadmin.zip'
|
||||
Upgrade.executioner(command, 0)
|
||||
Upgrade.stdOut("Installing phpMyAdmin...", 0)
|
||||
|
||||
command = 'wget -q -O /usr/local/CyberCP/public/phpmyadmin.zip https://github.com/usmannasir/cyberpanel/raw/stable/phpmyadmin.zip'
|
||||
Upgrade.executioner_silent(command, 'Download phpMyAdmin')
|
||||
|
||||
command = 'unzip /usr/local/CyberCP/public/phpmyadmin.zip -d /usr/local/CyberCP/public/'
|
||||
Upgrade.executioner(command, 0)
|
||||
command = 'unzip -q /usr/local/CyberCP/public/phpmyadmin.zip -d /usr/local/CyberCP/public/'
|
||||
Upgrade.executioner_silent(command, 'Extract phpMyAdmin')
|
||||
|
||||
command = 'mv /usr/local/CyberCP/public/phpMyAdmin-*-all-languages /usr/local/CyberCP/public/phpmyadmin'
|
||||
subprocess.call(command, shell=True)
|
||||
subprocess.call(command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
|
||||
command = 'rm -f /usr/local/CyberCP/public/phpmyadmin.zip'
|
||||
Upgrade.executioner(command, 0)
|
||||
Upgrade.executioner_silent(command, 'Cleanup phpMyAdmin zip')
|
||||
|
||||
Upgrade.stdOut("phpMyAdmin installation completed.", 0)
|
||||
|
||||
## Write secret phrase
|
||||
|
||||
@@ -467,11 +493,13 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout';
|
||||
|
||||
count = 1
|
||||
|
||||
Upgrade.stdOut("Installing SnappyMail...", 0)
|
||||
|
||||
while (1):
|
||||
command = 'wget https://github.com/the-djmaze/snappymail/releases/download/v%s/snappymail-%s.zip' % (
|
||||
command = 'wget -q https://github.com/the-djmaze/snappymail/releases/download/v%s/snappymail-%s.zip' % (
|
||||
Upgrade.SnappyVersion, Upgrade.SnappyVersion)
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
res = subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
if res != 0:
|
||||
count = count + 1
|
||||
if count == 3:
|
||||
@@ -487,10 +515,10 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout';
|
||||
shutil.rmtree('/usr/local/CyberCP/public/snappymail')
|
||||
|
||||
while (1):
|
||||
command = 'unzip snappymail-%s.zip -d /usr/local/CyberCP/public/snappymail' % (Upgrade.SnappyVersion)
|
||||
command = 'unzip -q snappymail-%s.zip -d /usr/local/CyberCP/public/snappymail' % (Upgrade.SnappyVersion)
|
||||
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
res = subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
if res != 0:
|
||||
count = count + 1
|
||||
if count == 3:
|
||||
@@ -511,7 +539,7 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout';
|
||||
while (1):
|
||||
command = 'find . -type d -exec chmod 755 {} \;'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
res = subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
if res != 0:
|
||||
count = count + 1
|
||||
if count == 3:
|
||||
@@ -526,7 +554,7 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout';
|
||||
while (1):
|
||||
command = 'find . -type f -exec chmod 644 {} \;'
|
||||
cmd = shlex.split(command)
|
||||
res = subprocess.call(cmd)
|
||||
res = subprocess.call(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
if res != 0:
|
||||
count = count + 1
|
||||
if count == 3:
|
||||
@@ -552,13 +580,13 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout';
|
||||
writeToFile.close()
|
||||
|
||||
command = "mkdir -p /usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/configs/"
|
||||
Upgrade.executioner(command, 'mkdir snappymail configs', 0)
|
||||
Upgrade.executioner_silent(command, 'mkdir snappymail configs', 0)
|
||||
|
||||
command = f'wget -O /usr/local/CyberCP/snappymail_cyberpanel.php https://raw.githubusercontent.com/the-djmaze/snappymail/master/integrations/cyberpanel/install.php'
|
||||
Upgrade.executioner(command, 'verify certificate', 0)
|
||||
command = f'wget -q -O /usr/local/CyberCP/snappymail_cyberpanel.php https://raw.githubusercontent.com/the-djmaze/snappymail/master/integrations/cyberpanel/install.php'
|
||||
Upgrade.executioner_silent(command, 'verify certificate', 0)
|
||||
|
||||
command = f'/usr/local/lsws/lsphp80/bin/php /usr/local/CyberCP/snappymail_cyberpanel.php'
|
||||
Upgrade.executioner(command, 'verify certificate', 0)
|
||||
Upgrade.executioner_silent(command, 'verify certificate', 0)
|
||||
|
||||
# labsPath = '/usr/local/lscp/cyberpanel/rainloop/data/_data_/_default_/configs/application.ini'
|
||||
|
||||
@@ -680,6 +708,8 @@ $cfg['Servers'][$i]['LogoutURL'] = 'phpmyadminsignin.php?logout';
|
||||
# Upgrade.executioner(command, 'verify certificate', 0)
|
||||
|
||||
os.chdir(cwd)
|
||||
|
||||
Upgrade.stdOut("SnappyMail installation completed.", 0)
|
||||
|
||||
except BaseException as msg:
|
||||
Upgrade.stdOut(str(msg) + " [downoad_and_install_raindloop]", 0)
|
||||
@@ -2752,10 +2782,10 @@ echo $oConfig->Save() ? 'Done' : 'Error';
|
||||
Upgrade.executioner(command, 0)
|
||||
|
||||
command = '/usr/local/lsws/lsphp72/bin/php /usr/local/CyberCP/public/snappymail.php'
|
||||
Upgrade.executioner(command, 0)
|
||||
Upgrade.executioner_silent(command, 'Configure SnappyMail')
|
||||
|
||||
command = 'chmod 600 /usr/local/CyberCP/public/snappymail.php'
|
||||
Upgrade.executioner(command, 0)
|
||||
Upgrade.executioner_silent(command, 'Secure SnappyMail config')
|
||||
|
||||
###
|
||||
|
||||
|
||||
Reference in New Issue
Block a user