2016-09-01 15:30:48 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
|
|
|
|
2019-10-23 23:57:17 -04:00
|
|
|
"github.com/hashicorp/packer/common"
|
2018-01-19 19:18:44 -05:00
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2016-09-01 15:30:48 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type postMountCommandsData struct {
|
|
|
|
Device string
|
|
|
|
MountPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
// StepPostMountCommands allows running arbitrary commands after mounting the
|
|
|
|
// device, but prior to the bind mount and copy steps.
|
|
|
|
type StepPostMountCommands struct {
|
|
|
|
Commands []string
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepPostMountCommands) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2019-05-31 14:39:43 -04:00
|
|
|
config := state.Get("config").(interpolateContextProvider)
|
2016-09-01 15:30:48 -04:00
|
|
|
device := state.Get("device").(string)
|
|
|
|
mountPath := state.Get("mount_path").(string)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2019-10-23 23:57:17 -04:00
|
|
|
wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper)
|
2016-09-01 15:30:48 -04:00
|
|
|
|
|
|
|
if len(s.Commands) == 0 {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2019-05-31 14:39:43 -04:00
|
|
|
ictx := config.GetContext()
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx.Data = &postMountCommandsData{
|
2016-09-01 15:30:48 -04:00
|
|
|
Device: device,
|
|
|
|
MountPath: mountPath,
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say("Running post-mount commands...")
|
2019-03-29 11:50:02 -04:00
|
|
|
if err := RunLocalCommands(s.Commands, wrappedCommand, ictx, ui); err != nil {
|
2016-09-01 15:30:48 -04:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepPostMountCommands) Cleanup(state multistep.StateBag) {}
|