Browse Source

完善升级程序

docker-svn
witersen 3 years ago
parent
commit
b229913df2
  1. 4
      02.php/app/service/Update.php
  2. 17
      02.php/config/update.php
  3. 83
      02.php/server/install.php
  4. 94
      02.php/server/update.json

4
02.php/app/service/Update.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-07 20:01:24 * @LastEditTime: 2022-05-09 11:41:40
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -22,7 +22,7 @@ class Update extends Base
public function CheckUpdate() public function CheckUpdate()
{ {
foreach ($this->config_update['update_server'] as $key => $value) { foreach ($this->config_update['update_server'] as $key => $value) {
$versionInfo = FunCurlRequest($value); $versionInfo = FunCurlRequest($value['url']);
if ($versionInfo != null) { if ($versionInfo != null) {
$versionInfo = json_decode($versionInfo, true); $versionInfo = json_decode($versionInfo, true);
$latestVersion = $versionInfo['latestVersion']; $latestVersion = $versionInfo['latestVersion'];

17
02.php/config/update.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:06 * @Date: 2022-04-24 23:37:06
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-09 00:26:12 * @LastEditTime: 2022-05-09 11:41:24
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -12,8 +12,17 @@
*/ */
return [ return [
'update_server' => [ 'update_server' => [
// 'https://gitee.com/witersen/update/raw/master/SvnAdmin/update2.json', // [
// 'https://raw.githubusercontent.com/witersen/update/master/SvnAdmin/update2.json', // 'nodeName' => 'gitee.com',
'http://dev.witersen.com/server/update.json' // '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'
]
] ]
]; ];

83
02.php/server/install.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-05-08 13:31:07 * @Date: 2022-05-08 13:31:07
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-09 01:23:06 * @LastEditTime: 2022-05-09 13:06:47
* @Description: QQ:1801168257 * @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) { if ($json == null) {
echo '节点访问超时,切换下一节点' . PHP_EOL; echo '节点 ' . $value1['nodeName'] . ' 访问超时,切换下一节点' . PHP_EOL;
continue; continue;
} }
//json转换 //json => array
$result = json_decode($result, true); $array = json_decode($json, true);
$version = $result['version']; $last = $array['version'];
if ($this->config_version['version'] == $version) {
exit('当前为最新版:' . $version . PHP_EOL); if ($this->config_version['version'] == $last) {
exit('当前为最新版:' . $last . PHP_EOL);
} }
if ($this->config_version['version'] < $version) { if ($this->config_version['version'] < $last) {
echo '有新版本:' . $version . PHP_EOL; echo '有新版本:' . $last . PHP_EOL;
echo '修复内容如下:' . PHP_EOL; echo '修复内容如下:' . PHP_EOL;
foreach ($result['fixd']['con'] as $value) { foreach ($array['fixd']['con'] as $cons) {
echo ' [' . $value['title'] . ']' . ' ' . $value['content'] . PHP_EOL; echo ' [' . $cons['title'] . ']' . ' ' . $cons['content'] . PHP_EOL;
} }
echo '新增内容如下:' . PHP_EOL; echo '新增内容如下:' . PHP_EOL;
foreach ($result['add']['con'] as $value) { foreach ($array['add']['con'] as $cons) {
echo ' [' . $value['title'] . ']' . ' ' . $value['content'] . PHP_EOL; echo ' [' . $cons['title'] . ']' . ' ' . $cons['content'] . PHP_EOL;
} }
echo '移除内容如下:' . PHP_EOL; echo '移除内容如下:' . PHP_EOL;
foreach ($result['remove']['con'] as $value) { foreach ($array['remove']['con'] as $cons) {
echo ' [' . $value['title'] . ']' . ' ' . $value['content'] . PHP_EOL; echo ' [' . $cons['title'] . ']' . ' ' . $cons['content'] . PHP_EOL;
} }
echo "确定要升级到 $version 版本吗[y/n]:"; echo "确定要升级到 $last 版本吗[y/n]:";
$answer = strtolower(trim(fgets(STDIN))); $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加入到开机自启动 * 将SVNAdmin加入到开机自启动
*/ */
@ -155,13 +175,6 @@ class Install
{ {
} }
/**
* 卸载Subversion
*/
function UninstallSubversion()
{
}
/** /**
* 修改已经安装的Subversion配置以适合SVNAdmin的管理 * 修改已经安装的Subversion配置以适合SVNAdmin的管理
*/ */

94
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": { "update": {
"step": [ "step": [
{ {
@ -55,27 +71,63 @@
"content": "php ${your_path}/server/install.php" "content": "php ${your_path}/server/install.php"
} }
], ],
"release": { "download": [
"download": [ {
{ "nodeName": "gitee.com",
"nodeName": "gitee.com", "packages": [
"package": "" {
}, "for": {
{ "source": "2.3",
"nodeName": "github.com", "dest": "2.4"
"package": "" },
}, "url": "xxx"
{ },
"nodeName": "witersen.com", {
"package": "https://download.witersen.com/SVNAdmin/SVNAdmin-2.3.zip" "for": {
} "source": "2.3",
] "dest": "2.5"
}, },
"update": [ "url": "xxx"
{ }
"source": "2.3", ]
"dest": "2.4", },
"package": "" {
"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"
}
]
} }
] ]
} }

Loading…
Cancel
Save