versionManagement: use usmannasir only, allow local installs, up-to-date if version higher

- versionManagment/versionManagement: detect git origin, compare only against usmannasir
- Local/fork installs: show up to date (no update nag)
- If current version > cyberpanel.net latest: show up to date
- cyberpanel_upgrade.sh: python3 -m venv for AlmaLinux 9/10, pip upgrade

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
master3395
2026-02-14 23:47:37 +01:00
parent 05ae9fe415
commit 0ca62a81c1
2 changed files with 114 additions and 48 deletions

View File

@@ -33,6 +33,27 @@ VERSION = '2.5.5'
BUILD = 'dev'
def _version_compare(a, b):
"""Return 1 if a > b, -1 if a < b, 0 if equal."""
def parse(v):
parts = []
for p in str(v).split('.'):
try:
parts.append(int(p))
except ValueError:
parts.append(0)
return parts
pa, pb = parse(a), parse(b)
for i in range(max(len(pa), len(pb))):
va = pa[i] if i < len(pa) else 0
vb = pb[i] if i < len(pb) else 0
if va > vb:
return 1
if va < vb:
return -1
return 0
@ensure_csrf_cookie
def renderBase(request):
template = 'baseTemplate/homePage.html'
@@ -45,27 +66,41 @@ def renderBase(request):
@ensure_csrf_cookie
def versionManagement(request):
currentVersion = VERSION
currentBuild = str(BUILD)
getVersion = requests.get('https://cyberpanel.net/version.txt')
latest = getVersion.json()
latestVersion = latest['version']
latestBuild = latest['build']
branch_ref = 'v%s.%s' % (latestVersion, latestBuild)
currentVersion = VERSION
currentBuild = str(BUILD)
u = "https://api.github.com/repos/usmannasir/cyberpanel/commits?sha=v%s.%s" % (latestVersion, latestBuild)
logging.writeToFile(u)
r = requests.get(u)
latestcomit = r.json()[0]['sha']
command = "git -C /usr/local/CyberCP/ rev-parse HEAD"
output = ProcessUtilities.outputExecutioner(command)
Currentcomt = output.rstrip("\n")
notechk = True
Currentcomt = ''
latestcomit = ''
if Currentcomt == latestcomit:
if _version_compare(currentVersion, latestVersion) > 0:
notechk = False
else:
remote_cmd = 'git -C /usr/local/CyberCP remote get-url origin 2>/dev/null || true'
remote_out = ProcessUtilities.outputExecutioner(remote_cmd)
is_usmannasir = 'usmannasir/cyberpanel' in (remote_out or '')
if is_usmannasir:
u = "https://api.github.com/repos/usmannasir/cyberpanel/commits?sha=%s" % branch_ref
logging.CyberCPLogFileWriter.writeToFile(u)
try:
r = requests.get(u, timeout=10)
r.raise_for_status()
latestcomit = r.json()[0]['sha']
except (requests.RequestException, IndexError, KeyError) as e:
logging.CyberCPLogFileWriter.writeToFile('[versionManagement] GitHub API failed: %s' % str(e))
head_cmd = 'git -C /usr/local/CyberCP rev-parse HEAD 2>/dev/null || true'
Currentcomt = ProcessUtilities.outputExecutioner(head_cmd).rstrip('\n')
if latestcomit and Currentcomt == latestcomit:
notechk = False
else:
notechk = False
template = 'baseTemplate/versionManagment.html'
finalData = {'build': currentBuild, 'currentVersion': currentVersion, 'latestVersion': latestVersion,
@@ -253,31 +288,41 @@ def getLoadAverage(request):
@ensure_csrf_cookie
def versionManagment(request):
## Get latest version
currentVersion = VERSION
currentBuild = str(BUILD)
getVersion = requests.get('https://cyberpanel.net/version.txt')
latest = getVersion.json()
latestVersion = latest['version']
latestBuild = latest['build']
branch_ref = 'v%s.%s' % (latestVersion, latestBuild)
## Get local version
currentVersion = VERSION
currentBuild = str(BUILD)
u = "https://api.github.com/repos/usmannasir/cyberpanel/commits?sha=v%s.%s" % (latestVersion, latestBuild)
logging.CyberCPLogFileWriter.writeToFile(u)
r = requests.get(u)
latestcomit = r.json()[0]['sha']
command = "git -C /usr/local/CyberCP/ rev-parse HEAD"
output = ProcessUtilities.outputExecutioner(command)
Currentcomt = output.rstrip("\n")
notechk = True
Currentcomt = ''
latestcomit = ''
if (Currentcomt == latestcomit):
if _version_compare(currentVersion, latestVersion) > 0:
notechk = False
else:
remote_cmd = 'git -C /usr/local/CyberCP remote get-url origin 2>/dev/null || true'
remote_out = ProcessUtilities.outputExecutioner(remote_cmd)
is_usmannasir = 'usmannasir/cyberpanel' in (remote_out or '')
if is_usmannasir:
u = "https://api.github.com/repos/usmannasir/cyberpanel/commits?sha=%s" % branch_ref
logging.CyberCPLogFileWriter.writeToFile(u)
try:
r = requests.get(u, timeout=10)
r.raise_for_status()
latestcomit = r.json()[0]['sha']
except (requests.RequestException, IndexError, KeyError) as e:
logging.CyberCPLogFileWriter.writeToFile('[versionManagment] GitHub API failed: %s' % str(e))
head_cmd = 'git -C /usr/local/CyberCP rev-parse HEAD 2>/dev/null || true'
Currentcomt = ProcessUtilities.outputExecutioner(head_cmd).rstrip('\n')
if latestcomit and Currentcomt == latestcomit:
notechk = False
else:
notechk = False
template = 'baseTemplate/versionManagment.html'
finalData = {'build': currentBuild, 'currentVersion': currentVersion, 'latestVersion': latestVersion,

View File

@@ -795,13 +795,20 @@ if [ "$Server_OS" = "Ubuntu" ]; then
fi
else
rm -rf /usr/local/CyberPanel
if [ -e /usr/bin/pip3 ]; then
PIP3="/usr/bin/pip3"
# AlmaLinux 9/10, Rocky 9: use python3 -m venv (no virtualenv pkg needed)
if [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "AlmaLinux9" ]] || [[ "$Server_OS" = "RockyLinux" ]]; then
if [[ "$Server_OS_Version" = "9" ]] || [[ "$Server_OS_Version" = "10" ]]; then
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] AlmaLinux/Rocky $Server_OS_Version: will use python3 -m venv, skipping virtualenv package" | tee -a /var/log/cyberpanel_upgrade_debug.log
else
if [ -e /usr/bin/pip3 ]; then PIP3="/usr/bin/pip3"; else PIP3="pip3.6"; fi
$PIP3 install --default-timeout=3600 virtualenv
Check_Return
fi
else
PIP3="pip3.6"
if [ -e /usr/bin/pip3 ]; then PIP3="/usr/bin/pip3"; else PIP3="pip3.6"; fi
$PIP3 install --default-timeout=3600 virtualenv
Check_Return
fi
$PIP3 install --default-timeout=3600 virtualenv
Check_Return
fi
if [[ -f /usr/local/CyberPanel/bin/python2 ]]; then
@@ -809,10 +816,15 @@ if [[ -f /usr/local/CyberPanel/bin/python2 ]]; then
rm -rf /usr/local/CyberPanel/bin
if [[ "$Server_OS" = "Ubuntu" ]] && ([[ "$Server_OS_Version" = "22" ]] || [[ "$Server_OS_Version" = "24" ]]); then
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Ubuntu $Server_OS_Version detected, using python3 -m venv..." | tee -a /var/log/cyberpanel_upgrade_debug.log
python3 -m venv /usr/local/CyberPanel
elif [[ "$Server_OS" = "CentOS" ]] && ([[ "$Server_OS_Version" = "9" ]] || [[ "$Server_OS_Version" = "10" ]]); then
PYTHON_PATH=$(which python3 2>/dev/null || which python3.9 2>/dev/null || echo "/usr/bin/python3")
virtualenv -p "$PYTHON_PATH" --system-site-packages /usr/local/CyberPanel
python3 -m venv --system-site-packages /usr/local/CyberPanel
elif [[ "$Server_OS" = "CentOS" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "AlmaLinux9" ]] || [[ "$Server_OS" = "RockyLinux" ]]; then
if [[ "$Server_OS_Version" = "9" ]] || [[ "$Server_OS_Version" = "10" ]]; then
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] AlmaLinux/Rocky $Server_OS_Version detected, using python3 -m venv..." | tee -a /var/log/cyberpanel_upgrade_debug.log
python3 -m venv --system-site-packages /usr/local/CyberPanel
else
PYTHON_PATH=$(which python3 2>/dev/null || which python3.9 2>/dev/null || echo "/usr/bin/python3")
virtualenv -p "$PYTHON_PATH" --system-site-packages /usr/local/CyberPanel
fi
else
virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel
fi
@@ -828,14 +840,19 @@ echo -e "\nNothing found, need fresh setup...\n"
if [[ "$Server_OS" = "Ubuntu" ]] && ([[ "$Server_OS_Version" = "22" ]] || [[ "$Server_OS_Version" = "24" ]]); then
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Ubuntu $Server_OS_Version detected, using python3 -m venv..." | tee -a /var/log/cyberpanel_upgrade_debug.log
python3 -m venv /usr/local/CyberPanel
elif [[ "$Server_OS" = "CentOS" ]] && ([[ "$Server_OS_Version" = "9" ]] || [[ "$Server_OS_Version" = "10" ]]); then
PYTHON_PATH=$(which python3 2>/dev/null || which python3.9 2>/dev/null || echo "/usr/bin/python3")
virtualenv -p "$PYTHON_PATH" --system-site-packages /usr/local/CyberPanel
elif [[ "$Server_OS" = "CentOS" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "AlmaLinux9" ]] || [[ "$Server_OS" = "RockyLinux" ]]; then
if [[ "$Server_OS_Version" = "9" ]] || [[ "$Server_OS_Version" = "10" ]]; then
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] AlmaLinux/Rocky $Server_OS_Version: using python3 -m venv (no virtualenv pkg needed)..." | tee -a /var/log/cyberpanel_upgrade_debug.log
python3 -m venv --system-site-packages /usr/local/CyberPanel
else
PYTHON_PATH=$(which python3 2>/dev/null || which python3.9 2>/dev/null || echo "/usr/bin/python3")
virtualenv -p "$PYTHON_PATH" --system-site-packages /usr/local/CyberPanel
fi
else
virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel
fi
# Check if the virtualenv command failed
# Check if the virtualenv/venv command failed
if [ $? -ne 0 ]; then
echo "virtualenv command failed."
@@ -861,11 +878,15 @@ if [ $? -ne 0 ]; then
if [ $? -eq 0 ]; then
echo "'packaging' module reinstalled and upgraded successfully."
if [[ "$Server_OS" = "Ubuntu" ]] && ([[ "$Server_OS_Version" = "22" ]] || [[ "$Server_OS_Version" = "24" ]]); then
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Ubuntu $Server_OS_Version detected, using python3 -m venv..." | tee -a /var/log/cyberpanel_upgrade_debug.log
python3 -m venv /usr/local/CyberPanel
elif [[ "$Server_OS" = "CentOS" ]] && ([[ "$Server_OS_Version" = "9" ]] || [[ "$Server_OS_Version" = "10" ]]); then
PYTHON_PATH=$(which python3 2>/dev/null || which python3.9 2>/dev/null || echo "/usr/bin/python3")
virtualenv -p "$PYTHON_PATH" --system-site-packages /usr/local/CyberPanel
echo -e "[$(date +"%Y-%m-%d %H:%M:%S")] Ubuntu: using python3 -m venv..." | tee -a /var/log/cyberpanel_upgrade_debug.log
python3 -m venv --system-site-packages /usr/local/CyberPanel
elif [[ "$Server_OS" = "CentOS" ]] || [[ "$Server_OS" = "AlmaLinux" ]] || [[ "$Server_OS" = "AlmaLinux9" ]] || [[ "$Server_OS" = "RockyLinux" ]]; then
if [[ "$Server_OS_Version" = "9" ]] || [[ "$Server_OS_Version" = "10" ]]; then
python3 -m venv --system-site-packages /usr/local/CyberPanel
else
PYTHON_PATH=$(which python3 2>/dev/null || which python3.9 2>/dev/null || echo "/usr/bin/python3")
virtualenv -p "$PYTHON_PATH" --system-site-packages /usr/local/CyberPanel
fi
else
virtualenv -p /usr/bin/python3 --system-site-packages /usr/local/CyberPanel
fi
@@ -888,7 +909,7 @@ fi
# shellcheck disable=SC1091
. /usr/local/CyberPanel/bin/activate
pip install --upgrade setuptools packaging
pip install --upgrade pip setuptools packaging
Download_Requirement