mirror of
https://github.com/kairos-io/immucore.git
synced 2025-09-02 15:14:27 +00:00
several improvements
- drop vfs - less hardcoded stuff, use the runtime status - Remove things that syscalls dont understand (defaults, auto) Signed-off-by: Itxaka <itxaka@spectrocloud.com>
This commit is contained in:
@@ -2,10 +2,11 @@ package utils
|
||||
|
||||
import (
|
||||
"github.com/kairos-io/kairos/sdk/state"
|
||||
"github.com/twpayne/go-vfs"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func BootedFromCD(fs vfs.FS) (bool, error) {
|
||||
func BootedFromCD() (bool, error) {
|
||||
runtime, err := state.NewRuntime()
|
||||
if err != nil {
|
||||
return false, err
|
||||
@@ -13,3 +14,48 @@ func BootedFromCD(fs vfs.FS) (bool, error) {
|
||||
|
||||
return runtime.BootState == state.LiveCD, nil
|
||||
}
|
||||
|
||||
func BootStateToLabel() string {
|
||||
runtime, err := state.NewRuntime()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
switch runtime.BootState {
|
||||
case "active_boot":
|
||||
return "COS_ACTIVE"
|
||||
case "passive_boot":
|
||||
return "COS_PASSIVE"
|
||||
case "recovery_boot":
|
||||
return "COS_RECOVERY"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func BootStateToImage() string {
|
||||
runtime, err := state.NewRuntime()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
switch runtime.BootState {
|
||||
case "active_boot":
|
||||
return "/cOS/active.img"
|
||||
case "passive_boot":
|
||||
return "/cOS/passive.img"
|
||||
case "recovery_boot":
|
||||
return "/recovery.img"
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func GetRootDir() string {
|
||||
cmdline, _ := os.ReadFile("/proc/cmdline")
|
||||
switch {
|
||||
case strings.Contains(string(cmdline), "IMMUCORE_NOPIVOT"):
|
||||
return "/"
|
||||
default:
|
||||
// Default is sysroot for normal no-pivot boot
|
||||
return "/sysroot"
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user