From b574663cddfe809a53c6c7fed6e8fe61d410fa5f Mon Sep 17 00:00:00 2001 From: dkeven <82354774+dkeven@users.noreply.github.com> Date: Mon, 29 Sep 2025 17:47:14 +0800 Subject: [PATCH] fix(cli): unify apt tool installation check for both Ubuntu & Debian (#1889) --- cli/pkg/bootstrap/patch/tasks.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cli/pkg/bootstrap/patch/tasks.go b/cli/pkg/bootstrap/patch/tasks.go index 00fa02e7e..9eab36949 100644 --- a/cli/pkg/bootstrap/patch/tasks.go +++ b/cli/pkg/bootstrap/patch/tasks.go @@ -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 {