2019-01-28 06:30:15 -05:00
|
|
|
package hyperone
|
|
|
|
|
|
|
|
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-01-28 06:30:15 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type preMountCommandsData struct {
|
|
|
|
Device string
|
|
|
|
MountPath string
|
|
|
|
}
|
|
|
|
|
|
|
|
type stepPreMountCommands struct{}
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
func (s *stepPreMountCommands) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
2019-01-28 06:30:15 -05:00
|
|
|
config := state.Get("config").(*Config)
|
2020-11-19 14:54:31 -05:00
|
|
|
ui := state.Get("ui").(packersdk.Ui)
|
2019-01-28 06:30:15 -05:00
|
|
|
device := state.Get("device").(string)
|
|
|
|
|
2019-03-29 11:50:02 -04:00
|
|
|
ictx := config.ctx
|
|
|
|
ictx.Data = &preMountCommandsData{
|
2019-01-28 06:30:15 -05:00
|
|
|
Device: device,
|
|
|
|
MountPath: config.ChrootMountPath,
|
|
|
|
}
|
|
|
|
|
|
|
|
ui.Say("Running pre-mount commands...")
|
2019-03-29 11:50:02 -04:00
|
|
|
if err := runCommands(config.PreMountCommands, ictx, state); err != nil {
|
2019-01-28 06:30:15 -05:00
|
|
|
state.Put("error", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepPreMountCommands) Cleanup(state multistep.StateBag) {}
|