From a8a236e74c58fb7e56b3d2ace5b2dc1eb403c8f0 Mon Sep 17 00:00:00 2001 From: Aoody743 Date: Tue, 12 May 2026 15:25:45 +0800 Subject: [PATCH] Use PowerLinux releases for updates --- scripts/init.d/mw.tpl | 16 ++--- scripts/install.sh | 4 +- scripts/install/macos.sh | 12 ++-- scripts/install_dev.sh | 22 ++++--- scripts/update.sh | 2 +- scripts/update_dev.sh | 20 +++--- web/utils/system/update.py | 131 ++++++++++++++++++++++++++++++++----- 7 files changed, 158 insertions(+), 49 deletions(-) diff --git a/scripts/init.d/mw.tpl b/scripts/init.d/mw.tpl index aa1307f5c..9bb5b69b8 100755 --- a/scripts/init.d/mw.tpl +++ b/scripts/init.d/mw.tpl @@ -375,8 +375,8 @@ mw_install(){ fi mw_common_proxy - echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/install.sh")" - bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/install.sh") + echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/AndyXeCM/PowerLinux/main/scripts/install.sh")" + bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/AndyXeCM/PowerLinux/main/scripts/install.sh") } mw_update() @@ -387,8 +387,8 @@ mw_update() fi mw_common_proxy - echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh")" - bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/master/scripts/update.sh") + echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/AndyXeCM/PowerLinux/main/scripts/update.sh")" + bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/AndyXeCM/PowerLinux/main/scripts/update.sh") } mw_update_dev() @@ -399,8 +399,8 @@ mw_update_dev() fi mw_common_proxy - echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh")" - bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh") + echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/AndyXeCM/PowerLinux/main/scripts/update_dev.sh")" + bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/AndyXeCM/PowerLinux/main/scripts/update_dev.sh") cd ${PANEL_DIR} } @@ -412,8 +412,8 @@ mw_update_venv() rm -rf ${PANEL_DIR}/lib mw_common_proxy - echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh")" - bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/dev/scripts/update_dev.sh") + echo "bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/AndyXeCM/PowerLinux/main/scripts/update_dev.sh")" + bash <(curl -fsSL "${HTTP_PREFIX}raw.githubusercontent.com/AndyXeCM/PowerLinux/main/scripts/update_dev.sh") cd ${PANEL_DIR} } diff --git a/scripts/install.sh b/scripts/install.sh index 0561aff95..40ac13d75 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -15,7 +15,7 @@ ERROR='[\033[31mERROR\033[0m]' WORKING='[\033[34m*\033[0m]' REPO_OWNER="AndyXeCM" REPO_NAME="PowerLinux" -REPO_BRANCH="master" +REPO_BRANCH="main" # LANG=en_US.UTF-8 @@ -152,7 +152,7 @@ if [ "$LOCAL_ADDR" != "common" ];then fi if [ -f /etc/motd ];then - echo "welcome to mdserver-web panel" > /etc/motd + echo "welcome to PowerLinux panel" > /etc/motd fi startTime=`date +%s` diff --git a/scripts/install/macos.sh b/scripts/install/macos.sh index 42a5c3983..51158206c 100755 --- a/scripts/install/macos.sh +++ b/scripts/install/macos.sh @@ -5,6 +5,9 @@ LANG=en_US.UTF-8 USER=$(who | sed -n "2,1p" |awk '{print $1}') DEV="/Users/${USER}/Desktop/mwdev" +REPO_OWNER="AndyXeCM" +REPO_NAME="PowerLinux" +REPO_BRANCH="main" mkdir -p $DEV @@ -31,11 +34,12 @@ brew install pcre2 libxpm libelf brew install automake icu4c libmemcached if [ ! -d $DEV/server/mdserver-web ]; then - wget -O /tmp/master.zip https://codeload.github.com/midoks/mdserver-web/zip/master + wget -O /tmp/master.zip https://codeload.github.com/${REPO_OWNER}/${REPO_NAME}/zip/${REPO_BRANCH} + TARBALL_DIR=$(unzip -Z1 /tmp/master.zip | head -1 | cut -d/ -f1) cd /tmp && unzip /tmp/master.zip - mv /tmp/mdserver-web-master $DEV/server/mdserver-web + mv /tmp/${TARBALL_DIR} $DEV/server/mdserver-web rm -f /tmp/master.zip - rm -rf /tmp/mdserver-web-master + rm -rf /tmp/${TARBALL_DIR} fi if [ ! -d $DEV/server/lib ]; then @@ -57,4 +61,4 @@ cd $DEV/server/mdserver-web && ./cli.sh stop sleep 5 cd $DEV/server/mdserver-web && ./scripts/init.d/mw default -cd $DEV/server/mdserver-web && ./cli.sh debug \ No newline at end of file +cd $DEV/server/mdserver-web && ./cli.sh debug diff --git a/scripts/install_dev.sh b/scripts/install_dev.sh index 97e16a742..e15bdd082 100755 --- a/scripts/install_dev.sh +++ b/scripts/install_dev.sh @@ -16,6 +16,9 @@ WORKING='[\033[34m*\033[0m]' # LANG=en_US.UTF-8 is64bit=`getconf LONG_BIT` +REPO_OWNER="AndyXeCM" +REPO_NAME="PowerLinux" +REPO_BRANCH="main" if [ -f /www/server/mdserver-web/tools.py ];then @@ -25,8 +28,8 @@ if [ -f /www/server/mdserver-web/tools.py ];then exit 0 fi -echo -e "您正在安装的是\033[31mmdserver-web测试版\033[0m,非开发测试用途请使用正式版 install.sh !" -echo -e "You are installing\033[31m mdserver-web dev version\033[0m, normally use install.sh for production.\n" +echo -e "您正在安装的是\033[31mPowerLinux测试版\033[0m,非开发测试用途请使用正式版 install.sh !" +echo -e "You are installing\033[31m PowerLinux dev version\033[0m, normally use install.sh for production.\n" sleep 1 LOG_FILE=/var/log/mw-install.log @@ -153,7 +156,7 @@ if [ "$LOCAL_ADDR" != "common" ];then fi if [ -f /etc/motd ];then - echo "welcome to mdserver-web panel" > /etc/motd + echo "welcome to PowerLinux panel" > /etc/motd fi startTime=`date +%s` @@ -234,12 +237,13 @@ if [ $OSNAME != "macos" ];then mkdir -p /www/backup/site if [ ! -d /www/server/mdserver-web ];then - echo "downloading ${HTTP_PREFIX}github.com/midoks/mdserver-web/archive/refs/heads/dev.tar.gz" - curl --insecure -sSLo /tmp/dev.tar.gz ${HTTP_PREFIX}github.com/midoks/mdserver-web/archive/refs/heads/dev.tar.gz + echo "downloading ${HTTP_PREFIX}github.com/${REPO_OWNER}/${REPO_NAME}/archive/refs/heads/${REPO_BRANCH}.tar.gz" + curl --insecure -sSLo /tmp/dev.tar.gz ${HTTP_PREFIX}github.com/${REPO_OWNER}/${REPO_NAME}/archive/refs/heads/${REPO_BRANCH}.tar.gz + TARBALL_DIR=$(tar -tf /tmp/dev.tar.gz | head -1 | cut -d/ -f1) cd /tmp && tar -zxvf /tmp/dev.tar.gz - mv -f /tmp/mdserver-web-dev /www/server/mdserver-web + mv -f /tmp/${TARBALL_DIR} /www/server/mdserver-web rm -rf /tmp/dev.tar.gz - rm -rf /tmp/mdserver-web-dev + rm -rf /tmp/${TARBALL_DIR} fi # install acme.sh @@ -258,7 +262,7 @@ fi echo "use system version: ${OSNAME}" if [ "${OSNAME}" == "macos" ];then - curl --insecure -fsSL ${HTTP_PREFIX}raw.githubusercontent.com/midoks/mdserver-web/refs/heads/dev/scripts/install/macos.sh | bash + curl --insecure -fsSL ${HTTP_PREFIX}raw.githubusercontent.com/${REPO_OWNER}/${REPO_NAME}/main/scripts/install/macos.sh | bash else cd /www/server/mdserver-web && bash scripts/install/${OSNAME}.sh fi @@ -300,4 +304,4 @@ echo -e "Time consumed:\033[32m $outTime \033[0mMinute!" } 1> >(tee $LOG_FILE) 2>&1 echo -e "\nInstall completed. If error occurs, please contact us with the log file mw-install.log ." -echo "安装完毕,如果出现错误,请带上同目录下的安装日志 mw-install.log 联系我们反馈." \ No newline at end of file +echo "安装完毕,如果出现错误,请带上同目录下的安装日志 mw-install.log 联系我们反馈." diff --git a/scripts/update.sh b/scripts/update.sh index 501b935d4..d254c03db 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -5,7 +5,7 @@ export PATH is64bit=`getconf LONG_BIT` REPO_OWNER="AndyXeCM" REPO_NAME="PowerLinux" -REPO_BRANCH="master" +REPO_BRANCH="main" startTime=`date +%s` diff --git a/scripts/update_dev.sh b/scripts/update_dev.sh index 7fc281e8f..606d4de12 100755 --- a/scripts/update_dev.sh +++ b/scripts/update_dev.sh @@ -16,6 +16,9 @@ WORKING='[\033[34m*\033[0m]' # LANG=en_US.UTF-8 is64bit=`getconf LONG_BIT` +REPO_OWNER="AndyXeCM" +REPO_NAME="PowerLinux" +REPO_BRANCH="main" startTime=`date +%s` @@ -214,19 +217,16 @@ if [ -f /tmp/dev.tar.gz ];then rm -rf /tmp/dev.tar.gz fi -if [ -d /tmp/mdserver-web-dev ];then - rm -rf /tmp/mdserver-web-dev -fi - -echo "update mdserver-web dev code start" +echo "update PowerLinux dev code start" -curl --insecure -sSLo /tmp/dev.tar.gz ${HTTP_PREFIX}github.com/midoks/mdserver-web/archive/refs/heads/dev.tar.gz +curl --insecure -sSLo /tmp/dev.tar.gz ${HTTP_PREFIX}github.com/${REPO_OWNER}/${REPO_NAME}/archive/refs/heads/${REPO_BRANCH}.tar.gz +TARBALL_DIR=$(tar -tf /tmp/dev.tar.gz | head -1 | cut -d/ -f1) cd /tmp && tar -zxvf /tmp/dev.tar.gz -$CP_CMD -rf /tmp/mdserver-web-dev/* /www/server/mdserver-web +$CP_CMD -rf /tmp/${TARBALL_DIR}/* /www/server/mdserver-web rm -rf /tmp/dev.tar.gz -rm -rf /tmp/mdserver-web-dev +rm -rf /tmp/${TARBALL_DIR} -echo "update mdserver-web dev code end" +echo "update PowerLinux dev code end" #pip uninstall public @@ -250,4 +250,4 @@ endTime=`date +%s` ((outTime=($endTime-$startTime)/60)) echo -e "Time consumed:\033[32m $outTime \033[0mMinute!" -} 1> >(tee $LOG_FILE) 2>&1 \ No newline at end of file +} 1> >(tee $LOG_FILE) 2>&1 diff --git a/web/utils/system/update.py b/web/utils/system/update.py index 54a78c35f..24be75850 100644 --- a/web/utils/system/update.py +++ b/web/utils/system/update.py @@ -15,15 +15,97 @@ import math import psutil import json +import html import core.mw as mw +PANEL_REPO_OWNER = 'AndyXeCM' +PANEL_REPO_NAME = 'PowerLinux' +PANEL_RELEASE_API = 'https://api.github.com/repos/%s/%s/releases/latest' % (PANEL_REPO_OWNER, PANEL_REPO_NAME) +PANEL_RELEASE_PAGE = 'https://github.com/%s/%s/releases/latest' % (PANEL_REPO_OWNER, PANEL_REPO_NAME) + + +def _normalize_version_name(version): + version = str(version or '').strip() + if version.startswith('v') and len(version) > 1 and version[1].isdigit(): + version = version[1:] + return version + + +def _strip_html_tags(content): + content = re.sub(r'(?i)', '\n', content) + content = re.sub(r'(?i)', '\n\n', content) + content = re.sub(r'(?i)', '\n', content) + content = re.sub(r'(?i)', '\n', content) + content = re.sub(r'(?i)]*>', ' - ', content) + content = re.sub(r'<[^>]+>', '', content) + return html.unescape(content).strip() + + +def _parse_release_page(result): + tag_name = '' + release_name = '' + + title_match = re.search(r'(.*?)', result, re.S | re.I) + if title_match is not None: + title = title_match.group(1) + title = re.sub(r'\s*·\s*[^<]+$', '', title).strip() + title = re.sub(r'(?i)^release\s+', '', title).strip() + if title != '': + release_name = title + version_match = re.search(r'(\d+(?:\.\d+)+)\s*$', release_name) + if version_match is not None: + tag_name = version_match.group(1) + + if tag_name == '': + tag_candidates = re.findall(r'/[^/]+/[^/]+/releases/tag/([^"\'?#/]+)', result) + for candidate in tag_candidates: + candidate = _normalize_version_name(candidate) + if re.match(r'^\d+(?:\.\d+)+$', candidate) is not None: + tag_name = candidate + break + + if release_name == '': + release_name = tag_name + + if tag_name == '': + return None + + body_match = re.search(r']+class="[^"]*markdown-body[^"]*"[^>]*>(.*?)', result, re.S | re.I) + body = '' + if body_match is not None: + body = _strip_html_tags(body_match.group(1)) + + return { + 'tag_name': tag_name, + 'name': release_name, + 'body': body, + 'html_url': 'https://github.com/%s/%s/releases/tag/%s' % (PANEL_REPO_OWNER, PANEL_REPO_NAME, tag_name), + } + + +def _release_version(version_new_info): + version = _normalize_version_name(version_new_info.get('tag_name', '')) + if version == '': + version = _normalize_version_name(version_new_info.get('version', '')) + if version == '': + version = _normalize_version_name(version_new_info.get('name', '')) + match = re.search(r'(\d+(?:\.\d+)+)', version) + if match is not None: + version = match.group(1) + return version + def versionDiff(now, new): ''' test 测试 new 有新版本 none 没有新版本 ''' + now = _normalize_version_name(now) + new = _normalize_version_name(new) + if now == '' or new == '': + return 'none' + new_list = new.split('.') if len(new_list) > 3: return 'test' @@ -39,16 +121,34 @@ def versionDiff(now, new): def getServerInfo(): import urllib.request import ssl - upAddr = 'https://api.github.com/repos/midoks/mdserver-web/releases/latest' + headers = { + 'User-Agent': 'PowerLinux-Updater/1.0', + 'Accept': 'application/vnd.github+json', + } + upAddrList = [PANEL_RELEASE_API, PANEL_RELEASE_PAGE] + last_error = None try: context = ssl._create_unverified_context() - req = urllib.request.urlopen(upAddr, context=context, timeout=3) - result = req.read().decode('utf-8') - version = json.loads(result) - return version + for upAddr in upAddrList: + try: + req = urllib.request.Request(upAddr, headers=headers) + resp = urllib.request.urlopen(req, context=context, timeout=5) + result = resp.read().decode('utf-8') + if upAddr == PANEL_RELEASE_API: + version = json.loads(result) + if isinstance(version, dict) and version.get('tag_name'): + return version + else: + version = _parse_release_page(result) + if version is not None: + return version + except Exception as e: + last_error = e except Exception as e: print(str(e)) return None + if last_error is not None: + print(str(last_error)) return None def updateServer(stype, version=''): @@ -62,8 +162,8 @@ def updateServer(stype, version=''): if version_new_info is None: return mw.returnData(False, '服务器数据或网络有问题!') - version_now = config.APP_VERSION - new_ver = version_new_info['name'] + version_now = _normalize_version_name(config.APP_VERSION) + new_ver = _release_version(version_new_info) if stype == 'check': diff = versionDiff(version_now, new_ver) if diff == 'new': @@ -77,7 +177,10 @@ def updateServer(stype, version=''): diff = versionDiff(version_now, new_ver) data = {} data['version'] = new_ver - data['content'] = version_new_info['body'].replace("\n", "
") + content = str(version_new_info.get('body', '')) + if content.strip() == '': + content = '当前版本来自 GitHub Release,未提供更新说明。' + data['content'] = content.replace("\n", "
") return mw.returnData(True, '更新信息!', data) if stype == 'update': @@ -91,20 +194,21 @@ def updateServer(stype, version=''): if not os.path.exists(toPath): mw.execShell('mkdir -p ' + toPath) - newUrl = "https://github.com/midoks/mdserver-web/archive/refs/tags/" + version + ".zip" + version = _normalize_version_name(version) + newUrl = "https://github.com/%s/%s/archive/refs/tags/%s.zip" % (PANEL_REPO_OWNER, PANEL_REPO_NAME, version) dist_mw = toPath + '/mw.zip' if not os.path.exists(dist_mw): mw.execShell('wget --no-check-certificate -O ' + dist_mw + ' ' + newUrl) - dist_to = toPath + "/mdserver-web-" + version + dist_to = toPath + "/PowerLinux-" + version if not os.path.exists(dist_to): os.system('unzip -o ' + toPath + '/mw.zip' + ' -d ' + toPath) - cmd_cp = 'cp -rf ' + toPath + '/mdserver-web-' + version + '/* ' + mw.getServerDir() + '/mdserver-web' + cmd_cp = 'cp -rf ' + toPath + '/PowerLinux-' + version + '/* ' + mw.getServerDir() + '/mdserver-web' mw.execShell(cmd_cp) - mw.execShell('rm -rf ' + toPath + '/mdserver-web-' + version) + mw.execShell('rm -rf ' + toPath + '/PowerLinux-' + version) mw.execShell('rm -rf ' + toPath + '/mw.zip') update_env = ''' @@ -145,6 +249,3 @@ def updateServer(stype, version=''): # print('updateServer', ex) return mw.returnData(False, "连接服务器失败!" + str(ex)) - - -