2016-08-10 20:24:30 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
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-08-10 20:24:30 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type preMountCommandsData struct {
|
|
|
|
Device string
|
|
|
|
}
|
|
|
|
|
|
|
|
// StepPreMountCommands sets up the a new block device when building from scratch
|
|
|
|
type StepPreMountCommands struct {
|
|
|
|
Commands []string
|
|
|
|
}
|
|
|
|
|
2018-01-22 18:31:41 -05:00
|
|
|
func (s *StepPreMountCommands) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
2016-08-10 20:24:30 -04:00
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
device := state.Get("device").(string)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
wrappedCommand := state.Get("wrappedCommand").(CommandWrapper)
|
|
|
|
|
|
|
|
if len(s.Commands) == 0 {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := config.ctx
|
|
|
|
ctx.Data = &preMountCommandsData{Device: device}
|
|
|
|
|
|
|
|
ui.Say("Running device setup commands...")
|
|
|
|
if err := RunLocalCommands(s.Commands, wrappedCommand, ctx, ui); err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepPreMountCommands) Cleanup(state multistep.StateBag) {}
|