kairos-agent/internal/agent/hooks/kcrypt.go
Ettore Di Giacinto 5893294c54 sparkles: state api sdk (#262)
*  Add state api

This is related to https://github.com/kairos-io/kairos/issues/34.

Starts to unify the API to retrieve the state in the sdk to have a common place to query system status information.

* 🤖 Add test

* Update go.mod

* ⚙️ Fine-tune detection of partitions

* 🤖 Add more fine-grained tests

* 🎨 Add /dev/ to partition name

* 🤖 Fixup tests

* ⚙️ Remount accessors

*  Add state partition to cloud-init paths

* 📝 Upper case Kairos in motd

* 🎨 Add mounts sdk

* 🎨 Set grub options via SDK

* 🎨 Make it more idiomatic
2022-10-23 20:22:32 +02:00

57 lines
1.1 KiB
Go

package hook
import (
"fmt"
"os"
"time"
config "github.com/kairos-io/kairos/pkg/config"
"github.com/kairos-io/kairos/pkg/machine"
"github.com/kairos-io/kairos/pkg/utils"
cp "github.com/otiai10/copy"
)
type Kcrypt struct{}
func (k Kcrypt) Run(c config.Config) error {
if len(c.Install.Encrypt) == 0 {
return nil
}
machine.Mount("COS_OEM", "/oem") //nolint:errcheck
defer func() {
machine.Umount("/oem") //nolint:errcheck
}()
_ = os.MkdirAll("/oem/system/discovery", 0650)
for _, p := range c.Install.Encrypt {
out, err := utils.SH(fmt.Sprintf("kcrypt encrypt %s", p))
if err != nil {
fmt.Printf("could not encrypt partition: %s\n", out+err.Error())
if c.FailOnBundleErrors {
return err
}
// Give time to show the error
time.Sleep(10 * time.Second)
return nil // do not error out
}
}
if c.Install.SkipEncryptCopyPlugins {
fmt.Println("Skip discovery plugin copy")
return nil
}
err := cp.Copy("/system/discovery", "/oem/system/discovery")
if err != nil {
fmt.Println("Failed during copying discovery plugins: ", err.Error())
if c.FailOnBundleErrors {
return err
}
}
return nil
}