mirror of
https://github.com/kairos-io/kairos-agent.git
synced 2025-05-10 01:14:31 +00:00
sparkles: Minor enhancements (#239)
* 🐛 Fixup grub option quoting * ⚙️ Copy discovery to oem if found * ✨ Add environment block to install * ⚙️ Use /oem for mount in kcrypt post-hook * 📝 Update docs with installer env reference * 🤖 Add test deps * ⚙️ Be consistent and set env also for post-hooks * ⚙️ propagate env in post-hooks
This commit is contained in:
parent
78bcb65cb6
commit
5c4e29f3d3
internal/agent
@ -17,7 +17,7 @@ func (b GrubOptions) Run(c config.Config) error {
|
||||
machine.Umount("/tmp/oem")
|
||||
}()
|
||||
for k, v := range c.Install.GrubOptions {
|
||||
out, err := utils.SH(fmt.Sprintf("grub2-editenv /tmp/oem/grubenv set %s=%s", k, v))
|
||||
out, err := utils.SH(fmt.Sprintf(`grub2-editenv /tmp/oem/grubenv set "%s=%s"`, k, v))
|
||||
if err != nil {
|
||||
fmt.Printf("could not set boot option: %s\n", out+err.Error())
|
||||
return nil // do not error out
|
||||
|
@ -2,15 +2,30 @@ 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")
|
||||
}()
|
||||
|
||||
_ = 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 {
|
||||
@ -24,5 +39,18 @@ func (k Kcrypt) Run(c config.Config) error {
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@ -226,6 +227,15 @@ func RunInstall(options map[string]string) error {
|
||||
c.Install.Reboot = true
|
||||
}
|
||||
|
||||
for _, e := range c.Install.Env {
|
||||
pair := strings.SplitN(e, "=", 2)
|
||||
if len(pair) >= 2 {
|
||||
os.Setenv(pair[0], pair[1])
|
||||
}
|
||||
}
|
||||
|
||||
envs := os.Environ()
|
||||
|
||||
err := ioutil.WriteFile(f.Name(), []byte(cloudInit), os.ModePerm)
|
||||
if err != nil {
|
||||
fmt.Printf("could not write cloud init: %s\n", err.Error())
|
||||
@ -236,7 +246,7 @@ func RunInstall(options map[string]string) error {
|
||||
args = append(args, "-c", f.Name(), device)
|
||||
|
||||
cmd := exec.Command("elemental", args...)
|
||||
cmd.Env = os.Environ()
|
||||
cmd.Env = envs
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stderr = os.Stderr
|
||||
|
Loading…
Reference in New Issue
Block a user