Skip to content

Commit

Permalink
feat: 发布v2.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 14, 2024
1 parent 8dee17b commit 31ab4f0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 49 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ require (
github.com/mholt/acmez/v2 v2.0.3
github.com/mholt/archiver/v4 v4.0.0-alpha.8
github.com/robfig/cron/v3 v3.0.1
github.com/samber/lo v1.47.0
github.com/sethvargo/go-limiter v1.0.0
github.com/shirou/gopsutil v2.21.11+incompatible
github.com/spf13/cast v1.7.0
Expand Down Expand Up @@ -103,7 +104,6 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/samber/lo v1.47.0 // indirect
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.597 // indirect
github.com/therootcompany/xz v1.0.1 // indirect
github.com/tklauser/go-sysconf v0.3.14 // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,6 @@ github.com/tklauser/go-sysconf v0.3.14 h1:g5vzr9iPFFz24v2KZXs/pvpvh8/V9Fw6vQK5ZZ
github.com/tklauser/go-sysconf v0.3.14/go.mod h1:1ym4lWMLUOhuBOPGtRcJm7tEGX4SCYNEEEtghGG/8uY=
github.com/tklauser/numcpus v0.8.0 h1:Mx4Wwe/FjZLeQsK/6kt2EOepwwSl7SmJrK5bV/dXYgY=
github.com/tklauser/numcpus v0.8.0/go.mod h1:ZJZlAY+dmR4eut8epnzf0u/VwodKmryxR8txiloSqBE=
github.com/tufanbarisyildirim/gonginx v0.0.0-20240907135031-d38eb71142ac h1:IXccMEFcB+UqGWae8OF9EoA0/8GCLlDj6s84LCU7y58=
github.com/tufanbarisyildirim/gonginx v0.0.0-20240907135031-d38eb71142ac/go.mod h1:itu4KWRgrfEwGcfNka+rV4houuirUau53i0diN4lG5g=
github.com/tufanbarisyildirim/gonginx v0.0.0-20241013191809-e73b7dd454e8 h1:7yw1yHkylDcu/CwY4hEEe8MycDLo7B9LjcqwhoL8NrM=
github.com/tufanbarisyildirim/gonginx v0.0.0-20241013191809-e73b7dd454e8/go.mod h1:itu4KWRgrfEwGcfNka+rV4houuirUau53i0diN4lG5g=
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
Expand Down
3 changes: 2 additions & 1 deletion internal/bootstrap/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package bootstrap

import (
"context"
"fmt"
"os"
"strings"

Expand Down Expand Up @@ -43,6 +44,6 @@ func initCli() {
Commands: route.Cli(),
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
color.Redln(err.Error())
color.Redln(fmt.Sprintf("|-%v", err))
}
}
2 changes: 1 addition & 1 deletion internal/bootstrap/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func initConf() {

func initGlobal() {
app.Root = app.Conf.MustString("app.root")
app.Version = "2.3.4"
app.Version = "2.3.5"
app.Locale = app.Conf.MustString("app.locale")

// 初始化时区
Expand Down
73 changes: 32 additions & 41 deletions internal/data/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,100 +186,91 @@ func (r *settingRepo) UpdatePanel(version, url, checksum string) error {
}

name := filepath.Base(url)
color.Greenln(fmt.Sprintf("目标版本:%s", version))
color.Greenln(fmt.Sprintf("下载链接:%s", url))
color.Greenln(fmt.Sprintf("文件名:%s", name))
color.Greenln(fmt.Sprintf("|-目标版本:%s", version))
color.Greenln(fmt.Sprintf("|-下载链接:%s", url))
color.Greenln(fmt.Sprintf("|-文件名:%s", name))

color.Greenln("正在下载...")
color.Greenln("|-正在下载...")
if _, err := shell.Execf("wget -T 120 -t 3 -O /tmp/%s %s", name, url); err != nil {
color.Redln("下载失败:", err)
return err
return fmt.Errorf("下载失败:%w", err)
}
if _, err := shell.Execf("wget -T 20 -t 3 -O /tmp/%s %s", name+".sha256", checksum); err != nil {
color.Redln("下载失败:", err)
return err
return fmt.Errorf("下载失败:%w", err)
}
if !io.Exists(filepath.Join("/tmp", name)) || !io.Exists(filepath.Join("/tmp", name+".sha256")) {
return errors.New("下载文件检查失败")
}

color.Greenln("校验下载文件...")
color.Greenln("|-校验下载文件...")
if check, err := shell.Execf("cd /tmp && sha256sum -c %s --ignore-missing", name+".sha256"); check != name+": OK" || err != nil {
return errors.New("下载文件校验失败")
}
if err := io.Remove(filepath.Join("/tmp", name+".sha256")); err != nil {
color.Redln("清理校验文件失败:", err)
color.Redln("|-清理校验文件失败:", err)
return err
}

color.Greenln("前置检查...")
color.Greenln("|-前置检查...")
if io.Exists("/tmp/panel-storage.zip") {
return errors.New("检测到 /tmp 存在临时文件,可能是上次更新失败所致,请运行 panel-cli fix 修复后重试")
}

color.Greenln("备份面板数据...")
color.Greenln("|-备份面板数据...")
// 备份面板
backup := NewBackupRepo()
if err := backup.Create(biz.BackupTypePanel, ""); err != nil {
color.Redln("备份面板失败:", err)
color.Redln("|-备份面板失败:", err)
return err
}
if err := io.Compress([]string{filepath.Join(app.Root, "panel/storage")}, "/tmp/panel-storage.zip", io.Zip); err != nil {
color.Redln("备份面板数据失败:", err)
color.Redln("|-备份面板数据失败:", err)
return err
}
if !io.Exists("/tmp/panel-storage.zip") {
return errors.New("已备份面板数据检查失败")
}

color.Greenln("清理旧版本...")
color.Greenln("|-清理旧版本...")
if _, err := shell.Execf("rm -rf %s/panel/*", app.Root); err != nil {
color.Redln("清理旧版本失败:", err)
return err
return fmt.Errorf("清理旧版本失败:%w", err)
}

color.Greenln("解压新版本...")
color.Greenln("|-解压新版本...")
if err := io.UnCompress(filepath.Join("/tmp", name), filepath.Join(app.Root, "panel"), io.Zip); err != nil {
color.Redln("解压失败:", err)
return err
return fmt.Errorf("解压失败:%w", err)
}
if !io.Exists(filepath.Join(app.Root, "panel", "web")) {
return errors.New("解压失败,缺失文件")
}

color.Greenln("恢复面板数据...")
color.Greenln("|-恢复面板数据...")
if err := io.UnCompress("/tmp/panel-storage.zip", filepath.Join(app.Root, "panel"), io.Zip); err != nil {
color.Redln("恢复面板数据失败:", err)
return err
return fmt.Errorf("恢复面板数据失败:%w", err)
}
if !io.Exists(filepath.Join(app.Root, "panel/storage/app.db")) {
return errors.New("恢复面板数据失败")
}

color.Greenln("运行升级后脚本...")
color.Greenln("|-运行升级后脚本...")
if _, err := shell.Execf("curl -fsLm 10 https://dl.cdn.haozi.net/panel/auto_update.sh | bash"); err != nil {
color.Redln("运行面板升级后脚本失败:", err)
return 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 {
color.Redln("下载面板服务文件失败:", err)
return err
return fmt.Errorf("下载面板服务文件失败:%w", err)
}
if _, err := shell.Execf("panel-cli setting write version %s", version); err != nil {
color.Redln("写入面板版本号失败:", err)
return err
return fmt.Errorf("写入面板版本号失败:%w", err)
}
if err := io.Mv(filepath.Join(app.Root, "panel/cli"), "/usr/local/sbin/panel-cli"); err != nil {
color.Redln("移动面板命令行工具失败:", err)
return err
return fmt.Errorf("移动面板命令行工具失败:%w", err)
}

color.Greenln("设置关键文件权限...")
color.Greenln("|-设置关键文件权限...")
_ = io.Chmod("/usr/local/sbin/panel-cli", 0700)
_ = io.Chmod("/etc/systemd/system/panel.service", 0700)
_ = io.Chmod(filepath.Join(app.Root, "panel"), 0700)

color.Greenln("升级完成")
color.Greenln("|-升级完成")

_, _ = shell.Execf("systemctl daemon-reload")
_ = io.Remove("/tmp/panel-storage.zip")
Expand All @@ -290,7 +281,7 @@ func (r *settingRepo) UpdatePanel(version, url, checksum string) error {
}

func (r *settingRepo) FixPanel() error {
color.Greenln("开始修复面板...")
color.Greenln("|-开始修复面板...")
// 检查关键文件是否正常
flag := false
if !io.Exists(filepath.Join(app.Root, "panel", "web")) {
Expand Down Expand Up @@ -319,10 +310,10 @@ func (r *settingRepo) FixPanel() error {
return fmt.Errorf("未找到备份文件,无法自动修复")
}
latest := list[0]
color.Greenln(fmt.Sprintf("使用备份文件:%s", latest.Name))
color.Greenln(fmt.Sprintf("|-使用备份文件:%s", latest.Name))

// 解压备份文件
color.Greenln("解压备份文件...")
color.Greenln("|-解压备份文件...")
if err = io.Remove("/tmp/panel-fix"); err != nil {
return fmt.Errorf("清理临时目录失败:%w", err)
}
Expand All @@ -331,7 +322,7 @@ func (r *settingRepo) FixPanel() error {
}

// 移动文件到对应位置
color.Greenln("移动备份文件...")
color.Greenln("|-移动备份文件...")
if io.Exists(filepath.Join("/tmp/panel-fix", "panel")) && io.IsDir(filepath.Join("/tmp/panel-fix", "panel")) {
if err = io.Remove(filepath.Join(app.Root, "panel")); err != nil {
return fmt.Errorf("删除目录失败:%w", err)
Expand All @@ -352,7 +343,7 @@ func (r *settingRepo) FixPanel() error {
}

// tmp目录下如果有storage备份,则解压回去
color.Greenln("恢复面板数据...")
color.Greenln("|-恢复面板数据...")
if io.Exists("/tmp/panel-storage.zip") {
if err = io.UnCompress("/tmp/panel-storage.zip", filepath.Join(app.Root, "panel"), io.Zip); err != nil {
return fmt.Errorf("恢复面板数据失败:%w", err)
Expand All @@ -370,7 +361,7 @@ func (r *settingRepo) FixPanel() error {
}

// 处理权限
color.Greenln("设置关键文件权限...")
color.Greenln("|-设置关键文件权限...")
if err = io.Chmod("/usr/local/etc/panel/config.yml", 0600); err != nil {
return err
}
Expand All @@ -384,7 +375,7 @@ func (r *settingRepo) FixPanel() error {
return err
}

color.Greenln("修复完成")
color.Greenln("|-修复完成")
tools.RestartPanel()

return nil
Expand Down
3 changes: 0 additions & 3 deletions pkg/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/go-resty/resty/v2"
"github.com/gookit/color"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/host"
Expand Down Expand Up @@ -61,9 +60,7 @@ func GetMonitoringInfo() MonitoringInfo {
}

func RestartPanel() {
color.Greenln("重启面板...")
_ = shell.ExecfAsync("sleep 1 && systemctl restart panel")
color.Greenln("重启完成")
}

// IsChina 是否中国大陆
Expand Down

0 comments on commit 31ab4f0

Please sign in to comment.