immucore/main.go

100 lines
2.4 KiB
Go
Raw Normal View History

2023-01-12 18:10:10 +00:00
package main
import (
"context"
2023-01-12 18:10:10 +00:00
"fmt"
"os"
"github.com/kairos-io/immucore/internal/utils"
"github.com/kairos-io/immucore/internal/version"
2024-03-20 10:48:51 +00:00
"github.com/kairos-io/immucore/pkg/dag"
"github.com/kairos-io/immucore/pkg/state"
"github.com/spectrocloud-labs/herd"
"github.com/urfave/cli/v2"
2023-01-12 18:10:10 +00:00
)
// Apply Immutability profiles.
func main() {
app := cli.NewApp()
app.Version = version.GetVersion()
app.Authors = []*cli.Author{{Name: "Kairos authors"}}
app.Copyright = "kairos authors"
app.Action = func(c *cli.Context) (err error) {
var targetDevice, targetImage string
2024-03-20 10:48:51 +00:00
var st *state.State
utils.MountBasic()
utils.SetLogger()
v := version.Get()
utils.Log.Info().Str("commit", v.GitCommit).Str("compiled with", v.GoVersion).Str("version", v.Version).Msg("Immucore")
cmdline, _ := os.ReadFile(utils.GetHostProcCmdline())
utils.Log.Debug().Str("content", string(cmdline)).Msg("cmdline")
g := herd.DAG(herd.EnableInit)
// Get targets and state
targetImage, targetDevice, err = utils.GetTarget(c.Bool("dry-run"))
if err != nil {
return err
}
2024-03-20 10:48:51 +00:00
st = &state.State{
Rootdir: utils.GetRootDir(),
TargetDevice: targetDevice,
TargetImage: targetImage,
RootMountMode: utils.RootRW(),
OverlayBase: utils.GetOverlayBase(),
}
if utils.DisableImmucore() {
utils.Log.Info().Msg("Stanza rd.cos.disable/rd.immucore.disable on the cmdline or booting from CDROM/Netboot/Squash recovery. Disabling immucore.")
2024-03-20 10:48:51 +00:00
err = dag.RegisterLiveMedia(st, g)
} else if utils.IsUKI() {
utils.Log.Info().Msg("UKI booting!")
2024-03-20 10:48:51 +00:00
err = dag.RegisterUKI(st, g)
} else {
utils.Log.Info().Msg("Booting on active/passive/recovery.")
2024-03-20 10:48:51 +00:00
err = dag.RegisterNormalBoot(st, g)
}
if err != nil {
return err
}
2024-03-20 10:48:51 +00:00
utils.Log.Info().Msg(st.WriteDAG(g))
// Once we print the dag we can exit already
if c.Bool("dry-run") {
return nil
}
err = g.Run(context.Background())
2024-03-20 10:48:51 +00:00
utils.Log.Info().Msg(st.WriteDAG(g))
return err
}
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "dry-run",
},
}
app.Commands = []*cli.Command{
{
Name: "version",
Usage: "version",
2024-03-18 13:38:57 +00:00
Action: func(_ *cli.Context) error {
utils.SetLogger()
v := version.Get()
utils.Log.Info().Str("commit", v.GitCommit).Str("compiled with", v.GoVersion).Str("version", v.Version).Msg("Immucore")
return nil
},
},
2023-01-12 18:10:10 +00:00
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}