-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathbuild-vagrant
More file actions
executable file
·75 lines (64 loc) · 2.51 KB
/
build-vagrant
File metadata and controls
executable file
·75 lines (64 loc) · 2.51 KB
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
#!/bin/sh
set -e
. "$(dirname $0)/config.sh"
for ARCH in $ARCHS
do
VBOX="${LABEL}-ubuntu-$VERSION-$DISTRO-$ARCH"
# Reset to snapshot at time of initial build
VBoxManage snapshot "${VBOX}" restore "AUTO_${LABEL}_base_build__000001"
# Start the virtual machine. Spin slowly until SSH is usable.
VBoxManage startvm "$VBOX" --type gui
#VBoxHeadless --startvm "$VBOX" --vrdp config
until eval "$SSH exit"
do
sleep 1
done
# Install Ruby, RubyGems, and Chef as Vagrant requires.
eval "$SSH \"
set -e
export DEBCONF_FRONTEND=noninteractive
sudo -E apt-get -y install build-essential ruby ruby-dev rubygems
sudo gem install --no-rdoc --no-ri chef
echo 'PATH=\"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/var/lib/gems/1.8/bin\"' | sudo tee /etc/environment >/dev/null
\""
# Remove generated udev rule for network device as the mac address on the next instantiation is not going to match
eval "$SSH \"
sudo rm /etc/udev/rules.d/70-persistent-net.rules
\""
# Shutdown the virtual machine.
eval "$SSH \"sudo shutdown -h now\""
until VBoxManage showvminfo "$VBOX" | grep "^State: *powered off"
do
sleep 1
done
## Check if vagrant box dir for vagrant drives is hosted on an ext4 fs. If so, ensure hostiocache is enabled to avoid corruption
[ ${HOSTIOCACHE} ] || {
vbox_hd_dir="$HOME/.vagrant/boxes"
HOSTIOCACHE="";
for dir in ${vbox_hd_dir}; do
vbox_hd_dir_disk=$(df ${dir} | tail -n 1 | cut -d" " -f1);
vbox_hd_dir_fs="$(grep ${vbox_hd_dir_disk} /proc/mounts | awk '{ print $3 }')"
[ "$vbox_hd_dir_fs" = "ext4" ] && {
echo "Auto enabling HOSTIOCACHE due ext4 fs [${dir}]";
HOSTIOCACHE=" --hostiocache on ";
VBoxManage storagectl "$VBOX" \
--name SATA ${HOSTIOCACHE} \
break;
}
done
}
# Remove the Proxy configuration before packaging a box. Not all vagrant users will be running an apt proxy server on their machines.
[ ${BOX_DISABLE_APT_PROXY} -eq 1 ] && {
eval "$SSH \"
sudo sed -i '/^Acquire::http::Proxy/ d' /etc/apt/apt.conf
\""
}
# Now build the Vagrant box file.
vagrant package --base "$VBOX"
mv "package.box" \
"${LABEL}$([ "$ARCH" = "i386" ] && echo 32 || echo 64).box"
# Snapshot after vagrant dep install....
VBoxManage snapshot "${VBOX}" take "AUTO_${LABEL}_vagrant_base__000002" --description "Snapshot taken after installing vagrant dependencies"
done
# Creating Vagrant boxes ruins the normal VM setup so get rid of them.
#eval "$(dirname $0)/clean-vbox"