#!/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" false fi if [ -z "$INSTALL_DIRECTORY" ]; then echo "An install directory must be specified for this virtual machine" echo "Usage: $0 VM_NAME INSTALL_DIRECTORY" false 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" false 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" false fi fi cd "$INSTALL_DIRECTORY" # Download and extract the water-bomb .img file wget --no-clobber "http://download.baserock.org/baserock/$DEVEL_IMAGE_NAME.img.gz" 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