mirror of
https://github.com/beclab/Olares
synced 2026-05-24 09:18:23 +00:00
fix(cli): unify apt tool installation check for both Ubuntu & Debian (#1889)
This commit is contained in:
parent
77076f97fe
commit
b574663cdd
1 changed files with 11 additions and 10 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue