80 lines
2.3 KiB
Go
80 lines
2.3 KiB
Go
package iocage
|
|
|
|
import (
|
|
"fmt"
|
|
"context"
|
|
|
|
"github.com/hashicorp/packer/helper/multistep"
|
|
"github.com/hashicorp/packer/packer"
|
|
)
|
|
|
|
type StepSetupJail struct {
|
|
|
|
}
|
|
|
|
func (s *StepSetupJail) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
|
|
ui := state.Get("ui").(packer.Ui)
|
|
comm := state.Get("communicator").(packer.Communicator)
|
|
config := state.Get("config").(Config)
|
|
|
|
ui.Say("Setting up iocage...")
|
|
|
|
cmdInstall := &packer.RemoteCmd {
|
|
Command: "sudo env ASSUME_ALWAYS_YES=YES pkg install py36-iocage",
|
|
}
|
|
if err := cmdInstall.RunWithUi(ctx, comm, ui); err != nil || cmdInstall.ExitStatus() != 0 {
|
|
if err == nil {
|
|
err = fmt.Errorf("Bad exit status: %d", cmdInstall.ExitStatus())
|
|
}
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
cmdFstab := &packer.RemoteCmd {
|
|
Command: "echo 'fdescfs /dev/fd fdescfs rw 0 0' | sudo tee -a /etc/fstab && sudo mount -t fdescfs null /dev/fd",
|
|
}
|
|
if err := cmdFstab.RunWithUi(ctx, comm, ui); err != nil || cmdFstab.ExitStatus() != 0 {
|
|
if err == nil {
|
|
err = fmt.Errorf("Bad exit status: %d", cmdFstab.ExitStatus())
|
|
}
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
cmdFetch := &packer.RemoteCmd {
|
|
Command: "sudo zfs set mountpoint=\"/iocage\" tank/iocage && echo 3 | sudo iocage fetch",
|
|
}
|
|
if err := cmdFetch.RunWithUi(ctx, comm, ui); err != nil || cmdFetch.ExitStatus() != 0 {
|
|
if err == nil {
|
|
err = fmt.Errorf("Bad exit status: %d", cmdFetch.ExitStatus())
|
|
}
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
ui.Say("Setting up jail...")
|
|
|
|
cmdJailCreate := &packer.RemoteCmd {
|
|
Command: fmt.Sprintf("sudo iocage create -r 12.1-RELEASE -n %s", config.JailName),
|
|
}
|
|
if err := cmdJailCreate.RunWithUi(ctx, comm, ui); err != nil || cmdJailCreate.ExitStatus() != 0 {
|
|
if err == nil {
|
|
err = fmt.Errorf("Bad exit status: %d", cmdJailCreate.ExitStatus())
|
|
}
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
cmdJailStart := &packer.RemoteCmd {
|
|
Command: fmt.Sprintf("sudo iocage start %s", config.JailName),
|
|
}
|
|
if err := cmdJailStart.RunWithUi(ctx, comm, ui); err != nil || cmdJailStart.ExitStatus() != 0 {
|
|
if err == nil {
|
|
err = fmt.Errorf("Bad exit status: %d", cmdJailStart.ExitStatus())
|
|
}
|
|
return multistep.ActionHalt
|
|
}
|
|
|
|
ui.Say("Done, continue to provisioning.")
|
|
|
|
return multistep.ActionContinue
|
|
}
|
|
|
|
func (s *StepSetupJail) Cleanup(state multistep.StateBag) {
|
|
} |