2013-06-24 02:09:52 -04:00
|
|
|
package virtualbox
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
2013-06-24 02:14:19 -04:00
|
|
|
type guestAdditionsPathTemplate struct {
|
|
|
|
Version string
|
|
|
|
}
|
|
|
|
|
|
|
|
// This step uploads the guest additions ISO to the VM.
|
2013-06-24 02:09:52 -04:00
|
|
|
type stepUploadGuestAdditions struct{}
|
|
|
|
|
|
|
|
func (s *stepUploadGuestAdditions) Run(state map[string]interface{}) multistep.StepAction {
|
|
|
|
comm := state["communicator"].(packer.Communicator)
|
|
|
|
config := state["config"].(*config)
|
2013-06-24 02:14:19 -04:00
|
|
|
driver := state["driver"].(Driver)
|
2013-06-24 02:09:52 -04:00
|
|
|
guestAdditionsPath := state["guest_additions_path"].(string)
|
|
|
|
ui := state["ui"].(packer.Ui)
|
|
|
|
|
2013-06-24 02:14:19 -04:00
|
|
|
version, err := driver.Version()
|
|
|
|
if err != nil {
|
|
|
|
state["error"] = fmt.Errorf("Error reading version for guest additions upload: %s", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-06-24 02:09:52 -04:00
|
|
|
f, err := os.Open(guestAdditionsPath)
|
|
|
|
if err != nil {
|
|
|
|
state["error"] = fmt.Errorf("Error opening guest additions ISO: %s", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2013-06-24 02:14:19 -04:00
|
|
|
tplData := &guestAdditionsPathTemplate{
|
|
|
|
Version: version,
|
|
|
|
}
|
|
|
|
|
2013-08-08 19:00:47 -04:00
|
|
|
config.GuestAdditionsPath, err = config.tpl.Process(config.GuestAdditionsPath, tplData)
|
|
|
|
if err != nil {
|
|
|
|
err := fmt.Errorf("Error preparing guest additions path: %s", err)
|
|
|
|
state["error"] = err
|
|
|
|
ui.Error(err.Error())
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
2013-06-24 02:14:19 -04:00
|
|
|
|
2013-06-24 02:44:03 -04:00
|
|
|
ui.Say("Uploading VirtualBox guest additions ISO...")
|
2013-08-08 19:00:47 -04:00
|
|
|
if err := comm.Upload(config.GuestAdditionsPath, f); err != nil {
|
2013-06-24 02:09:52 -04:00
|
|
|
state["error"] = fmt.Errorf("Error uploading guest additions: %s", err)
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepUploadGuestAdditions) Cleanup(state map[string]interface{}) {}
|