1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-05-11 14:59:38 -04:00

refactor(sysupdate): improve cmd handling, formatted colors & progress indication

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
purian23
2026-05-04 13:13:44 -04:00
parent cfe6e6867e
commit 408beb202c
9 changed files with 113 additions and 23 deletions

View File

@@ -49,7 +49,8 @@ func (aptBackend) Upgrade(ctx context.Context, opts UpgradeOptions, onLine func(
if len(names) == 0 {
return nil
}
argv := append([]string{"pkexec", "env", "DEBIAN_FRONTEND=noninteractive", "LC_ALL=C", bin, "install", "-y", "--only-upgrade"}, names...)
privesc := privescBin(opts.UseSudo)
argv := append([]string{privesc, "env", "DEBIAN_FRONTEND=noninteractive", "LC_ALL=C", bin, "install", "-y", "--only-upgrade"}, names...)
return Run(ctx, argv, RunOptions{OnLine: onLine})
}

View File

@@ -43,18 +43,19 @@ func (b dnfBackend) CheckUpdates(ctx context.Context) ([]Package, error) {
func (b dnfBackend) Upgrade(ctx context.Context, opts UpgradeOptions, onLine func(string)) error {
if opts.DryRun {
return Run(ctx, []string{b.bin, "upgrade", "--refresh", "--assumeno"}, RunOptions{OnLine: onLine})
return Run(ctx, []string{b.bin, "upgrade", "--assumeno"}, RunOptions{OnLine: onLine})
}
names := pickTargetNames(opts.Targets, b.bin, true)
if len(names) == 0 {
return nil
}
argv := append([]string{"pkexec", b.bin, "upgrade", "--refresh", "-y"}, names...)
privesc := privescBin(opts.UseSudo)
argv := append([]string{privesc, b.bin, "upgrade", "-y"}, names...)
return Run(ctx, argv, RunOptions{OnLine: onLine})
}
func dnfListUpgrades(ctx context.Context, bin string) (string, error) {
cmd := exec.CommandContext(ctx, bin, "list", "--upgrades", "--quiet")
cmd := exec.CommandContext(ctx, bin, "list", "--upgrades", "--refresh", "--quiet")
out, err := cmd.Output()
if err == nil {
return string(out), nil

View File

@@ -47,7 +47,8 @@ func (b pacmanBackend) Upgrade(ctx context.Context, opts UpgradeOptions, onLine
if len(names) == 0 {
return nil
}
argv := append([]string{"pkexec", "pacman", "-Sy", "--noconfirm", "--needed"}, names...)
privesc := privescBin(opts.UseSudo)
argv := append([]string{privesc, "pacman", "-Sy", "--noconfirm", "--needed"}, names...)
return Run(ctx, argv, RunOptions{OnLine: onLine})
}

View File

@@ -78,6 +78,7 @@ func (zypperBackend) Upgrade(ctx context.Context, opts UpgradeOptions, onLine fu
if len(names) == 0 {
return nil
}
argv := append([]string{"pkexec", "zypper", "--non-interactive", "update"}, names...)
privesc := privescBin(opts.UseSudo)
argv := append([]string{privesc, "zypper", "--non-interactive", "update"}, names...)
return Run(ctx, argv, RunOptions{OnLine: onLine})
}

View File

@@ -9,6 +9,8 @@ import (
"os/exec"
"sync"
"syscall"
"github.com/AvengeMedia/DankMaterialShell/core/internal/privesc"
)
type RunOptions struct {
@@ -77,6 +79,18 @@ func Capture(ctx context.Context, argv []string) (string, error) {
return string(out), err
}
// privescBin returns the binary to use for privilege escalation.
// When useSudo is true it auto-detects the best available tool (sudo/doas/run0).
// When false it falls back to pkexec for GUI callers.
func privescBin(useSudo bool) string {
if useSudo {
if t, err := privesc.Detect(); err == nil {
return t.Name()
}
}
return "pkexec"
}
func findTerminal(override string) string {
if override != "" && commandExists(override) {
return override

View File

@@ -76,6 +76,7 @@ type UpgradeOptions struct {
IncludeFlatpak bool
IncludeAUR bool
DryRun bool
UseSudo bool
CustomCommand string
Terminal string
Targets []Package