Skip to content

Commit

Permalink
Fix the condition check with the pre-install in generic installer (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed May 22, 2022
1 parent 70e6a51 commit 7fde2eb
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pkg/os/generic_installer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package os

import (
"fmt"
"io/ioutil"
"runtime"
"strings"

"github.com/linuxsuren/http-downloader/pkg/exec"
"github.com/linuxsuren/http-downloader/pkg/os/apt"
"github.com/linuxsuren/http-downloader/pkg/os/core"
"github.com/linuxsuren/http-downloader/pkg/os/yum"
"gopkg.in/yaml.v3"
"io/ioutil"
"runtime"
"strings"
)

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

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

if strings.HasPrefix(string(data), preInstall.IssuePrefix) {
if err = exec.RunCommand(preInstall.Cmd.Cmd, preInstall.Cmd.Args...); err != nil {
return
}
needInstall = true
}
} else if preInstall.IssuePrefix == "" {
needInstall = true
}

if needInstall {
if err = exec.RunCommand(preInstall.Cmd.Cmd, preInstall.Cmd.Args...); err != nil {
return
}
}
}
Expand Down

0 comments on commit 7fde2eb

Please sign in to comment.