2022-10-07 11:36:32 +00:00
|
|
|
package hook
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2022-10-18 05:45:07 +00:00
|
|
|
"os"
|
2022-10-07 11:36:32 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
config "github.com/kairos-io/kairos/pkg/config"
|
2022-10-18 05:45:07 +00:00
|
|
|
"github.com/kairos-io/kairos/pkg/machine"
|
2022-10-07 11:36:32 +00:00
|
|
|
"github.com/kairos-io/kairos/pkg/utils"
|
2022-10-18 05:45:07 +00:00
|
|
|
cp "github.com/otiai10/copy"
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
machine.Mount("COS_OEM", "/oem") //nolint:errcheck
|
|
|
|
defer func() {
|
2022-10-23 18:22:32 +00:00
|
|
|
machine.Umount("/oem") //nolint:errcheck
|
2022-10-18 05:45:07 +00:00
|
|
|
}()
|
|
|
|
|
|
|
|
_ = os.MkdirAll("/oem/system/discovery", 0650)
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-18 05:45:07 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-07 11:36:32 +00:00
|
|
|
return nil
|
|
|
|
}
|