diff --git a/internal/agent/install.go b/internal/agent/install.go index 4895704..c9317d0 100644 --- a/internal/agent/install.go +++ b/internal/agent/install.go @@ -65,6 +65,13 @@ func Install(dir ...string) error { } }) + // Try to pull userdata once more. best-effort + if _, err := os.Stat("/oem/userdata"); err != nil { + if err := machine.ExecuteCloudConfig("/system/oem/00_datasource.yaml", "rootfs.before"); err != nil { + fmt.Println("Warning: Failed pulling from datasources") + } + } + // Reads config, and if present and offline is defined, // runs the installation cc, err := config.Scan(config.Directories(dir...), config.MergeBootLine) diff --git a/internal/machine/machine.go b/internal/machine/machine.go index 67e6433..7d6d81e 100644 --- a/internal/machine/machine.go +++ b/internal/machine/machine.go @@ -145,3 +145,13 @@ func SentinelExist(f string) bool { } return false } + +func ExecuteInlineCloudConfig(cloudConfig, stage string) error { + _, err := utils.ShellSTDIN(cloudConfig, fmt.Sprintf("elemental run-stage -s %s -", stage)) + return err +} + +func ExecuteCloudConfig(file, stage string) error { + _, err := utils.SH(fmt.Sprintf("elemental run-stage -s %s %s", stage, file)) + return err +} diff --git a/internal/utils/sh.go b/internal/utils/sh.go index 4f0e619..25758ec 100644 --- a/internal/utils/sh.go +++ b/internal/utils/sh.go @@ -1,6 +1,7 @@ package utils import ( + "bytes" "io/ioutil" "os" "os/exec" @@ -31,3 +32,12 @@ func Shell() *exec.Cmd { 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 +}