mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-09-24 19:57:24 +00:00
Add support for common and recovery folders in sysext (#757)
This commit is contained in:
77
main.go
77
main.go
@@ -831,11 +831,20 @@ The validate command expects a configuration file as its only argument. Local fi
|
||||
Name: "passive",
|
||||
Usage: "List the system extensions for the passive boot entry",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "recovery",
|
||||
Usage: "List the system extensions for the recovery boot entry",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "common",
|
||||
Usage: "List the system extensions for the common boot entry (applies to all boot states)",
|
||||
},
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
if c.Bool("active") && c.Bool("passive") {
|
||||
return fmt.Errorf("only one of --active or --passive can be set")
|
||||
if moreThanOneEnabled(c.Bool("active"), c.Bool("passive"), c.Bool("recovery"), c.Bool("common")) {
|
||||
return fmt.Errorf("only one of --active, --passive, --recovery or --common can be set")
|
||||
}
|
||||
|
||||
if err := checkRoot(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -882,21 +891,32 @@ The validate command expects a configuration file as its only argument. Local fi
|
||||
Name: "passive",
|
||||
Usage: "Enable the system extension for the passive boot entry",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "recovery",
|
||||
Usage: "List the system extensions for the recovery boot entry",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "common",
|
||||
Usage: "List the system extensions for the common boot entry (applies to all boot states)",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "now",
|
||||
Usage: "Enable the system extension now and reload systemd-sysext",
|
||||
},
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
if c.Bool("active") && c.Bool("passive") {
|
||||
return fmt.Errorf("only one of --active or --passive can be set")
|
||||
}
|
||||
if c.Args().Len() != 1 {
|
||||
return fmt.Errorf("extension name required")
|
||||
}
|
||||
if c.Bool("active") == false && c.Bool("passive") == false {
|
||||
return fmt.Errorf("either --active or --passive must be set")
|
||||
|
||||
if moreThanOneEnabled(c.Bool("active"), c.Bool("passive"), c.Bool("recovery"), c.Bool("common")) {
|
||||
return fmt.Errorf("only one of --active, --passive, --recovery or --common can be set")
|
||||
}
|
||||
|
||||
if noneOfEnabled(c.Bool("active"), c.Bool("passive"), c.Bool("recovery"), c.Bool("common")) {
|
||||
return fmt.Errorf("either --active, --passive, --recovery or --common must be set")
|
||||
}
|
||||
|
||||
if err := checkRoot(); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -936,20 +956,30 @@ The validate command expects a configuration file as its only argument. Local fi
|
||||
Name: "passive",
|
||||
Usage: "Disable the system extension for the passive boot entry",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "recovery",
|
||||
Usage: "List the system extensions for the recovery boot entry",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "common",
|
||||
Usage: "List the system extensions for the common boot entry (applies to all boot states)",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Name: "now",
|
||||
Usage: "Disable the system extension now and reload systemd-sysext",
|
||||
},
|
||||
},
|
||||
Before: func(c *cli.Context) error {
|
||||
if c.Bool("active") && c.Bool("passive") {
|
||||
return fmt.Errorf("only one of --active or --passive can be set")
|
||||
}
|
||||
if c.Args().Len() != 1 {
|
||||
return fmt.Errorf("extension name required")
|
||||
}
|
||||
if c.Bool("active") == false && c.Bool("passive") == false {
|
||||
return fmt.Errorf("either --active or --passive must be set")
|
||||
|
||||
if moreThanOneEnabled(c.Bool("active"), c.Bool("passive"), c.Bool("recovery"), c.Bool("common")) {
|
||||
return fmt.Errorf("only one of --active, --passive, --recovery or --common can be set")
|
||||
}
|
||||
|
||||
if noneOfEnabled(c.Bool("active"), c.Bool("passive"), c.Bool("recovery"), c.Bool("common")) {
|
||||
return fmt.Errorf("either --active, --passive, --recovery or --common must be set")
|
||||
}
|
||||
if err := checkRoot(); err != nil {
|
||||
return err
|
||||
@@ -1171,3 +1201,26 @@ func getReleasesFromProvider(includePrereleases bool) ([]string, error) {
|
||||
|
||||
return tags, nil
|
||||
}
|
||||
|
||||
func moreThanOneEnabled(bools ...bool) bool {
|
||||
count := 0
|
||||
for _, b := range bools {
|
||||
if b {
|
||||
count++
|
||||
}
|
||||
if count > 1 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func noneOfEnabled(bools ...bool) bool {
|
||||
count := 0
|
||||
for _, b := range bools {
|
||||
if b {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count == 0
|
||||
}
|
||||
|
Reference in New Issue
Block a user