2023-01-30 13:05:20 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2023-03-21 07:16:28 +00:00
|
|
|
"encoding/json"
|
2023-01-30 13:05:20 +00:00
|
|
|
"fmt"
|
2023-02-07 07:33:47 +00:00
|
|
|
"net/http"
|
2023-01-30 13:05:20 +00:00
|
|
|
"os"
|
2023-08-01 14:05:14 +00:00
|
|
|
"path"
|
2024-04-24 15:12:12 +00:00
|
|
|
"strconv"
|
2023-02-05 15:48:37 +00:00
|
|
|
"strings"
|
2023-01-30 13:05:20 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
2024-06-06 09:37:38 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
2023-01-30 13:05:20 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/global"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/cmd"
|
2023-03-17 10:05:21 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/common"
|
2023-01-30 13:05:20 +00:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/utils/files"
|
2024-05-29 03:05:09 +00:00
|
|
|
httpUtil "github.com/1Panel-dev/1Panel/backend/utils/http"
|
2023-01-30 13:05:20 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type UpgradeService struct{}
|
|
|
|
|
|
|
|
type IUpgradeService interface {
|
2023-02-05 15:48:37 +00:00
|
|
|
Upgrade(req dto.Upgrade) error
|
2023-03-21 07:16:28 +00:00
|
|
|
LoadNotes(req dto.Upgrade) (string, error)
|
2023-01-30 13:05:20 +00:00
|
|
|
SearchUpgrade() (*dto.UpgradeInfo, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
func NewIUpgradeService() IUpgradeService {
|
|
|
|
return &UpgradeService{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *UpgradeService) SearchUpgrade() (*dto.UpgradeInfo, error) {
|
2023-02-17 08:22:59 +00:00
|
|
|
var upgrade dto.UpgradeInfo
|
2023-02-10 10:07:29 +00:00
|
|
|
currentVersion, err := settingRepo.Get(settingRepo.WithByKey("SystemVersion"))
|
2023-01-30 13:05:20 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-04-24 15:12:12 +00:00
|
|
|
DeveloperMode, err := settingRepo.Get(settingRepo.WithByKey("DeveloperMode"))
|
2023-02-17 08:22:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2023-01-30 13:05:20 +00:00
|
|
|
}
|
2024-04-24 15:12:12 +00:00
|
|
|
|
|
|
|
upgrade.TestVersion, upgrade.NewVersion, upgrade.LatestVersion = u.loadVersionByMode(DeveloperMode.Value, currentVersion.Value)
|
2024-05-08 06:32:23 +00:00
|
|
|
var itemVersion string
|
|
|
|
if len(upgrade.LatestVersion) != 0 {
|
|
|
|
itemVersion = upgrade.LatestVersion
|
|
|
|
}
|
|
|
|
if len(upgrade.NewVersion) != 0 {
|
2023-03-24 03:52:10 +00:00
|
|
|
itemVersion = upgrade.NewVersion
|
|
|
|
}
|
2024-05-08 06:32:23 +00:00
|
|
|
if (global.CONF.System.Mode == "dev" || DeveloperMode.Value == "enable") && len(upgrade.TestVersion) != 0 {
|
|
|
|
itemVersion = upgrade.TestVersion
|
|
|
|
}
|
|
|
|
if len(itemVersion) == 0 {
|
|
|
|
return &upgrade, nil
|
|
|
|
}
|
2024-05-08 10:46:23 +00:00
|
|
|
mode := global.CONF.System.Mode
|
|
|
|
if strings.Contains(itemVersion, "beta") {
|
|
|
|
mode = "beta"
|
|
|
|
}
|
|
|
|
notes, err := u.loadReleaseNotes(fmt.Sprintf("%s/%s/%s/release/1panel-%s-release-notes", global.CONF.System.RepoUrl, mode, itemVersion, itemVersion))
|
2023-02-17 08:22:59 +00:00
|
|
|
if err != nil {
|
2024-04-24 15:12:12 +00:00
|
|
|
return nil, fmt.Errorf("load releases-notes of version %s failed, err: %v", itemVersion, err)
|
2023-02-17 08:22:59 +00:00
|
|
|
}
|
2023-03-21 07:16:28 +00:00
|
|
|
upgrade.ReleaseNote = notes
|
|
|
|
return &upgrade, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *UpgradeService) LoadNotes(req dto.Upgrade) (string, error) {
|
2024-04-24 15:12:12 +00:00
|
|
|
mode := global.CONF.System.Mode
|
|
|
|
if strings.Contains(req.Version, "beta") {
|
|
|
|
mode = "beta"
|
|
|
|
}
|
|
|
|
notes, err := u.loadReleaseNotes(fmt.Sprintf("%s/%s/%s/release/1panel-%s-release-notes", global.CONF.System.RepoUrl, mode, req.Version, req.Version))
|
2023-02-17 08:22:59 +00:00
|
|
|
if err != nil {
|
2023-05-30 07:30:57 +00:00
|
|
|
return "", fmt.Errorf("load releases-notes of version %s failed, err: %v", req.Version, err)
|
2023-02-17 08:22:59 +00:00
|
|
|
}
|
2023-03-21 07:16:28 +00:00
|
|
|
return notes, nil
|
2023-01-30 13:05:20 +00:00
|
|
|
}
|
|
|
|
|
2023-02-05 15:48:37 +00:00
|
|
|
func (u *UpgradeService) Upgrade(req dto.Upgrade) error {
|
2023-01-30 13:05:20 +00:00
|
|
|
global.LOG.Info("start to upgrade now...")
|
|
|
|
fileOp := files.NewFileOp()
|
2024-06-28 06:04:08 +00:00
|
|
|
timeStr := time.Now().Format(constant.DateTimeSlimLayout)
|
2023-08-01 14:05:14 +00:00
|
|
|
rootDir := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("upgrade/upgrade_%s/downloads", timeStr))
|
|
|
|
originalDir := path.Join(global.CONF.System.TmpDir, fmt.Sprintf("upgrade/upgrade_%s/original", timeStr))
|
2023-02-05 15:48:37 +00:00
|
|
|
if err := os.MkdirAll(rootDir, os.ModePerm); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := os.MkdirAll(originalDir, os.ModePerm); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-06-02 09:03:20 +00:00
|
|
|
itemArch, err := loadArch()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-01-30 13:05:20 +00:00
|
|
|
|
2024-05-10 06:56:24 +00:00
|
|
|
mode := global.CONF.System.Mode
|
|
|
|
if strings.Contains(req.Version, "beta") {
|
|
|
|
mode = "beta"
|
|
|
|
}
|
|
|
|
downloadPath := fmt.Sprintf("%s/%s/%s/release", global.CONF.System.RepoUrl, mode, req.Version)
|
2023-06-02 09:03:20 +00:00
|
|
|
fileName := fmt.Sprintf("1panel-%s-%s-%s.tar.gz", req.Version, "linux", itemArch)
|
2023-02-02 07:01:37 +00:00
|
|
|
_ = settingRepo.Update("SystemStatus", "Upgrading")
|
2023-01-30 13:05:20 +00:00
|
|
|
go func() {
|
2023-09-13 07:54:12 +00:00
|
|
|
_ = global.Cron.Stop()
|
|
|
|
defer func() {
|
|
|
|
global.Cron.Start()
|
|
|
|
}()
|
2024-06-05 15:46:11 +00:00
|
|
|
if err := fileOp.DownloadFileWithProxy(downloadPath+"/"+fileName, rootDir+"/"+fileName); err != nil {
|
2023-02-05 15:48:37 +00:00
|
|
|
global.LOG.Errorf("download service file failed, err: %v", err)
|
2023-02-09 08:36:28 +00:00
|
|
|
_ = settingRepo.Update("SystemStatus", "Free")
|
2023-01-30 13:05:20 +00:00
|
|
|
return
|
|
|
|
}
|
2023-02-05 15:48:37 +00:00
|
|
|
global.LOG.Info("download all file successful!")
|
2023-01-30 13:05:20 +00:00
|
|
|
defer func() {
|
2023-02-05 15:48:37 +00:00
|
|
|
_ = os.Remove(rootDir)
|
2023-01-30 13:05:20 +00:00
|
|
|
}()
|
2024-06-04 08:48:31 +00:00
|
|
|
if err := handleUnTar(rootDir+"/"+fileName, rootDir, ""); err != nil {
|
2023-02-02 07:01:37 +00:00
|
|
|
global.LOG.Errorf("decompress file failed, err: %v", err)
|
2023-02-09 08:36:28 +00:00
|
|
|
_ = settingRepo.Update("SystemStatus", "Free")
|
2023-01-30 13:05:20 +00:00
|
|
|
return
|
|
|
|
}
|
2023-03-14 08:45:32 +00:00
|
|
|
tmpDir := rootDir + "/" + strings.ReplaceAll(fileName, ".tar.gz", "")
|
2023-01-30 13:05:20 +00:00
|
|
|
|
|
|
|
if err := u.handleBackup(fileOp, originalDir); err != nil {
|
2023-02-02 07:01:37 +00:00
|
|
|
global.LOG.Errorf("handle backup original file failed, err: %v", err)
|
2023-02-09 08:36:28 +00:00
|
|
|
_ = settingRepo.Update("SystemStatus", "Free")
|
2023-01-30 13:05:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
global.LOG.Info("backup original data successful, now start to upgrade!")
|
|
|
|
|
2024-04-06 14:32:10 +00:00
|
|
|
if err := common.CopyFile(path.Join(tmpDir, "1panel"), "/usr/local/bin"); err != nil {
|
2023-02-02 07:01:37 +00:00
|
|
|
global.LOG.Errorf("upgrade 1panel failed, err: %v", err)
|
2024-03-01 08:55:02 +00:00
|
|
|
u.handleRollback(originalDir, 1)
|
2023-01-30 13:05:20 +00:00
|
|
|
return
|
|
|
|
}
|
2023-03-14 13:55:28 +00:00
|
|
|
|
2024-04-06 14:32:10 +00:00
|
|
|
if err := common.CopyFile(path.Join(tmpDir, "1pctl"), "/usr/local/bin"); err != nil {
|
2023-02-02 07:01:37 +00:00
|
|
|
global.LOG.Errorf("upgrade 1pctl failed, err: %v", err)
|
2024-03-01 08:55:02 +00:00
|
|
|
u.handleRollback(originalDir, 2)
|
2023-01-30 13:05:20 +00:00
|
|
|
return
|
|
|
|
}
|
2024-12-10 10:36:53 +00:00
|
|
|
_, _ = cmd.Execf("cp -r %s /usr/local/bin", path.Join(tmpDir, "lang"))
|
2024-04-07 15:21:15 +00:00
|
|
|
if _, err := cmd.Execf("sed -i -e 's#BASE_DIR=.*#BASE_DIR=%s#g' /usr/local/bin/1pctl", global.CONF.System.BaseDir); err != nil {
|
2023-03-14 13:55:28 +00:00
|
|
|
global.LOG.Errorf("upgrade basedir in 1pctl failed, err: %v", err)
|
2024-03-01 08:55:02 +00:00
|
|
|
u.handleRollback(originalDir, 2)
|
2023-03-14 13:55:28 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-04-06 14:32:10 +00:00
|
|
|
if err := common.CopyFile(path.Join(tmpDir, "1panel.service"), "/etc/systemd/system"); err != nil {
|
2023-02-02 07:01:37 +00:00
|
|
|
global.LOG.Errorf("upgrade 1panel.service failed, err: %v", err)
|
2024-03-01 08:55:02 +00:00
|
|
|
u.handleRollback(originalDir, 3)
|
2023-01-30 13:05:20 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
global.LOG.Info("upgrade successful!")
|
2023-03-15 07:58:26 +00:00
|
|
|
go writeLogs(req.Version)
|
2023-02-05 15:48:37 +00:00
|
|
|
_ = settingRepo.Update("SystemVersion", req.Version)
|
|
|
|
_ = settingRepo.Update("SystemStatus", "Free")
|
2024-01-02 09:10:13 +00:00
|
|
|
checkPointOfWal()
|
2023-04-17 06:03:01 +00:00
|
|
|
_, _ = cmd.ExecWithTimeOut("systemctl daemon-reload && systemctl restart 1panel.service", 1*time.Minute)
|
2023-01-30 13:05:20 +00:00
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *UpgradeService) handleBackup(fileOp files.FileOp, originalDir string) error {
|
|
|
|
if err := fileOp.Copy("/usr/local/bin/1panel", originalDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := fileOp.Copy("/usr/local/bin/1pctl", originalDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := fileOp.Copy("/etc/systemd/system/1panel.service", originalDir); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-12-10 10:36:53 +00:00
|
|
|
_, _ = cmd.Execf("cp -r /usr/local/bin/lang %s", originalDir)
|
2024-04-22 14:22:27 +00:00
|
|
|
checkPointOfWal()
|
2024-06-04 08:48:31 +00:00
|
|
|
if err := handleTar(path.Join(global.CONF.System.BaseDir, "1panel/db"), originalDir, "db.tar.gz", "db/1Panel.db-*", ""); err != nil {
|
2023-01-30 13:05:20 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-03-01 08:55:02 +00:00
|
|
|
func (u *UpgradeService) handleRollback(originalDir string, errStep int) {
|
2023-02-09 08:36:28 +00:00
|
|
|
_ = settingRepo.Update("SystemStatus", "Free")
|
2024-04-22 14:22:27 +00:00
|
|
|
|
|
|
|
checkPointOfWal()
|
|
|
|
if _, err := os.Stat(path.Join(originalDir, "1Panel.db")); err == nil {
|
|
|
|
if err := common.CopyFile(path.Join(originalDir, "1Panel.db"), global.CONF.System.DbPath); err != nil {
|
|
|
|
global.LOG.Errorf("rollback 1panel db failed, err: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(path.Join(originalDir, "db.tar.gz")); err == nil {
|
2024-06-04 08:48:31 +00:00
|
|
|
if err := handleUnTar(path.Join(originalDir, "db.tar.gz"), global.CONF.System.DbPath, ""); err != nil {
|
2024-04-22 14:22:27 +00:00
|
|
|
global.LOG.Errorf("rollback 1panel db failed, err: %v", err)
|
|
|
|
}
|
2023-01-30 13:05:20 +00:00
|
|
|
}
|
2024-04-06 14:32:10 +00:00
|
|
|
if err := common.CopyFile(path.Join(originalDir, "1panel"), "/usr/local/bin"); err != nil {
|
2023-01-30 13:05:20 +00:00
|
|
|
global.LOG.Errorf("rollback 1pctl failed, err: %v", err)
|
|
|
|
}
|
|
|
|
if errStep == 1 {
|
|
|
|
return
|
|
|
|
}
|
2024-04-06 14:32:10 +00:00
|
|
|
if err := common.CopyFile(path.Join(originalDir, "1pctl"), "/usr/local/bin"); err != nil {
|
2023-01-30 13:05:20 +00:00
|
|
|
global.LOG.Errorf("rollback 1panel failed, err: %v", err)
|
|
|
|
}
|
2024-12-10 10:36:53 +00:00
|
|
|
_, _ = cmd.Execf("cp -r %s /usr/local/bin", path.Join(originalDir, "lang"))
|
|
|
|
|
2023-01-30 13:05:20 +00:00
|
|
|
if errStep == 2 {
|
|
|
|
return
|
|
|
|
}
|
2024-04-06 14:32:10 +00:00
|
|
|
if err := common.CopyFile(path.Join(originalDir, "1panel.service"), "/etc/systemd/system"); err != nil {
|
2023-01-30 13:05:20 +00:00
|
|
|
global.LOG.Errorf("rollback 1panel failed, err: %v", err)
|
|
|
|
}
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
2023-02-09 08:36:28 +00:00
|
|
|
|
2024-04-24 15:12:12 +00:00
|
|
|
func (u *UpgradeService) loadVersionByMode(developer, currentVersion string) (string, string, string) {
|
|
|
|
var current, latest string
|
|
|
|
if global.CONF.System.Mode == "dev" {
|
|
|
|
betaVersionLatest := u.loadVersion(true, currentVersion, "beta")
|
|
|
|
devVersionLatest := u.loadVersion(true, currentVersion, "dev")
|
|
|
|
if common.ComparePanelVersion(betaVersionLatest, devVersionLatest) {
|
|
|
|
return betaVersionLatest, "", ""
|
|
|
|
}
|
|
|
|
return devVersionLatest, "", ""
|
|
|
|
}
|
|
|
|
|
2024-05-08 10:46:23 +00:00
|
|
|
betaVersionLatest := ""
|
2024-04-24 15:12:12 +00:00
|
|
|
latest = u.loadVersion(true, currentVersion, "stable")
|
|
|
|
current = u.loadVersion(false, currentVersion, "stable")
|
2024-05-08 10:46:23 +00:00
|
|
|
if developer == "enable" {
|
|
|
|
betaVersionLatest = u.loadVersion(true, currentVersion, "beta")
|
|
|
|
}
|
|
|
|
if current != latest {
|
|
|
|
return betaVersionLatest, current, latest
|
2024-04-24 15:12:12 +00:00
|
|
|
}
|
|
|
|
|
2024-05-08 10:46:23 +00:00
|
|
|
versionPart := strings.Split(current, ".")
|
|
|
|
if len(versionPart) < 3 {
|
|
|
|
return betaVersionLatest, current, latest
|
|
|
|
}
|
|
|
|
num, _ := strconv.Atoi(versionPart[1])
|
|
|
|
if num == 0 {
|
|
|
|
return betaVersionLatest, current, latest
|
|
|
|
}
|
|
|
|
if num >= 10 {
|
|
|
|
if current[:6] == currentVersion[:6] {
|
|
|
|
return betaVersionLatest, current, ""
|
|
|
|
}
|
|
|
|
return betaVersionLatest, "", latest
|
|
|
|
}
|
|
|
|
if current[:5] == currentVersion[:5] {
|
|
|
|
return betaVersionLatest, current, ""
|
|
|
|
}
|
|
|
|
return betaVersionLatest, "", latest
|
2024-04-24 15:12:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (u *UpgradeService) loadVersion(isLatest bool, currentVersion, mode string) string {
|
|
|
|
path := fmt.Sprintf("%s/%s/latest", global.CONF.System.RepoUrl, mode)
|
2023-03-21 07:16:28 +00:00
|
|
|
if !isLatest {
|
2024-04-24 15:12:12 +00:00
|
|
|
path = fmt.Sprintf("%s/%s/latest.current", global.CONF.System.RepoUrl, mode)
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
2024-06-06 09:37:38 +00:00
|
|
|
_, latestVersionRes, err := httpUtil.HandleGet(path, http.MethodGet, constant.TimeOut20s)
|
2023-03-21 07:16:28 +00:00
|
|
|
if err != nil {
|
2024-04-24 15:12:12 +00:00
|
|
|
global.LOG.Errorf("load latest version from oss failed, err: %v", err)
|
|
|
|
return ""
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
2024-05-29 03:05:09 +00:00
|
|
|
version := string(latestVersionRes)
|
|
|
|
if strings.Contains(version, "<") {
|
2024-04-24 15:12:12 +00:00
|
|
|
global.LOG.Errorf("load latest version from oss failed, err: %v", version)
|
|
|
|
return ""
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
|
|
|
if isLatest {
|
2024-04-24 15:12:12 +00:00
|
|
|
return u.checkVersion(version, currentVersion)
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
versionMap := make(map[string]string)
|
2024-05-29 03:05:09 +00:00
|
|
|
if err := json.Unmarshal(latestVersionRes, &versionMap); err != nil {
|
2024-04-24 15:12:12 +00:00
|
|
|
global.LOG.Errorf("load latest version from oss failed (error unmarshal), err: %v", err)
|
|
|
|
return ""
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
|
|
|
|
2024-04-24 15:12:12 +00:00
|
|
|
versionPart := strings.Split(currentVersion, ".")
|
|
|
|
if len(versionPart) < 3 {
|
|
|
|
global.LOG.Errorf("current version is error format: %s", currentVersion)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
num, _ := strconv.Atoi(versionPart[1])
|
|
|
|
if num == 0 {
|
|
|
|
global.LOG.Errorf("current version is error format: %s", currentVersion)
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
if num >= 10 {
|
|
|
|
if version, ok := versionMap[currentVersion[0:5]]; ok {
|
|
|
|
return u.checkVersion(version, currentVersion)
|
|
|
|
}
|
|
|
|
return ""
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
|
|
|
if version, ok := versionMap[currentVersion[0:4]]; ok {
|
2024-04-24 15:12:12 +00:00
|
|
|
return u.checkVersion(version, currentVersion)
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *UpgradeService) checkVersion(v2, v1 string) string {
|
|
|
|
addSuffix := false
|
|
|
|
if !strings.Contains(v1, "-") {
|
|
|
|
v1 = v1 + "-lts"
|
|
|
|
}
|
|
|
|
if !strings.Contains(v2, "-") {
|
|
|
|
addSuffix = true
|
|
|
|
v2 = v2 + "-lts"
|
|
|
|
}
|
|
|
|
if common.ComparePanelVersion(v2, v1) {
|
|
|
|
if addSuffix {
|
|
|
|
return strings.TrimSuffix(v2, "-lts")
|
|
|
|
}
|
|
|
|
return v2
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
2024-04-24 15:12:12 +00:00
|
|
|
return ""
|
2023-03-21 07:16:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (u *UpgradeService) loadReleaseNotes(path string) (string, error) {
|
2024-06-06 09:37:38 +00:00
|
|
|
_, releaseNotes, err := httpUtil.HandleGet(path, http.MethodGet, constant.TimeOut20s)
|
2023-03-21 07:16:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2024-05-29 03:05:09 +00:00
|
|
|
return string(releaseNotes), nil
|
2023-01-30 13:05:20 +00:00
|
|
|
}
|
2023-06-02 09:03:20 +00:00
|
|
|
|
|
|
|
func loadArch() (string, error) {
|
2024-03-07 03:05:05 +00:00
|
|
|
std, err := cmd.Exec("uname -a")
|
|
|
|
if err != nil {
|
|
|
|
return "", fmt.Errorf("std: %s, err: %s", std, err.Error())
|
|
|
|
}
|
|
|
|
if strings.Contains(std, "x86_64") {
|
|
|
|
return "amd64", nil
|
|
|
|
}
|
|
|
|
if strings.Contains(std, "arm64") || strings.Contains(std, "aarch64") {
|
|
|
|
return "arm64", nil
|
|
|
|
}
|
|
|
|
if strings.Contains(std, "armv7l") {
|
|
|
|
return "armv7", nil
|
|
|
|
}
|
|
|
|
if strings.Contains(std, "ppc64le") {
|
|
|
|
return "ppc64le", nil
|
|
|
|
}
|
|
|
|
if strings.Contains(std, "s390x") {
|
|
|
|
return "s390x", nil
|
2023-06-02 09:03:20 +00:00
|
|
|
}
|
2024-03-07 03:05:05 +00:00
|
|
|
return "", fmt.Errorf("unsupported such arch: %s", std)
|
2023-06-02 09:03:20 +00:00
|
|
|
}
|