mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-06-26 16:21:40 +00:00
https://go.dev/doc/modules/major-version This way we can bump the kairos dependency on the provider-kairos repo which otherwise produced the error: ``` ~/workspace/kairos/provider-kairos (main)*$ go get -u github.com/kairos-io/kairos@v2.0.0-alpha3 go: github.com/kairos-io/kairos@v2.0.0-alpha3: invalid version: module contains a go.mod file, so module path must match major version ("github.com/kairos-io/kairos/v2") ``` Signed-off-by: Dimitris Karakasilis <dimitris@karakasilis.me> Co-authored-by: Itxaka <itxaka.garcia@spectrocloud.com>
67 lines
1.4 KiB
Go
67 lines
1.4 KiB
Go
package hook
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/kairos-io/kairos-sdk/machine"
|
|
"github.com/kairos-io/kairos-sdk/utils"
|
|
config "github.com/kairos-io/kairos/v2/pkg/config"
|
|
|
|
kcryptconfig "github.com/kairos-io/kcrypt/pkg/config"
|
|
)
|
|
|
|
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
|
|
}()
|
|
|
|
kcryptc, err := kcryptconfig.GetConfiguration(kcryptconfig.ConfigScanDirs)
|
|
if err != nil {
|
|
fmt.Println("Failed getting kcrypt configuration: ", err.Error())
|
|
if c.FailOnBundleErrors {
|
|
return err
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
err = kcryptc.SetMapping(strings.TrimSpace(out))
|
|
if err != nil {
|
|
fmt.Println("Failed updating the kcrypt configuration file: ", err.Error())
|
|
if c.FailOnBundleErrors {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
|
|
err = kcryptc.WriteMappings(kcryptconfig.MappingsFile)
|
|
if err != nil {
|
|
fmt.Println("Failed writing kcrypt partition mappings: ", err.Error())
|
|
if c.FailOnBundleErrors {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|