-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
99 lines (85 loc) · 2.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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/dag"
"github.com/kairos-io/immucore/pkg/state"
"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 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
}
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.")
err = dag.RegisterLiveMedia(st, g)
} else if utils.IsUKI() {
utils.Log.Info().Msg("UKI booting!")
err = dag.RegisterUKI(st, g)
} else {
utils.Log.Info().Msg("Booting on active/passive/recovery.")
err = dag.RegisterNormalBoot(st, g)
}
if err != nil {
return err
}
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())
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",
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
},
},
}
err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}