Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
易企天创
zentaoatf
提交
60c71cd9
Z
zentaoatf
项目概览
易企天创
/
zentaoatf
大约 1 年 前同步成功
通知
11
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
3
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Z
zentaoatf
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
3
Issue
3
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
60c71cd9
编写于
12月 31, 2020
作者:
aaronchen2k2k
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
check md5 before update
上级
37723d88
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
48 addition
and
14 deletion
+48
-14
Makefile
Makefile
+1
-1
res/messages_en.json
res/messages_en.json
+4
-0
res/messages_zh.json
res/messages_zh.json
+4
-0
src/server/service/upgrade.go
src/server/service/upgrade.go
+38
-12
src/server/utils/const/const.go
src/server/utils/const/const.go
+1
-1
未找到文件。
Makefile
浏览文件 @
60c71cd9
VERSION
=
2.
0
VERSION
=
2.
1
PROJECT
=
ztf
QINIU_DIR
=
/Users/aaron/work/zentao/qiniu/
QINIU_DIST_DIR
=
${QINIU_DIR}${PROJECT}
/
${VERSION}
/
...
...
res/messages_en.json
浏览文件 @
60c71cd9
...
...
@@ -490,6 +490,10 @@
{
"id"
:
"fail_unzip"
,
"translation"
:
"Fail to unzip file %s."
},
{
"id"
:
"fail_md5_check"
,
"translation"
:
"Check file %s MD5 failed."
}
]
}
res/messages_zh.json
浏览文件 @
60c71cd9
...
...
@@ -497,6 +497,10 @@
{
"id"
:
"fail_unzip"
,
"translation"
:
"解压文件%s失败。"
},
{
"id"
:
"fail_md5_check"
,
"translation"
:
"验证文件%s的MD5失败。"
}
]
}
src/server/service/upgrade.go
浏览文件 @
60c71cd9
package
service
import
(
"errors"
"fmt"
serverUtils
"github.com/easysoft/zentaoatf/src/server/utils/common"
serverConst
"github.com/easysoft/zentaoatf/src/server/utils/const"
...
...
@@ -10,6 +11,7 @@ import (
fileUtils
"github.com/easysoft/zentaoatf/src/utils/file"
i118Utils
"github.com/easysoft/zentaoatf/src/utils/i118"
logUtils
"github.com/easysoft/zentaoatf/src/utils/log"
shellUtils
"github.com/easysoft/zentaoatf/src/utils/shell"
"github.com/easysoft/zentaoatf/src/utils/vari"
"github.com/fatih/color"
"github.com/inconshreveable/go-update"
...
...
@@ -31,7 +33,7 @@ func NewUpgradeService() *UpgradeService {
func
(
s
*
UpgradeService
)
CheckUpgrade
()
{
pth
:=
vari
.
AgentLogDir
+
"version.txt"
serverUtils
.
Download
(
serverConst
.
Agent
Upgrade
URL
,
pth
)
serverUtils
.
Download
(
serverConst
.
Agent
Version
URL
,
pth
)
content
:=
strings
.
TrimSpace
(
fileUtils
.
ReadFile
(
pth
))
version
,
_
:=
strconv
.
ParseFloat
(
content
,
64
)
...
...
@@ -39,15 +41,14 @@ func (s *UpgradeService) CheckUpgrade() {
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"find_new_ver"
,
content
),
color
.
FgCyan
)
versionStr
:=
fmt
.
Sprintf
(
"%.1f"
,
version
)
err
:=
s
.
DownloadVersion
(
versionStr
)
if
err
==
nil
{
pass
,
err
:=
s
.
DownloadFile
(
versionStr
)
if
pass
&&
err
==
nil
{
s
.
RestartVersion
(
versionStr
)
}
}
}
func
(
s
*
UpgradeService
)
DownloadVersion
(
version
string
)
(
err
error
)
{
func
(
s
*
UpgradeService
)
DownloadFile
(
version
string
)
(
pass
bool
,
err
error
)
{
os
:=
commonUtils
.
GetOs
()
if
commonUtils
.
IsWin
()
{
os
=
fmt
.
Sprintf
(
"%s%d"
,
os
,
strconv
.
IntSize
)
...
...
@@ -55,17 +56,35 @@ func (s *UpgradeService) DownloadVersion(version string) (err error) {
url
:=
fmt
.
Sprintf
(
serverConst
.
AgentDownloadURL
,
version
,
os
)
dir
:=
vari
.
AgentLogDir
+
version
pth
:=
dir
+
".zip"
err
=
serverUtils
.
Download
(
url
,
pth
)
if
err
!=
nil
{
return
}
if
err
==
nil
{
fileUtils
.
RmDir
(
dir
)
fileUtils
.
MkDirIfNeeded
(
dir
)
err
=
archiver
.
Unarchive
(
pth
,
dir
)
md5Url
:=
url
+
".md5"
md5Pth
:=
pth
+
".md5"
err
=
serverUtils
.
Download
(
md5Url
,
md5Pth
)
if
err
!=
nil
{
return
}
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_unzip"
,
pth
),
color
.
FgCyan
)
}
pass
=
s
.
checkMd5
(
pth
,
md5Pth
)
if
!
pass
{
msg
:=
i118Utils
.
I118Prt
.
Sprintf
(
"fail_md5_check"
,
pth
)
logUtils
.
PrintToWithColor
(
msg
,
color
.
FgCyan
)
err
=
errors
.
New
(
msg
)
return
}
fileUtils
.
RmDir
(
dir
)
fileUtils
.
MkDirIfNeeded
(
dir
)
err
=
archiver
.
Unarchive
(
pth
,
dir
)
if
err
!=
nil
{
logUtils
.
PrintToWithColor
(
i118Utils
.
I118Prt
.
Sprintf
(
"fail_unzip"
,
pth
),
color
.
FgCyan
)
return
}
return
...
...
@@ -98,3 +117,10 @@ func (s *UpgradeService) RestartVersion(version string) (err error) {
return
}
func
(
s
*
UpgradeService
)
checkMd5
(
filePth
,
md5Pth
string
)
(
pass
bool
)
{
expectVal
:=
fileUtils
.
ReadFile
(
md5Pth
)
actualVal
,
_
:=
shellUtils
.
ExeSysCmd
(
"md5sum "
+
filePth
+
" | awk '{print $1}'"
)
return
strings
.
TrimSpace
(
actualVal
)
==
strings
.
TrimSpace
(
expectVal
)
}
src/server/utils/const/const.go
浏览文件 @
60c71cd9
...
...
@@ -10,6 +10,6 @@ const (
AgentLogDir
=
"log-agent"
QiNiuURL
=
"https://dl.cnezsoft.com/"
+
constant
.
AppName
+
"/"
Agent
Upgrade
URL
=
QiNiuURL
+
"version.txt"
Agent
Version
URL
=
QiNiuURL
+
"version.txt"
AgentDownloadURL
=
QiNiuURL
+
"%s/%s/"
+
constant
.
AppName
+
".zip"
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录