summaryrefslogtreecommitdiff
path: root/x86_64-generic/create-vm
blob: 84137e4bdb615ffe5cb4e57403f706145069e5ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/sh
set -e

DEVEL_IMAGE_NAME="water-bomb-devel-x86_64"

# Usage: baserock-install-vm $VM_NAME $INSTALL_DIRECTORY
VM_NAME="$1"
INSTALL_DIRECTORY="$2"

VM_VBOX_NAME=$(echo "$VM_NAME" | sed 's|\s|\.|g')

if [ -z "$VM_NAME" ]; then
	echo "A name must be specified for this virtual machine"
	echo "Usage: $0 VM_NAME INSTALL_DIRECTORY"
	exit 1
fi

if [ -z "$INSTALL_DIRECTORY" ]; then
	echo "An install directory must be specified for this virtual machine"
	echo "Usage: $0 VM_NAME INSTALL_DIRECTORY"
	exit 1
fi

# Check that we don't already have a VM of this name
if [ -e "$VM_NAME.vdi" ]; then
	echo "A VM by this name already exists"
	exit 1
fi

# Ensure curl or wget is installed

if ! which wget >/dev/null; then
	if which curl >/dev/null; then
		# Fall back to curl if no wget
		USE_CURL=true
	else
		# If neither, try to install curl
		if which yum >/dev/null; then
			echo "Attempting to install curl using yum"
			sudo yum install curl
			USE_CURL=true
		elif which apt-get >/dev/null; then
			echo "Attempting to install curl using apt-get"
			sudo apt-get install curl
			USE_CURL=true
		else
			echo "I do not know how to install curl on this system. Please install curl or wget manually"
			exit 1
		fi
	fi
fi

# Ensuring VirtualBox is installed
if which VBoxManage >/dev/null; then
	echo "VirtualBox is installed"
else
	echo "VirtualBox is not installed"
	if which yum >/dev/null; then
		echo "Attempting to install VirtualBox using yum"
		sudo yum install VirtualBox
	elif which apt-get >/dev/null; then
		echo "Attempting to install VirtualBox using apt-get"
		sudo apt-get install virtualbox-ose
	else
		echo "I do not know how to install VirtualBox on this system. Please install manually"
		exit 1
	fi
fi

mkdir -p "$INSTALL_DIRECTORY"

cd "$INSTALL_DIRECTORY"

# Download and extract the water-bomb .img file
if [ -z "$USE_CURL" ]; then
	wget --no-clobber "http://download.baserock.org/baserock/$DEVEL_IMAGE_NAME.img.gz"
else
	if ! [ -e "$DEVEL_IMAGE_NAME.img.gz" ]; then
		curl -O "http://download.baserock.org/baserock/$DEVEL_IMAGE_NAME.img.gz"
	fi
fi

if [ -e $DEVEL_IMAGE_NAME.img ]; then
	echo "Development image has already been decompressed"
else
	echo "Decompressing development image"
	gzip -dc "$DEVEL_IMAGE_NAME.img.gz" >"$DEVEL_IMAGE_NAME.img"
fi

# Convert the .img file into a VirtualBox .vdi and create the virtual machine
VBoxManage convertdd "$DEVEL_IMAGE_NAME.img" "$VM_NAME.vdi"
VBoxManage createvm --name "$VM_VBOX_NAME" --ostype Linux26_64 --register


# Configure the virtual machine
VBoxManage modifyvm "$VM_VBOX_NAME" --ioapic on --memory 1024 --nic1 nat


# Configure the virtual machine's first hard disk
VBoxManage storagectl "$VM_VBOX_NAME" --name "SATA Controller" --add sata --bootable on --sataportcount 2

VBoxManage storageattach "$VM_VBOX_NAME" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$VM_NAME.vdi"


# Configure the /src partition
VBoxManage createhd --filename "$VM_NAME-src.vdi" --size $((30*1024))

VBoxManage storageattach "$VM_VBOX_NAME" --storagectl "SATA Controller" --port 1 --device 0 --type hdd --medium "$VM_NAME-src.vdi"

cd - >/dev/null