2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 04:22:33 +08:00

feat: cli支持更新应用

This commit is contained in:
耗子
2024-10-17 17:32:38 +08:00
parent df021819b4
commit 1a9fe40b80
8 changed files with 47 additions and 27 deletions

View File

@@ -27,7 +27,7 @@ body:
required: false
- label: 这个问题可以被稳定复现 (The problem can be stably reproduced)
required: false
- label: 问题是在升级之后产生的 (The problem is generated after upgrading)
- label: 问题是在更新之后产生的 (The problem is generated after upgrading)
required: false
- type: dropdown
id: system

View File

@@ -295,7 +295,7 @@ func (r *appRepo) Update(slug string) error {
}
task := new(biz.Task)
task.Name = "升级应用 " + item.Name
task.Name = "更新应用 " + item.Name
task.Status = biz.TaskStatusWaiting
task.Shell = fmt.Sprintf(`curl -fsLm 10 --retry 3 "%s" | bash -s -- "%s" "%s" >> /tmp/%s.log 2>&1`, shellUrl, shellChannel, shellVersion, item.Slug)
task.Log = "/tmp/" + item.Slug + ".log"

View File

@@ -276,7 +276,7 @@ func (r *settingRepo) UpdatePanel(version, url, checksum string) error {
color.Greenln("|-前置检查...")
}
if io.Exists("/tmp/panel-storage.zip") {
return errors.New("检测到 /tmp 存在临时文件,可能是上次升级失败所致,请运行 panel-cli fix 修复后重试")
return errors.New("检测到 /tmp 存在临时文件,可能是上次更新失败所致,请运行 panel-cli fix 修复后重试")
}
if app.IsCli {
@@ -328,10 +328,10 @@ func (r *settingRepo) UpdatePanel(version, url, checksum string) error {
}
if app.IsCli {
color.Greenln("|-运行升级后脚本...")
color.Greenln("|-运行更新后脚本...")
}
if _, err := shell.Execf("curl -fsLm 10 https://dl.cdn.haozi.net/panel/auto_update.sh | bash"); err != nil {
return fmt.Errorf("运行面板升级后脚本失败:%w", err)
return fmt.Errorf("运行面板更新后脚本失败:%w", err)
}
if _, err := shell.Execf(`wget -O /etc/systemd/system/panel.service https://dl.cdn.haozi.net/panel/panel.service && sed -i "s|/www|%s|g" /etc/systemd/system/panel.service`, app.Root); err != nil {
return fmt.Errorf("下载面板服务文件失败:%w", err)
@@ -351,7 +351,7 @@ func (r *settingRepo) UpdatePanel(version, url, checksum string) error {
_ = io.Chmod(filepath.Join(app.Root, "panel"), 0700)
if app.IsCli {
color.Greenln("|-升级完成")
color.Greenln("|-更新完成")
}
_, _ = shell.Execf("systemctl daemon-reload")
@@ -378,7 +378,7 @@ func (r *settingRepo) FixPanel() error {
flag = true
}
if !flag {
return fmt.Errorf("文件正常无需修复,请运行 panel-cli update 升级面板")
return fmt.Errorf("文件正常无需修复,请运行 panel-cli update 更新面板")
}
// 再次确认是否需要修复
@@ -391,7 +391,7 @@ func (r *settingRepo) FixPanel() error {
return fmt.Errorf("清理临时文件失败:%w", err)
}
if app.IsCli {
color.Greenln("已清理临时文件,请运行 panel-cli update 升级面板")
color.Greenln("已清理临时文件,请运行 panel-cli update 更新面板")
}
return nil
}

View File

@@ -16,7 +16,7 @@ func Status(next http.Handler) http.Handler {
render := chix.NewRender(w)
render.Status(http.StatusServiceUnavailable)
render.JSON(chix.M{
"message": "面板升级中,请稍后刷新",
"message": "面板更新中,请稍后刷新",
})
return
case app.StatusMaintain:

View File

@@ -26,7 +26,7 @@ func Cli() []*cli.Command {
},
{
Name: "update",
Usage: "升级面板",
Usage: "更新面板",
Action: cliService.Update,
},
{
@@ -327,6 +327,11 @@ func Cli() []*cli.Command {
Usage: "卸载应用",
Action: cliService.AppUnInstall,
},
{
Name: "update",
Usage: "更新应用",
Action: cliService.AppUpdate,
},
{
Name: "write",
Usage: "添加面板应用标记(仅限指导下使用)",

View File

@@ -530,8 +530,8 @@ func (s *CliService) CutoffClear(ctx context.Context, cmd *cli.Command) error {
}
func (s *CliService) AppInstall(ctx context.Context, cmd *cli.Command) error {
channel := cmd.Args().Get(0)
slug := cmd.Args().Get(1)
slug := cmd.Args().First()
channel := cmd.Args().Get(1)
if channel == "" || slug == "" {
return fmt.Errorf("参数不能为空")
}
@@ -540,7 +540,7 @@ func (s *CliService) AppInstall(ctx context.Context, cmd *cli.Command) error {
return fmt.Errorf("应用安装失败:%v", err)
}
color.Greenln(fmt.Sprintf("已创建应用 %s 安装任务", slug))
color.Greenln(fmt.Sprintf("应用 %s 安装完成", slug))
return nil
}
@@ -555,7 +555,22 @@ func (s *CliService) AppUnInstall(ctx context.Context, cmd *cli.Command) error {
return fmt.Errorf("应用卸载失败:%v", err)
}
color.Greenln(fmt.Sprintf("已创建应用 %s 卸载任务", slug))
color.Greenln(fmt.Sprintf("应用 %s 卸载完成", slug))
return nil
}
func (s *CliService) AppUpdate(ctx context.Context, cmd *cli.Command) error {
slug := cmd.Args().First()
if slug == "" {
return fmt.Errorf("参数不能为空")
}
if err := s.appRepo.Update(slug); err != nil {
return fmt.Errorf("应用更新失败:%v", err)
}
color.Greenln(fmt.Sprintf("应用 %s 更新完成", slug))
return nil
}

View File

@@ -311,7 +311,7 @@ func (s *DashboardService) UpdateInfo(w http.ResponseWriter, r *http.Request) {
versions, err := s.api.IntermediateVersions()
if err != nil {
Error(w, http.StatusInternalServerError, "获取升级信息失败:%v", err)
Error(w, http.StatusInternalServerError, "获取更新信息失败:%v", err)
return
}
@@ -320,12 +320,12 @@ func (s *DashboardService) UpdateInfo(w http.ResponseWriter, r *http.Request) {
func (s *DashboardService) Update(w http.ResponseWriter, r *http.Request) {
if offline, _ := s.settingRepo.GetBool(biz.SettingKeyOfflineMode); offline {
Error(w, http.StatusForbidden, "离线模式下无法升级")
Error(w, http.StatusForbidden, "离线模式下无法更新")
return
}
if s.taskRepo.HasRunningTask() {
Error(w, http.StatusInternalServerError, "后台任务正在运行,禁止升级,请稍后再试")
Error(w, http.StatusInternalServerError, "后台任务正在运行,禁止更新,请稍后再试")
return
}

View File

@@ -13,22 +13,22 @@
"title": "文件管理"
},
"homeUpdate": {
"title": "升级面板",
"title": "更新面板",
"loading": "正在加载更新信息,稍等片刻",
"alerts": {
"success": "面板升级成功",
"info": "取消升级"
"success": "面板更新成功",
"info": "取消更新"
},
"button": {
"update": "立即升级"
"update": "立即更新"
},
"confirm": {
"update": {
"title": "升级面板",
"content": "确定升级面板吗?",
"title": "更新面板",
"content": "确定更新面板吗?",
"positiveText": "确定",
"negativeText": "取消",
"loading": "面板升级中..."
"loading": "面板更新中..."
}
}
},
@@ -39,7 +39,7 @@
"title": "应用中心",
"alerts": {
"cache": "缓存更新成功",
"warning": "升级应用前强烈建议先备份/快照,以免出现问题时无法回滚!",
"warning": "更新应用前强烈建议先备份/快照,以免出现问题时无法回滚!",
"setup": "设置成功",
"install": "任务已提交,请稍后查看任务进度",
"update": "任务已提交,请前往后台任务查看任务进度",
@@ -49,11 +49,11 @@
"updateCache": "更新缓存",
"install": "安装",
"manage": "管理",
"update": "升级",
"update": "更新",
"uninstall": "卸载"
},
"confirm": {
"update": "升级 {app} 应用可能会重置相关配置到默认状态,确定继续吗?",
"update": "更新 {app} 应用可能会重置相关配置到默认状态,确定继续吗?",
"uninstall": "确定卸载应用 {app} 吗?"
},
"columns": {