Files
CyberPanel/plogical/upgrade.py

108 lines
2.7 KiB
Python
Raw Normal View History

2017-10-24 19:16:36 +05:00
import os
import shlex
import subprocess
2018-04-23 19:23:03 +05:00
import shutil
2017-10-24 19:16:36 +05:00
import requests
2018-04-23 19:23:03 +05:00
import json
2018-05-14 22:26:25 +05:00
import time
2017-10-24 19:16:36 +05:00
class Upgrade:
logPath = "/usr/local/lscp/logs/upgradeLog"
@staticmethod
2018-04-23 19:23:03 +05:00
def downloadLink():
url = "https://cyberpanel.net/version.txt"
r = requests.get(url, verify=True)
data = json.loads(r.text)
version_number = str(data['version'])
version_build = str(data['build'])
return ("Temp.tar.gz")
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
@staticmethod
def upgrade():
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
os.chdir("/usr/local")
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
versionNumbring = Upgrade.downloadLink()
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
## Download latest version.
2017-10-24 19:16:36 +05:00
command = "wget https://cyberpanel.net/CyberPanel" + versionNumbring
2018-04-23 19:23:03 +05:00
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
## Backup settings file.
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
shutil.copy("/usr/local/CyberCP/CyberCP/settings.py","/usr/local/settings.py")
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
## Remove Core Files
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
command = "rm -rf /usr/local/CyberCP"
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
## Extract Latest files
2017-10-24 19:16:36 +05:00
command = "tar zxf CyberPanel" + versionNumbring
2018-04-23 19:23:03 +05:00
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
## Copy settings file
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
shutil.copy("/usr/local/settings.py", "/usr/local/CyberCP/CyberCP/")
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
## Move static files
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
command = "rm -rf /usr/local/lscp/cyberpanel/static"
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
command = "mv /usr/local/CyberCP/static /usr/local/lscp/cyberpanel"
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
## Copy File manager files
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
command = "rm -rf /usr/local/lsws/Example/html/FileManager"
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
command = "mv /usr/local/CyberCP/install/FileManager /usr/local/lsws/Example/html"
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
## Install TLDExtract
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
command = "pip install tldextract"
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-05-06 14:18:41 +05:00
## Install dnspython
#command = "pip install dnspython"
#subprocess.call(shlex.split(command))
2018-04-23 19:23:03 +05:00
## Change File manager permissions
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
command = "chmod -R 777 /usr/local/lsws/Example/html/FileManager"
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
## MailServer Model Changes
os.chdir('/usr/local/CyberCP')
command = "echo 'ALTER TABLE e_forwardings DROP PRIMARY KEY;ALTER TABLE e_forwardings ADD id INT AUTO_INCREMENT PRIMARY KEY;' | python manage.py dbshell"
subprocess.check_output(command, shell=True)
2018-04-23 19:23:03 +05:00
## Restart Gunicorn
2017-10-24 19:16:36 +05:00
2018-04-23 19:23:03 +05:00
command = "systemctl restart gunicorn.socket"
subprocess.call(shlex.split(command))
2017-10-24 19:16:36 +05:00
2018-05-14 22:26:25 +05:00
time.sleep(3)
2018-04-23 19:23:03 +05:00
## Upgrade version
2017-10-24 19:16:36 +05:00
r = requests.post("http://localhost:5003/base/upgradeVersion")
2017-10-24 19:16:36 +05:00
print("Upgrade Completed.")
2018-04-23 19:23:03 +05:00
Upgrade.upgrade()