diff --git a/internal/agent/agent.go b/internal/agent/agent.go index ad2853d..18229dc 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -24,6 +24,12 @@ func Run(apiAddress string, dir []string, force bool) error { if err != nil { return err } + bf := machine.BootFrom() + if c.Install != nil && c.Install.Auto && (bf == machine.NetBoot || bf == machine.LiveCDBoot) { + // Don't go ahead if we are asked to install from a booting live medium + fmt.Println("Agent run aborted. Installation being performed from live medium") + return nil + } os.MkdirAll("/var/log/c3os", 0600) fileName := filepath.Join("/var/log/c3os", "agent-provider.log") diff --git a/internal/machine/machine.go b/internal/machine/machine.go index 28f65c0..67e6433 100644 --- a/internal/machine/machine.go +++ b/internal/machine/machine.go @@ -4,6 +4,7 @@ import ( "fmt" "io/ioutil" "os" + "strings" "github.com/c3os-io/c3os/internal/machine/openrc" "github.com/c3os-io/c3os/internal/machine/systemd" @@ -20,6 +21,37 @@ type Service interface { Restart() error } +const ( + PassiveBoot = "passive" + ActiveBoot = "active" + RecoveryBoot = "recovery" + LiveCDBoot = "liveCD" + NetBoot = "netboot" + UnknownBoot = "unknown" +) + +// BootFrom returns the booting partition of the SUT +func BootFrom() string { + out, err := utils.SH("cat /proc/cmdline") + if err != nil { + return UnknownBoot + } + switch { + case strings.Contains(out, "COS_ACTIVE"): + return ActiveBoot + case strings.Contains(out, "COS_PASSIVE"): + return PassiveBoot + case strings.Contains(out, "COS_RECOVERY"), strings.Contains(out, "COS_SYSTEM"): + return RecoveryBoot + case strings.Contains(out, "live:CDLABEL"): + return LiveCDBoot + case strings.Contains(out, "netboot"): + return NetBoot + default: + return UnknownBoot + } +} + func EdgeVPN(instance, rootDir string) (Service, error) { if utils.IsOpenRCBased() { return openrc.NewService(