Created
June 22, 2010 12:06
-
-
Save jmar71n/448386 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Possibly use dedicated user... | |
#useradd vmadmin | |
#passwd vmadmin | |
echo "Virtualbox VMguest setup script" | |
echo | |
echo -n "unique VM guestname: " | |
read VMNAME | |
echo -n "VMGuest OS type (press h for a list of ostypes): " | |
read OSTYPE | |
if [ $OSTYPE = h ]; then | |
VBoxManage list ostypes | grep ID: | |
echo -n "VMGuest OS type (press h for a list of ostypes): " | |
read OSTYPE | |
fi | |
echo -n "VM HDD size (in MB): " | |
read HDSIZE | |
echo -n "CD/DVD image location: " | |
read "IMAGE" | |
echo "VM network interface" | |
echo "1) Bridged" | |
echo "2) NAT (Not done yet)" | |
echo -n "Enter selection: " | |
read SELECTION | |
if [ $SELECTION = "1" ]; then | |
VMNet="bridged --bridgeadapter1" | |
ifconfig -a | |
echo | |
echo "To which interface? " | |
read INTERFACE | |
else | |
VMNet="nat....." | |
echo "using NAT interface" | |
fi | |
echo -n "RDP Port No. " | |
read RDPPORT | |
trap exit ERR | |
trap "echo Ctl+C Detected... Exiting!; exit;" SIGINT SIGTERM | |
OK () | |
( | |
if [ $? -eq 0 ]; then | |
echo -n " "; echo -e '\E[47;32m'"\033[1mDONE\033[0m" | |
else | |
echo -n " "; echo -n '\E[47;31m'"\033[1mFail\033[0m" | |
fi | |
) | |
# install VM... | |
echo -n "Creating VM" | |
VBoxManage createvm --name "$VMNAME" --ostype $OSTYPE --register > /dev/null; OK | |
echo -n "Creating HDD .vdi" | |
VBoxManage createhd --filename "$VMNAME.vdi" --size $HDSIZE --register > /dev/null; OK | |
#VBoxManage modifyvm "$VMNAME" --hda "$VMNAME.vdi" | |
#VBoxManage openmedium dvd <filelocation_and_file_name> # Not sure if needed | |
echo -n "Adding IDE Controller" | |
VBoxManage storagectl "$VMNAME" --name "IDE Controller" --add ide > /dev/null; OK | |
echo -n "Adding HDD .vdi to VM" | |
VBoxManage storageattach "$VMNAME" --storagectl "IDE Controller" --port 0 --device 0 --type hdd --medium "$VMNAME.vdi" > /dev/null; OK | |
echo -n "Adding CD/DVD iso to VM" | |
VBoxManage storageattach "$VMNAME" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium "$IMAGE" > /dev/null; OK | |
echo -n "Setting RDP prefrences" | |
VBoxManage modifyvm "$VMNAME" --vrdp on --vrdpport $RDPPORT --vrdpauthtype null --vrdpmulticon on > /dev/null; OK | |
echo -n "Setting network prefrences" | |
VBoxManage modifyvm "$VMNAME" --nic1 $VMNet $INTERFACE > /dev/null; OK | |
# Start the vm | |
echo | |
echo "VirtualBox VM $VMNAME setup" | |
echo | |
echo -n "Start VM $VMNAME Now? (y/n): " | |
read YN | |
if [[ $YN = [y,Y] ]]; then | |
echo "Starting "$VMNAME", Use RDP port $RDPPORT" | |
echo "After installation is finish the iso should automatically be remove from the VM" | |
VBoxHeadless --startvm "$VMNAME" | |
# Remove iso ofter installation | |
VBoxManage storageattach "$VMNAME" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium none | |
else | |
echo | |
echo "Start VM using command" | |
echo "\"VBoxHeadless --startvm "$VMNAME"\"" | |
echo | |
echo "Remove iso from VM after installation finnishes using command" | |
echo "\"VBoxManage storageattach "$VMNAME" --storagectl "IDE Controller" --port 1 --device 0 --type dvddrive --medium none\"" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment