2022-10-07 11:36:32 +00:00
|
|
|
package hook
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2023-05-09 19:57:16 +00:00
|
|
|
"github.com/kairos-io/kairos-sdk/machine"
|
2022-10-07 11:36:32 +00:00
|
|
|
"time"
|
|
|
|
|
2023-03-18 09:27:18 +00:00
|
|
|
"github.com/kairos-io/kairos-sdk/utils"
|
2023-07-10 12:39:48 +00:00
|
|
|
"github.com/kairos-io/kairos-agent/v2/pkg/config"
|
2022-10-07 11:36:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Kcrypt struct{}
|
|
|
|
|
|
|
|
func (k Kcrypt) Run(c config.Config) error {
|
2022-10-18 05:45:07 +00:00
|
|
|
|
|
|
|
if len(c.Install.Encrypt) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-05-09 19:57:16 +00:00
|
|
|
// Config passed during install ends up here, so we need to read it
|
|
|
|
_ = machine.Mount("COS_OEM", "/oem")
|
|
|
|
defer func() {
|
|
|
|
_ = machine.Umount("/oem") //nolint:errcheck
|
|
|
|
}()
|
|
|
|
|
2022-10-07 11:36:32 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|