kairos-agent/internal/utils/sh.go
Ettore Di Giacinto 09b41735f4 gear: Be sure to run datasource before install
Seems in certain condition the datasource is kicking late and serving the datasource not fast as wanted.

We make sure to pull it before install, so we also give chance to convoluted setups to pull configs.

Also wires up autoinstall tests to CI
2022-07-21 21:38:07 +00:00

44 lines
838 B
Go

package utils
import (
"bytes"
"io/ioutil"
"os"
"os/exec"
"github.com/joho/godotenv"
)
func SH(c string) (string, error) {
o, err := exec.Command("/bin/sh", "-c", c).CombinedOutput()
return string(o), err
}
func WriteEnv(envFile string, config map[string]string) error {
content, _ := ioutil.ReadFile(envFile)
env, _ := godotenv.Unmarshal(string(content))
for key, val := range config {
env[key] = val
}
return godotenv.Write(env, envFile)
}
func Shell() *exec.Cmd {
cmd := exec.Command("/bin/sh")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
return cmd
}
func ShellSTDIN(s, c string) (string, error) {
cmd := exec.Command("/bin/sh", "-c", c)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = bytes.NewBuffer([]byte(s))
o, err := cmd.CombinedOutput()
return string(o), err
}