mirror of
https://github.com/kairos-io/immucore.git
synced 2025-06-24 22:02:14 +00:00
- set debug level via cmdline - set default RW paths needed ALWAYS to boot a working system, even with no config files(recovery) - Check for loop device before mounting it to avoid duplicated mounts - Force overlay and bind arrays to uniqueness - Rename OverlayDir to OverlayDirs to better represent the content Signed-off-by: Itxaka <itxaka@spectrocloud.com>
71 lines
1.3 KiB
Go
71 lines
1.3 KiB
Go
package utils
|
|
|
|
import (
|
|
"github.com/kairos-io/kairos/sdk/state"
|
|
"os"
|
|
"strings"
|
|
)
|
|
|
|
func BootedFromCD() (bool, error) {
|
|
runtime, err := state.NewRuntime()
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
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_SYSTEM"
|
|
default:
|
|
return ""
|
|
}
|
|
}
|
|
|
|
func IsRecovery() bool {
|
|
runtime, err := state.NewRuntime()
|
|
if err != nil {
|
|
return false
|
|
}
|
|
switch runtime.BootState {
|
|
case "recovery_boot":
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|
|
|
|
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"
|
|
}
|
|
}
|
|
|
|
// UniqueSlice removes duplicated entries from a slice.So dumb. Like really? Why not have a set which enforces uniqueness????
|
|
func UniqueSlice(slice []string) []string {
|
|
keys := make(map[string]bool)
|
|
var list []string
|
|
for _, entry := range slice {
|
|
if _, value := keys[entry]; !value {
|
|
keys[entry] = true
|
|
list = append(list, entry)
|
|
}
|
|
}
|
|
return list
|
|
}
|