2019-05-09 12:50:44 -04:00
|
|
|
package chroot
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
2019-05-09 12:50:44 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type preMountCommandsData struct {
|
|
|
|
Device string
|
|
|
|
}
|
|
|
|
|
|
|
|
// StepPreMountCommands sets up the a new block device when building from scratch
|
|
|
|
type StepPreMountCommands struct {
|
|
|
|
Commands []string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepPreMountCommands) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
|
|
|
config := state.Get("config").(*Config)
|
|
|
|
device := state.Get("device").(string)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2019-05-09 12:50:44 -04:00
|
|
|
wrappedCommand := state.Get("wrappedCommand").(CommandWrapper)
|
|
|
|
|
|
|
|
if len(s.Commands) == 0 {
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
ictx := config.ctx
|
|
|
|
ictx.Data = &preMountCommandsData{Device: device}
|
|
|
|
|
|
|
|
ui.Say("Running device setup commands...")
|
|
|
|
if err := RunLocalCommands(s.Commands, wrappedCommand, ictx, ui); err != nil {
|
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StepPreMountCommands) Cleanup(state multistep.StateBag) {}
|