2016-08-10 20:24:30 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
2018-01-22 18:32:33 -05:00
|
|
|
"context"
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *StepPreMountCommands) Run(ctx 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
|
|
|
|
}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx := config.ctx
|
|
|
|
ictx.Data = &preMountCommandsData{Device: device}
|
2016-08-10 20:24:30 -04:00
|
|
|
|
|
|
|
ui.Say("Running device setup commands...")
|
2019-03-29 11:50:02 -04:00
|
|
|
if err := RunLocalCommands(s.Commands, wrappedCommand, ictx, ui); err != nil {
|
2016-08-10 20:24:30 -04:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepPreMountCommands) Cleanup(state multistep.StateBag) {}
|