mirror of https://github.com/hashicorp/packer
commit
03994f052d
@ -0,0 +1,81 @@
|
||||
package virtualbox
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mitchellh/multistep"
|
||||
"github.com/mitchellh/packer/packer"
|
||||
"log"
|
||||
)
|
||||
|
||||
// This step attaches the VirtualBox guest additions as a inserted CD onto
|
||||
// the virtual machine.
|
||||
//
|
||||
// Uses:
|
||||
// config *config
|
||||
// driver Driver
|
||||
// guest_additions_path string
|
||||
// ui packer.Ui
|
||||
// vmName string
|
||||
//
|
||||
// Produces:
|
||||
type stepAttachGuestAdditions struct {
|
||||
attachedPath string
|
||||
}
|
||||
|
||||
func (s *stepAttachGuestAdditions) Run(state multistep.StateBag) multistep.StepAction {
|
||||
config := state.Get("config").(*config)
|
||||
driver := state.Get("driver").(Driver)
|
||||
guestAdditionsPath := state.Get("guest_additions_path").(string)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
// If we're not attaching the guest additions then just return
|
||||
if !config.GuestAdditionsAttach {
|
||||
log.Println("Not attaching guest additions since we're uploading.")
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
// Attach the guest additions to the computer
|
||||
log.Println("Attaching guest additions ISO onto IDE controller...")
|
||||
command := []string{
|
||||
"storageattach", vmName,
|
||||
"--storagectl", "IDE Controller",
|
||||
"--port", "1",
|
||||
"--device", "0",
|
||||
"--type", "dvddrive",
|
||||
"--medium", guestAdditionsPath,
|
||||
}
|
||||
if err := driver.VBoxManage(command...); err != nil {
|
||||
err := fmt.Errorf("Error attaching guest additions: %s", err)
|
||||
state.Put("error", err)
|
||||
ui.Error(err.Error())
|
||||
return multistep.ActionHalt
|
||||
}
|
||||
|
||||
// Track the path so that we can unregister it from VirtualBox later
|
||||
s.attachedPath = guestAdditionsPath
|
||||
|
||||
return multistep.ActionContinue
|
||||
}
|
||||
|
||||
func (s *stepAttachGuestAdditions) Cleanup(state multistep.StateBag) {
|
||||
if s.attachedPath == "" {
|
||||
return
|
||||
}
|
||||
|
||||
driver := state.Get("driver").(Driver)
|
||||
ui := state.Get("ui").(packer.Ui)
|
||||
vmName := state.Get("vmName").(string)
|
||||
|
||||
command := []string{
|
||||
"storageattach", vmName,
|
||||
"--storagectl", "IDE Controller",
|
||||
"--port", "1",
|
||||
"--device", "0",
|
||||
"--medium", "none",
|
||||
}
|
||||
|
||||
if err := driver.VBoxManage(command...); err != nil {
|
||||
ui.Error(fmt.Sprintf("Error unregistering guest additions: %s", err))
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"net"
|
||||
"net/rpc"
|
||||
)
|
||||
|
||||
// rpcDial makes a TCP connection to a remote RPC server and returns
|
||||
// the client. This will set the connection up properly so that keep-alives
|
||||
// are set and so on and should be used to make all RPC connections within
|
||||
// this package.
|
||||
func rpcDial(address string) (*rpc.Client, error) {
|
||||
tcpConn, err := tcpDial(address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Create an RPC client around our connection
|
||||
return rpc.NewClient(tcpConn), nil
|
||||
}
|
||||
|
||||
// tcpDial connects via TCP to the designated address.
|
||||
func tcpDial(address string) (*net.TCPConn, error) {
|
||||
conn, err := net.Dial("tcp", address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Set a keep-alive so that the connection stays alive even when idle
|
||||
tcpConn := conn.(*net.TCPConn)
|
||||
tcpConn.SetKeepAlive(true)
|
||||
return tcpConn, nil
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
|
||||
// UnixReader is a Reader implementation that automatically converts
|
||||
// Windows line endings to Unix line endings.
|
||||
type UnixReader struct {
|
||||
Reader io.Reader
|
||||
|
||||
buf []byte
|
||||
once sync.Once
|
||||
scanner *bufio.Scanner
|
||||
}
|
||||
|
||||
func (r *UnixReader) Read(p []byte) (n int, err error) {
|
||||
// Create the buffered reader once
|
||||
r.once.Do(func() {
|
||||
r.scanner = bufio.NewScanner(r.Reader)
|
||||
r.scanner.Split(scanUnixLine)
|
||||
})
|
||||
|
||||
// If we have no data in our buffer, scan to the next token
|
||||
if len(r.buf) == 0 {
|
||||
if !r.scanner.Scan() {
|
||||
err = r.scanner.Err()
|
||||
if err == nil {
|
||||
err = io.EOF
|
||||
}
|
||||
|
||||
return 0, err
|
||||
}
|
||||
|
||||
r.buf = r.scanner.Bytes()
|
||||
}
|
||||
|
||||
// Write out as much data as we can to the buffer, storing the rest
|
||||
// for the next read.
|
||||
n = len(p)
|
||||
if n > len(r.buf) {
|
||||
n = len(r.buf)
|
||||
}
|
||||
copy(p, r.buf)
|
||||
r.buf = r.buf[n:]
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// scanUnixLine is a bufio.Scanner SplitFunc. It tokenizes on lines, but
|
||||
// only returns unix-style lines. So even if the line is "one\r\n", the
|
||||
// token returned will be "one\n".
|
||||
func scanUnixLine(data []byte, atEOF bool) (advance int, token []byte, err error) {
|
||||
if atEOF && len(data) == 0 {
|
||||
return 0, nil, nil
|
||||
}
|
||||
|
||||
if i := bytes.IndexByte(data, '\n'); i >= 0 {
|
||||
// We have a new-line terminated line. Return the line with the newline
|
||||
return i + 1, dropCR(data[0 : i+1]), nil
|
||||
}
|
||||
|
||||
if atEOF {
|
||||
// We have a final, non-terminated line
|
||||
return len(data), dropCR(data), nil
|
||||
}
|
||||
|
||||
if data[len(data)-1] != '\r' {
|
||||
// We have a normal line, just let it tokenize
|
||||
return len(data), data, nil
|
||||
}
|
||||
|
||||
// We need more data
|
||||
return 0, nil, nil
|
||||
}
|
||||
|
||||
func dropCR(data []byte) []byte {
|
||||
if len(data) > 0 && data[len(data)-2] == '\r' {
|
||||
// Trim off the last byte and replace it with a '\n'
|
||||
data = data[0 : len(data)-1]
|
||||
data[len(data)-1] = '\n'
|
||||
}
|
||||
|
||||
return data
|
||||
}
|
||||
@ -0,0 +1,33 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUnixReader_impl(t *testing.T) {
|
||||
var raw interface{}
|
||||
raw = new(UnixReader)
|
||||
if _, ok := raw.(io.Reader); !ok {
|
||||
t.Fatal("should be reader")
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnixReader(t *testing.T) {
|
||||
input := "one\r\ntwo\nthree\r\n"
|
||||
expected := "one\ntwo\nthree\n"
|
||||
|
||||
r := &UnixReader{
|
||||
Reader: bytes.NewReader([]byte(input)),
|
||||
}
|
||||
|
||||
result := new(bytes.Buffer)
|
||||
if _, err := io.Copy(result, r); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
if result.String() != expected {
|
||||
t.Fatalf("bad: %#v", result.String())
|
||||
}
|
||||
}
|
||||
@ -1,134 +1,109 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
POpen4 (0.1.4)
|
||||
Platform (>= 0.4.0)
|
||||
open4
|
||||
Platform (0.4.0)
|
||||
activesupport (3.2.9)
|
||||
i18n (~> 0.6)
|
||||
activesupport (3.2.14)
|
||||
i18n (~> 0.6, >= 0.6.4)
|
||||
multi_json (~> 1.0)
|
||||
chunky_png (1.2.6)
|
||||
chunky_png (1.2.8)
|
||||
coffee-script (2.2.0)
|
||||
coffee-script-source
|
||||
execjs
|
||||
coffee-script-source (1.3.3)
|
||||
coffee-script-source (1.6.3)
|
||||
compass (0.12.2)
|
||||
chunky_png (~> 1.2)
|
||||
fssm (>= 0.2.7)
|
||||
sass (~> 3.1)
|
||||
daemons (1.1.9)
|
||||
eventmachine (1.0.0)
|
||||
eventmachine (1.0.3)
|
||||
execjs (1.4.0)
|
||||
multi_json (~> 1.0)
|
||||
ffi (1.2.0)
|
||||
fssm (0.2.9)
|
||||
haml (3.1.7)
|
||||
highline (1.6.15)
|
||||
hike (1.2.1)
|
||||
htmlcompressor (0.0.3)
|
||||
yui-compressor (~> 0.9.6)
|
||||
http_router (0.10.2)
|
||||
rack (>= 1.0.0)
|
||||
url_mount (~> 0.2.1)
|
||||
i18n (0.6.1)
|
||||
libv8 (3.3.10.4)
|
||||
listen (0.5.3)
|
||||
maruku (0.6.1)
|
||||
syntax (>= 1.0.0)
|
||||
middleman (3.0.6)
|
||||
middleman-core (= 3.0.6)
|
||||
middleman-more (= 3.0.6)
|
||||
middleman-sprockets (~> 3.0.2)
|
||||
middleman-core (3.0.6)
|
||||
activesupport (~> 3.2.6)
|
||||
bundler (~> 1.1)
|
||||
listen (~> 0.5.2)
|
||||
rack (~> 1.4.1)
|
||||
rack-test (~> 0.6.1)
|
||||
rb-fsevent (~> 0.9.1)
|
||||
rb-inotify (~> 0.8.8)
|
||||
thor (~> 0.15.4)
|
||||
tilt (~> 1.3.1)
|
||||
middleman-minify-html (3.0.0)
|
||||
htmlcompressor
|
||||
middleman-core (~> 3.0.0)
|
||||
middleman-more (3.0.6)
|
||||
ffi (1.9.0)
|
||||
fssm (0.2.10)
|
||||
haml (4.0.3)
|
||||
tilt
|
||||
highline (1.6.19)
|
||||
hike (1.2.3)
|
||||
i18n (0.6.5)
|
||||
kramdown (1.1.0)
|
||||
libv8 (3.16.14.3)
|
||||
listen (1.2.3)
|
||||
rb-fsevent (>= 0.9.3)
|
||||
rb-inotify (>= 0.9)
|
||||
rb-kqueue (>= 0.2)
|
||||
middleman (3.1.5)
|
||||
coffee-script (~> 2.2.0)
|
||||
coffee-script-source (~> 1.3.3)
|
||||
compass (>= 0.12.2)
|
||||
execjs (~> 1.4.0)
|
||||
haml (>= 3.1.6)
|
||||
i18n (~> 0.6.0)
|
||||
maruku (~> 0.6.0)
|
||||
middleman-core (= 3.0.6)
|
||||
padrino-helpers (= 0.10.7)
|
||||
kramdown (~> 1.1.0)
|
||||
middleman-core (= 3.1.5)
|
||||
middleman-more (= 3.1.5)
|
||||
middleman-sprockets (>= 3.1.2)
|
||||
sass (>= 3.1.20)
|
||||
uglifier (~> 1.2.6)
|
||||
middleman-sprockets (3.0.4)
|
||||
middleman-more (~> 3.0.1)
|
||||
sprockets (~> 2.1, < 2.5)
|
||||
sprockets-sass (~> 0.8.0)
|
||||
multi_json (1.4.0)
|
||||
open4 (1.3.0)
|
||||
padrino-core (0.10.7)
|
||||
activesupport (~> 3.2.0)
|
||||
http_router (~> 0.10.2)
|
||||
sinatra (~> 1.3.1)
|
||||
thor (~> 0.15.2)
|
||||
tilt (~> 1.3.0)
|
||||
padrino-helpers (0.10.7)
|
||||
i18n (~> 0.6)
|
||||
padrino-core (= 0.10.7)
|
||||
rack (1.4.1)
|
||||
uglifier (~> 2.1.0)
|
||||
middleman-core (3.1.5)
|
||||
activesupport (~> 3.2.6)
|
||||
bundler (~> 1.1)
|
||||
i18n (~> 0.6.1)
|
||||
listen (~> 1.2.2)
|
||||
rack (>= 1.4.5)
|
||||
rack-test (~> 0.6.1)
|
||||
thor (>= 0.15.2, < 2.0)
|
||||
tilt (~> 1.3.6)
|
||||
middleman-minify-html (3.1.1)
|
||||
middleman-core (~> 3.0)
|
||||
middleman-more (3.1.5)
|
||||
middleman-sprockets (3.1.4)
|
||||
middleman-core (>= 3.0.14)
|
||||
middleman-more (>= 3.0.14)
|
||||
sprockets (~> 2.1)
|
||||
sprockets-helpers (~> 1.0.0)
|
||||
sprockets-sass (~> 1.0.0)
|
||||
multi_json (1.8.0)
|
||||
rack (1.5.2)
|
||||
rack-contrib (1.1.0)
|
||||
rack (>= 0.9.1)
|
||||
rack-protection (1.2.0)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
rb-fsevent (0.9.2)
|
||||
rb-inotify (0.8.8)
|
||||
rb-fsevent (0.9.3)
|
||||
rb-inotify (0.9.2)
|
||||
ffi (>= 0.5.0)
|
||||
redcarpet (2.2.2)
|
||||
sass (3.2.3)
|
||||
sinatra (1.3.3)
|
||||
rack (~> 1.3, >= 1.3.6)
|
||||
rack-protection (~> 1.2)
|
||||
tilt (~> 1.3, >= 1.3.3)
|
||||
sprockets (2.4.5)
|
||||
rb-kqueue (0.2.0)
|
||||
ffi (>= 0.5.0)
|
||||
redcarpet (3.0.0)
|
||||
ref (1.0.5)
|
||||
sass (3.2.10)
|
||||
sprockets (2.10.0)
|
||||
hike (~> 1.2)
|
||||
multi_json (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
tilt (~> 1.1, != 1.3.0)
|
||||
sprockets-sass (0.8.0)
|
||||
sprockets-helpers (1.0.1)
|
||||
sprockets (~> 2.0)
|
||||
sprockets-sass (1.0.1)
|
||||
sprockets (~> 2.0)
|
||||
tilt (~> 1.1)
|
||||
syntax (1.0.0)
|
||||
therubyracer (0.10.2)
|
||||
libv8 (~> 3.3.10)
|
||||
thin (1.5.0)
|
||||
therubyracer (0.12.0)
|
||||
libv8 (~> 3.16.14.0)
|
||||
ref
|
||||
thin (1.5.1)
|
||||
daemons (>= 1.0.9)
|
||||
eventmachine (>= 0.12.6)
|
||||
rack (>= 1.0.0)
|
||||
thor (0.15.4)
|
||||
tilt (1.3.3)
|
||||
uglifier (1.2.7)
|
||||
thor (0.18.1)
|
||||
tilt (1.3.7)
|
||||
uglifier (2.1.2)
|
||||
execjs (>= 0.3.0)
|
||||
multi_json (~> 1.3)
|
||||
url_mount (0.2.1)
|
||||
rack
|
||||
yui-compressor (0.9.6)
|
||||
POpen4 (>= 0.1.4)
|
||||
multi_json (~> 1.0, >= 1.0.2)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
highline (~> 1.6.15)
|
||||
middleman (~> 3.0.6)
|
||||
middleman-minify-html (~> 3.0.0)
|
||||
middleman (~> 3.1.5)
|
||||
middleman-minify-html (~> 3.1.1)
|
||||
rack-contrib (~> 1.1.0)
|
||||
redcarpet (~> 2.2.2)
|
||||
therubyracer (~> 0.10.2)
|
||||
redcarpet (~> 3.0.0)
|
||||
therubyracer (~> 0.12.0)
|
||||
thin (~> 1.5.0)
|
||||
|
||||
Loading…
Reference in new issue