Complete rewrite of the bootstraper tool

This commit is contained in:
2022-06-15 17:29:45 +02:00
parent 5085bd4d69
commit b5172da6a7
28 changed files with 1263 additions and 148 deletions

View File

@ -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
View 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
}