Set the sentinel file from immucore directly

Also add a missing livecd sentinel file

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
This commit is contained in:
Itxaka
2023-02-13 21:42:45 +01:00
parent 1d6572faaa
commit 076bba95dc
4 changed files with 42 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import (
"github.com/joho/godotenv"
"github.com/kairos-io/kairos/sdk/state"
"os"
"path/filepath"
"strings"
)
@@ -118,3 +119,36 @@ func CleanupSlice(slice []string) []string {
}
return cleanSlice
}
// SetSentinelFile sets the sentinel file to identify the boot mode.
// This is used by several things to know in which state they are, for example cloud configs
func SetSentinelFile() error {
var sentinel string
err := CreateIfNotExists("/run/cos/")
if err != nil {
return err
}
runtime, err := state.NewRuntime()
if err != nil {
return err
}
switch runtime.BootState {
case state.Active:
sentinel = "active_mode"
case state.Passive:
sentinel = "passive_mode"
case state.Recovery:
sentinel = "recovery_mode"
case state.LiveCD:
sentinel = "live_mode"
default:
sentinel = string(state.Unknown)
}
err = os.WriteFile(filepath.Join("/run/cos/", sentinel), []byte("1"), os.ModePerm)
if err != nil {
return err
}
return nil
}