This commit is contained in:
2025-04-13 19:54:04 +03:00
parent f26b72b2a2
commit b8cb7af3bb
14 changed files with 213 additions and 261 deletions

View File

@@ -30,6 +30,7 @@ import (
"go.elara.ws/vercmp"
"golang.org/x/exp/maps"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/config"
database "gitea.plemya-x.ru/Plemya-x/ALR/internal/db"
"gitea.plemya-x.ru/Plemya-x/ALR/internal/overrides"
@@ -57,8 +58,7 @@ func UpgradeCmd() *cli.Command {
Action: func(c *cli.Context) error {
err := utils.DropCapsToAlrUser()
if err != nil {
slog.Error(gotext.Get("Error dropping capabilities"), "err", err)
os.Exit(1)
return cliutils.FormatCliExit(gotext.Get("Error dropping capabilities"), err)
}
ctx := c.Context
@@ -66,16 +66,14 @@ func UpgradeCmd() *cli.Command {
cfg := config.New()
err = cfg.Load()
if err != nil {
slog.Error(gotext.Get("Error loading config"), "err", err)
os.Exit(1)
return cliutils.FormatCliExit(gotext.Get("Error loading config"), err)
}
db := database.New(cfg)
rs := repos.New(cfg, db)
err = db.Init(ctx)
if err != nil {
slog.Error(gotext.Get("Error initialization database"), "err", err)
os.Exit(1)
return cliutils.FormatCliExit(gotext.Get("Error initialization database"), err)
}
slog.Debug("builder setup")
@@ -87,8 +85,7 @@ func UpgradeCmd() *cli.Command {
info, err := distro.ParseOSRelease(ctx)
slog.Debug("ParseOSRelease", "err", err)
if err != nil {
slog.Error(gotext.Get("Error parsing os-release file"), "err", err)
os.Exit(1)
return cliutils.FormatCliExit(gotext.Get("Error parsing os-release file"), err)
}
mgr := manager.Detect()
@@ -101,15 +98,13 @@ func UpgradeCmd() *cli.Command {
slog.Debug("autopull")
err = rs.Pull(ctx, cfg.Repos())
if err != nil {
slog.Error(gotext.Get("Error pulling repos"), "err", err)
os.Exit(1)
return cliutils.FormatCliExit(gotext.Get("Error pulling repos"), err)
}
}
updates, err := checkForUpdates(ctx, mgr, cfg, db, rs, info)
if err != nil {
slog.Error(gotext.Get("Error checking for updates"), "err", err)
os.Exit(1)
return cliutils.FormatCliExit(gotext.Get("Error checking for updates"), err)
}
if len(updates) > 0 {
@@ -126,8 +121,7 @@ func UpgradeCmd() *cli.Command {
updates,
)
if err != nil {
slog.Error(gotext.Get("Error checking for updates"), "err", err)
os.Exit(1)
return cliutils.FormatCliExit(gotext.Get("Error checking for updates"), err)
}
} else {
slog.Info(gotext.Get("There is nothing to do."))