mirror of https://github.com/ericonr/sbctl.git
sbctl/enroll-keys: Refactor immutable checking
Signed-off-by: Morten Linderud <morten@linderud.pw>
This commit is contained in:
parent
28eee4464d
commit
13bbb90c03
|
@ -9,24 +9,31 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
func CheckImmutable() error {
|
||||
var isImmutable bool
|
||||
for _, file := range sbctl.EfivarFSFiles {
|
||||
err := sbctl.IsImmutable(file)
|
||||
if errors.Is(err, sbctl.ErrImmutable) {
|
||||
isImmutable = true
|
||||
logging.Warn("File is immutable: %s", file)
|
||||
} else if errors.Is(err, sbctl.ErrNotImmutable) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("couldn't read file: %s", file)
|
||||
}
|
||||
}
|
||||
if isImmutable {
|
||||
return sbctl.ErrImmutable
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var enrollKeysCmd = &cobra.Command{
|
||||
Use: "enroll-keys",
|
||||
Short: "Enroll the current keys to EFI",
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
var isImmutable bool
|
||||
for _, file := range sbctl.EfivarFSFiles {
|
||||
err := sbctl.IsImmutable(file)
|
||||
if errors.Is(err, sbctl.ErrImmutable) {
|
||||
isImmutable = true
|
||||
logging.Warn("File is immutable: %s", file)
|
||||
} else if errors.Is(err, sbctl.ErrNotImmutable) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("couldn't read file: %s", file)
|
||||
}
|
||||
}
|
||||
if isImmutable {
|
||||
return sbctl.ErrImmutable
|
||||
if err := CheckImmutable(); err != nil {
|
||||
return err
|
||||
}
|
||||
logging.Print("Syncing keys to EFI variables...")
|
||||
synced := sbctl.SBKeySync(sbctl.KeysPath)
|
||||
|
|
Loading…
Reference in New Issue