|
|
|
|
@ -4,7 +4,6 @@ import (
|
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
|
"log"
|
|
|
|
|
"os/exec"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// StepChrootProvision provisions the instance within a chroot.
|
|
|
|
|
@ -19,29 +18,15 @@ type WrappedCommandTemplate struct {
|
|
|
|
|
func (s *StepChrootProvision) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
hook := state.Get("hook").(packer.Hook)
|
|
|
|
|
mountPath := state.Get("mount_path").(string)
|
|
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
chrootCmd := func(command string) *exec.Cmd {
|
|
|
|
|
return ChrootCommand(mountPath, command)
|
|
|
|
|
}
|
|
|
|
|
wrappedCommand := func(command string) *exec.Cmd {
|
|
|
|
|
wrapped, err := config.tpl.Process(config.CommandWrapper, &WrappedCommandTemplate{
|
|
|
|
|
Command: command,
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
ui.Error(err.Error())
|
|
|
|
|
}
|
|
|
|
|
return ShellCommand(wrapped)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state.Put("chrootCmd", chrootCmd)
|
|
|
|
|
state.Put("wrappedCommand", wrappedCommand)
|
|
|
|
|
wrappedCommand := state.Get("wrappedCommand").(Command)
|
|
|
|
|
chrootCmd := state.Get("chrootCmd").(Command)
|
|
|
|
|
|
|
|
|
|
// Create our communicator
|
|
|
|
|
comm := &Communicator{
|
|
|
|
|
Chroot: mountPath,
|
|
|
|
|
ChrootCmd: chrootCmd,
|
|
|
|
|
wrappedCommand: wrappedCommand,
|
|
|
|
|
WrappedCommand: wrappedCommand,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Provision
|
|
|
|
|
|