Complete rewrite of the bootstraper tool
This commit is contained in:
@ -1,6 +1,9 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
|
||||
"github.com/hashicorp/hcl/v2"
|
||||
)
|
||||
|
||||
@ -15,3 +18,15 @@ func CheckDiags(diag hcl.Diagnostics) {
|
||||
panic(diag.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// Execute a system command ...
|
||||
func RunSystemCommand(name string, arg ...string) ([]byte, []byte, error) {
|
||||
var stdOut bytes.Buffer
|
||||
var stdErr bytes.Buffer
|
||||
|
||||
cmd := exec.Command(name, arg...)
|
||||
cmd.Stderr = &stdErr
|
||||
cmd.Stdout = &stdOut
|
||||
err := cmd.Run()
|
||||
return stdOut.Bytes(), stdErr.Bytes(), err
|
||||
}
|
||||
|
27
pkg/utils/os.go
Normal file
27
pkg/utils/os.go
Normal file
@ -0,0 +1,27 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
ini "gopkg.in/ini.v1"
|
||||
)
|
||||
|
||||
var osReleaseFile = "/etc/os-release"
|
||||
|
||||
func ReadOSRelease() (map[string]string, error) {
|
||||
cfg, err := ini.Load(osReleaseFile)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Fail to read file: %v ", err)
|
||||
}
|
||||
|
||||
ConfigParams := make(map[string]string)
|
||||
ConfigParams["ID"] = cfg.Section("").Key("ID").String()
|
||||
idLike := cfg.Section("").Key("ID_LIKE").String()
|
||||
if idLike != "" {
|
||||
ConfigParams["ID_LIKE"] = idLike
|
||||
} else {
|
||||
ConfigParams["ID_LIKE"] = ConfigParams["ID"]
|
||||
}
|
||||
|
||||
return ConfigParams, nil
|
||||
}
|
Reference in New Issue
Block a user