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. 81
      02.php/server/install.php
  4. 68
      02.php/server/update.json

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

@ -3,7 +3,7 @@ @@ -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 @@ -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'];

17
02.php/config/update.php

@ -3,7 +3,7 @@ @@ -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 @@ @@ -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'
]
]
];

81
02.php/server/install.php

@ -3,7 +3,7 @@ @@ -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 @@ -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,18 +121,37 @@ class Install @@ -120,18 +121,37 @@ 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()
{
}
/**
@ -155,13 +175,6 @@ class Install @@ -155,13 +175,6 @@ class Install
{
}
/**
* 卸载Subversion
*/
function UninstallSubversion()
{
}
/**
* 修改已经安装的Subversion配置以适合SVNAdmin的管理
*/

68
02.php/server/update.json

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

Loading…
Cancel
Save