fix(cli): unify apt tool installation check for both Ubuntu & Debian (#1889)

This commit is contained in:
dkeven 2025-09-29 17:47:14 +08:00 committed by GitHub
parent 77076f97fe
commit b574663cdd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -63,6 +63,16 @@ func (t *PatchTask) Execute(runtime connector.Runtime) error {
var systemInfo = runtime.GetSystemInfo()
var platformFamily = systemInfo.GetOsPlatformFamily()
var aptToolAvailable bool
if _, err := util.GetCommand("add-apt-repository"); err == nil {
aptToolAvailable = true
} else {
if _, err := runtime.GetRunner().SudoCmd("apt install -y software-properties-common", false, true); err == nil {
aptToolAvailable = true
} else {
logger.Infof("software-properties-common not available, try to update apt sources ourself")
}
}
var pkgManager = systemInfo.GetPkgManager()
switch platformFamily {
case common.Debian:
@ -70,16 +80,7 @@ func (t *PatchTask) Execute(runtime connector.Runtime) error {
repoURL := "https://deb.debian.org/debian"
suite := systemInfo.GetDebianVersionCode()
components := []string{"contrib", "non-free"}
var aptToolAvailable bool
if _, err := util.GetCommand("add-apt-repository"); err == nil {
aptToolAvailable = true
} else {
if _, err := runtime.GetRunner().SudoCmd("apt install -y software-properties-common", false, true); err == nil {
aptToolAvailable = true
} else {
logger.Infof("software-properties-common not available, try to update apt sources ourself")
}
}
if aptToolAvailable {
cmd := fmt.Sprintf("add-apt-repository '%s %s %s %s' -y", sourceType, repoURL, suite, strings.Join(components, " "))
if _, err := runtime.GetRunner().SudoCmd(cmd, false, true); err != nil {