2016-08-10 20:24:30 -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-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 {
|
2019-05-28 20:40:44 -04:00
|
|
|
config := state.Get("config").(interpolateContextProvider)
|
2016-08-10 20:24:30 -04:00
|
|
|
device := state.Get("device").(string)
|
|
|
|
ui := state.Get("ui").(packer.Ui)
|
2019-10-23 23:57:17 -04:00
|
|
|
wrappedCommand := state.Get("wrappedCommand").(common.CommandWrapper)
|
2016-08-10 20:24:30 -04:00
|
|
|
|
|
|
|
if len(s.Commands) == 0 {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
2019-05-28 20:40:44 -04:00
|
|
|
ictx := config.GetContext()
|
2019-03-29 11:50:02 -04:00
|
|
|
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) {}
|