Use SDK to get machine state

This commit is contained in:
mudler
2023-02-06 14:49:35 +01:00
parent 46a7ee94ed
commit 13e11fca24
4 changed files with 50 additions and 12 deletions

View File

@@ -1,20 +1,15 @@
package utils
import (
"regexp"
"github.com/kairos-io/kairos/sdk/state"
"github.com/twpayne/go-vfs"
)
func BootedFromCD(fs vfs.FS) bool {
cdlabel := regexp.MustCompile("root=live:CDLABEL=")
cmdLine, err := fs.ReadFile("/proc/cmdline")
func BootedFromCD(fs vfs.FS) (bool, error) {
runtime, err := state.NewRuntime()
if err != nil {
return false
return false, err
}
if cdlabel.MatchString(string(cmdLine)) {
return true
}
return false
return runtime.BootState == state.LiveCD, nil
}