From b229913df298dc18ff27362d086043303cfd06ee Mon Sep 17 00:00:00 2001 From: witersen <1801168257@qq.com> Date: Mon, 9 May 2022 13:09:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8D=87=E7=BA=A7=E7=A8=8B?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02.php/app/service/Update.php | 4 +- 02.php/config/update.php | 17 +++++-- 02.php/server/install.php | 83 ++++++++++++++++++------------- 02.php/server/update.json | 94 +++++++++++++++++++++++++++-------- 4 files changed, 136 insertions(+), 62 deletions(-) diff --git a/02.php/app/service/Update.php b/02.php/app/service/Update.php index 9ee3199..4fcde98 100644 --- a/02.php/app/service/Update.php +++ b/02.php/app/service/Update.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-05-07 20:01:24 + * @LastEditTime: 2022-05-09 11:41:40 * @Description: QQ:1801168257 */ @@ -22,7 +22,7 @@ class Update extends Base public function CheckUpdate() { foreach ($this->config_update['update_server'] as $key => $value) { - $versionInfo = FunCurlRequest($value); + $versionInfo = FunCurlRequest($value['url']); if ($versionInfo != null) { $versionInfo = json_decode($versionInfo, true); $latestVersion = $versionInfo['latestVersion']; diff --git a/02.php/config/update.php b/02.php/config/update.php index b200df5..a1d1b64 100644 --- a/02.php/config/update.php +++ b/02.php/config/update.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:06 * @LastEditors: witersen - * @LastEditTime: 2022-05-09 00:26:12 + * @LastEditTime: 2022-05-09 11:41:24 * @Description: QQ:1801168257 */ @@ -12,8 +12,17 @@ */ return [ 'update_server' => [ - // 'https://gitee.com/witersen/update/raw/master/SvnAdmin/update2.json', - // 'https://raw.githubusercontent.com/witersen/update/master/SvnAdmin/update2.json', - 'http://dev.witersen.com/server/update.json' + // [ + // 'nodeName' => 'gitee.com', + // 'url' => 'https://gitee.com/witersen/update/raw/master/SvnAdmin/update2.json' + // ], + // [ + // 'nodeName' => 'github.com', + // 'url' => 'https://gitee.com/witersen/update/raw/master/SvnAdmin/update2.json' + // ], + [ + 'nodeName' => 'witersen.com', + 'url' => 'http://dev.witersen.com/server/update.json' + ] ] ]; diff --git a/02.php/server/install.php b/02.php/server/install.php index 64460c9..e603b4e 100644 --- a/02.php/server/install.php +++ b/02.php/server/install.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-05-08 13:31:07 * @LastEditors: witersen - * @LastEditTime: 2022-05-09 01:23:06 + * @LastEditTime: 2022-05-09 13:06:47 * @Description: QQ:1801168257 */ @@ -73,41 +73,42 @@ class Install //对升级服务器地址进行轮询 //获取当前版本可升级的版本信息 - foreach ($this->config_update['update_server'] as $value) { + foreach ($this->config_update['update_server'] as $key1 => $value1) { - $result = FunCurlRequest($value); + $json = FunCurlRequest($value1['url']); - if ($result == null) { - echo '节点访问超时,切换下一节点' . PHP_EOL; + if ($json == null) { + echo '节点 ' . $value1['nodeName'] . ' 访问超时,切换下一节点' . PHP_EOL; continue; } - //json转换 - $result = json_decode($result, true); + //json => array + $array = json_decode($json, true); - $version = $result['version']; - if ($this->config_version['version'] == $version) { - exit('当前为最新版:' . $version . PHP_EOL); + $last = $array['version']; + + if ($this->config_version['version'] == $last) { + exit('当前为最新版:' . $last . PHP_EOL); } - if ($this->config_version['version'] < $version) { - echo '有新版本:' . $version . PHP_EOL; + if ($this->config_version['version'] < $last) { + echo '有新版本:' . $last . PHP_EOL; echo '修复内容如下:' . PHP_EOL; - foreach ($result['fixd']['con'] as $value) { - echo ' [' . $value['title'] . ']' . ' ' . $value['content'] . PHP_EOL; + foreach ($array['fixd']['con'] as $cons) { + echo ' [' . $cons['title'] . ']' . ' ' . $cons['content'] . PHP_EOL; } echo '新增内容如下:' . PHP_EOL; - foreach ($result['add']['con'] as $value) { - echo ' [' . $value['title'] . ']' . ' ' . $value['content'] . PHP_EOL; + foreach ($array['add']['con'] as $cons) { + echo ' [' . $cons['title'] . ']' . ' ' . $cons['content'] . PHP_EOL; } echo '移除内容如下:' . PHP_EOL; - foreach ($result['remove']['con'] as $value) { - echo ' [' . $value['title'] . ']' . ' ' . $value['content'] . PHP_EOL; + foreach ($array['remove']['con'] as $cons) { + echo ' [' . $cons['title'] . ']' . ' ' . $cons['content'] . PHP_EOL; } - echo "确定要升级到 $version 版本吗[y/n]:"; + echo "确定要升级到 $last 版本吗[y/n]:"; $answer = strtolower(trim(fgets(STDIN))); @@ -120,20 +121,39 @@ class Install } //下载并执行升级脚本 - + $packages = $array['update']['download'][$key1]['packages']; + $forList = array_column($packages, 'for'); + $current = [ + 'source' => $this->config_version['version'], + 'dest' => $last + ]; + if (!in_array($current, $forList)) { + exit('没有合适的升级包,请尝试直接手动安装最新版!' . PHP_EOL); + } + $index = array_search($current, $forList); + $update_download_url = $packages[$index]['url']; + $update_zip = FunCurlRequest($update_download_url); + if ($update_zip == null) { + echo '从节点 ' . $value1['nodeName'] . ' 下载升级包超时,切换下一节点' . PHP_EOL; + continue; + } + file_put_contents(BASE_PATH . '/update.zip', $update_zip); + shell_exec('unzip ' . BASE_PATH . '/update.zip'); + if (!is_dir(BASE_PATH . '/update')) { + exit('解压升级包出错,请尝试手动解压并执行升级程序!' . PHP_EOL); + } - echo '===============================================' . PHP_EOL; + echo '正在执行升级程序' . PHP_EOL; + + passthru('php ' . BASE_PATH . '/update/index.php'); + + shell_exec(sprintf("cd '%s' && rm -rf ./update && rm -f update.zip", BASE_PATH)); + + exit('升级成功!请重启守护进程文件使部分配置文件生效' . PHP_EOL); } } } - /** - * 升级到指定版本的SVNAdmin - */ - function UpdateSVNAdmin() - { - } - /** * 将SVNAdmin加入到开机自启动 */ @@ -155,13 +175,6 @@ class Install { } - /** - * 卸载Subversion - */ - function UninstallSubversion() - { - } - /** * 修改已经安装的Subversion配置以适合SVNAdmin的管理 */ diff --git a/02.php/server/update.json b/02.php/server/update.json index 410a74a..23f8364 100644 --- a/02.php/server/update.json +++ b/02.php/server/update.json @@ -48,6 +48,22 @@ } ] }, + "release": { + "download": [ + { + "nodeName": "gitee.com", + "url": "" + }, + { + "nodeName": "github.com", + "url": "" + }, + { + "nodeName": "witersen.com", + "url": "https://download.witersen.com/SVNAdmin/SVNAdmin-2.3.zip" + } + ] + }, "update": { "step": [ { @@ -55,27 +71,63 @@ "content": "php ${your_path}/server/install.php" } ], - "release": { - "download": [ - { - "nodeName": "gitee.com", - "package": "" - }, - { - "nodeName": "github.com", - "package": "" - }, - { - "nodeName": "witersen.com", - "package": "https://download.witersen.com/SVNAdmin/SVNAdmin-2.3.zip" - } - ] - }, - "update": [ - { - "source": "2.3", - "dest": "2.4", - "package": "" + "download": [ + { + "nodeName": "gitee.com", + "packages": [ + { + "for": { + "source": "2.3", + "dest": "2.4" + }, + "url": "xxx" + }, + { + "for": { + "source": "2.3", + "dest": "2.5" + }, + "url": "xxx" + } + ] + }, + { + "nodeName": "github.com", + "packages": [ + { + "for": { + "source": "2.3", + "dest": "2.4" + }, + "url": "xxx" + }, + { + "for": { + "source": "2.3", + "dest": "2.5" + }, + "url": "xxx" + } + ] + }, + { + "nodeName": "witersen.com", + "packages": [ + { + "for": { + "source": "2.3", + "dest": "2.4" + }, + "url": "xxx" + }, + { + "for": { + "source": "2.3", + "dest": "2.5" + }, + "url": "xxx" + } + ] } ] }