Skip to content

Commit 7fde2eb

Browse files
authored
Fix the condition check with the pre-install in generic installer (#255)
1 parent 70e6a51 commit 7fde2eb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

pkg/os/generic_installer.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package os
22

33
import (
44
"fmt"
5+
"io/ioutil"
6+
"runtime"
7+
"strings"
8+
59
"github.com/linuxsuren/http-downloader/pkg/exec"
610
"github.com/linuxsuren/http-downloader/pkg/os/apt"
711
"github.com/linuxsuren/http-downloader/pkg/os/core"
812
"github.com/linuxsuren/http-downloader/pkg/os/yum"
913
"gopkg.in/yaml.v3"
10-
"io/ioutil"
11-
"runtime"
12-
"strings"
1314
)
1415

1516
type genericPackages struct {
@@ -91,16 +92,23 @@ func (i *genericPackage) Install() (err error) {
9192
for index := range i.PreInstall {
9293
preInstall := i.PreInstall[index]
9394

95+
needInstall := false
9496
if preInstall.IssuePrefix != "" && runtime.GOOS == "linux" {
9597
var data []byte
9698
if data, err = ioutil.ReadFile("/etc/issue"); err != nil {
9799
return
98100
}
99101

100102
if strings.HasPrefix(string(data), preInstall.IssuePrefix) {
101-
if err = exec.RunCommand(preInstall.Cmd.Cmd, preInstall.Cmd.Args...); err != nil {
102-
return
103-
}
103+
needInstall = true
104+
}
105+
} else if preInstall.IssuePrefix == "" {
106+
needInstall = true
107+
}
108+
109+
if needInstall {
110+
if err = exec.RunCommand(preInstall.Cmd.Cmd, preInstall.Cmd.Args...); err != nil {
111+
return
104112
}
105113
}
106114
}

0 commit comments

Comments
 (0)