Allow to finalizer to specify entrypoint command

In this way, finalizer in strict environment can override the default
shell used to run commands.

The shell keyword is a list, as it needs to contain the full command +
args.
This commit is contained in:
Ettore Di Giacinto
2020-04-14 17:46:34 +02:00
parent 333b9cc023
commit ee0fe1a86a
7 changed files with 109 additions and 6 deletions

View File

@@ -26,23 +26,37 @@ import (
)
type LuetFinalizer struct {
Shell []string `json:"shell"`
Install []string `json:"install"`
Uninstall []string `json:"uninstall"` // TODO: Where to store?
}
func (f *LuetFinalizer) RunInstall(s *System) error {
for _, c := range f.Install {
if s.Target == "/" {
var cmd string
var args []string
if len(f.Shell) == 0 {
// Default to sh otherwise
cmd = "sh"
args = []string{"-c"}
} else {
cmd = f.Shell[0]
if len(f.Shell) > 1 {
args = f.Shell[1:]
}
}
Info("finalizer on / :", "sh", "-c", c)
cmd := exec.Command("sh", "-c", c)
for _, c := range f.Install {
toRun := append(args, c)
Info("Executing finalizer on ", s.Target, cmd, toRun)
if s.Target == "/" {
cmd := exec.Command(cmd, toRun...)
stdoutStderr, err := cmd.CombinedOutput()
if err != nil {
return errors.Wrap(err, "Failed running command: "+string(stdoutStderr))
}
Info(string(stdoutStderr))
} else {
b := box.NewBox("sh", []string{"-c", c}, s.Target, false, true, true)
b := box.NewBox(cmd, toRun, s.Target, false, true, true)
err := b.Run()
if err != nil {
return errors.Wrap(err, "Failed running command ")