github.com/mmcquillan/packer@v1.1.1-0.20171009221028-c85cf0483a5d/builder/amazon/chroot/step_pre_mount_commands.go (about) 1 package chroot 2 3 import ( 4 "github.com/hashicorp/packer/packer" 5 "github.com/mitchellh/multistep" 6 ) 7 8 type preMountCommandsData struct { 9 Device string 10 } 11 12 // StepPreMountCommands sets up the a new block device when building from scratch 13 type StepPreMountCommands struct { 14 Commands []string 15 } 16 17 func (s *StepPreMountCommands) Run(state multistep.StateBag) multistep.StepAction { 18 config := state.Get("config").(*Config) 19 device := state.Get("device").(string) 20 ui := state.Get("ui").(packer.Ui) 21 wrappedCommand := state.Get("wrappedCommand").(CommandWrapper) 22 23 if len(s.Commands) == 0 { 24 return multistep.ActionContinue 25 } 26 27 ctx := config.ctx 28 ctx.Data = &preMountCommandsData{Device: device} 29 30 ui.Say("Running device setup commands...") 31 if err := RunLocalCommands(s.Commands, wrappedCommand, ctx, ui); err != nil { 32 state.Put("error", err) 33 ui.Error(err.Error()) 34 return multistep.ActionHalt 35 } 36 return multistep.ActionContinue 37 } 38 39 func (s *StepPreMountCommands) Cleanup(state multistep.StateBag) {}