1
0
mirror of https://github.com/kairos-io/immucore.git synced 2025-05-07 23:57:57 +00:00
immucore/main.go
Itxaka fecfbf8e92
Add tests and fix some issues that arised from testing ()
* Add tests and fix some issues that arised from testing

Mainly around the cmdargs and how many items it returns.
Also drop the iso target and jobs as its not necessary now

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>

* Lint

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>

---------

Signed-off-by: Itxaka <itxaka.garcia@spectrocloud.com>
2023-03-02 16:46:25 +01:00

99 lines
2.4 KiB
Go

package main
import (
"context"
"fmt"
"os"
"github.com/kairos-io/immucore/internal/utils"
"github.com/kairos-io/immucore/internal/version"
"github.com/kairos-io/immucore/pkg/mount"
"github.com/spectrocloud-labs/herd"
"github.com/urfave/cli/v2"
)
// 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
var state *mount.State
utils.MountProc()
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
}
state = &mount.State{
Rootdir: utils.GetRootDir(),
TargetDevice: targetDevice,
TargetImage: targetImage,
RootMountMode: utils.RootRW(),
OemTimout: utils.GetOemTimeout(),
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.")
err = state.RegisterLiveMedia(g)
} else if utils.IsUKI() {
utils.Log.Info().Msg("UKI booting!")
err = state.RegisterUKI(g)
} else {
utils.Log.Info().Msg("Booting on active/passive/recovery.")
err = state.RegisterNormalBoot(g)
}
if err != nil {
return err
}
utils.Log.Info().Msg(state.WriteDAG(g))
// Once we print the dag we can exit already
if c.Bool("dry-run") {
return nil
}
err = g.Run(context.Background())
utils.Log.Info().Msg(state.WriteDAG(g))
return err
}
app.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "dry-run",
},
}
app.Commands = []*cli.Command{
{
Name: "version",
Usage: "version",
Action: func(c *cli.Context) error {
v := version.Get()
utils.Log.Info().Str("commit", v.GitCommit).Str("compiled with", v.GoVersion).Str("version", v.Version).Msg("Immucore")
return nil
},
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}