#!/bin/bash -x

# Print env for debugging purposes
/usr/bin/env

cd /Volumes/MYPOCKET7
rm -rf ./*.log

/bin/cp "vm-images/pagefile_vol_vmware.vmdk" "$USBCOMPCFG"
/bin/cp "vm-images/pagefile_vol_vmware-s001.vmdk" "$USBCOMPCFG"
/bin/cp "vm-images/pagefile_vol_vmware-s002.vmdk" "$USBCOMPCFG"
/bin/cp "vm-images/pagefile_vol_vmware-s003.vmdk" "$USBCOMPCFG"

"$VMM_PATH/VBoxManage" setextradata global GUI/UpdateDate never
"$VMM_PATH/VBoxManage" createvm -name MyPocket7 --basefolder "$USBCOMPCFG" -register 
"$VMM_PATH/VBoxManage" storagectl MyPocket7 --name "IDE Controller" --add ide
"$VMM_PATH/VBoxManage" storageattach MyPocket7 --storagectl "IDE Controller" --port 0 --device 0 --type hdd --mtype immutable --medium "$(pwd)/vm-images/usbcomp_7.vmdk" 
"$VMM_PATH/VBoxManage" storageattach MyPocket7 --storagectl "IDE Controller" --port 0 --device 1 --type hdd --mtype immutable --medium "$(pwd)/vm-images/usbcomp_user.vmdk" 
"$VMM_PATH/VBoxManage" storageattach MyPocket7 --storagectl "IDE Controller" --port 1 --device 0 --type hdd --medium "$USBCOMPCFG/pagefile_vol_vmware.vmdk" 

if [ -n "$VBOX_CDROM_DVD" ]; then
	"$VMM_PATH/VBoxManage" storageattach MyPocket7 --storagectl "IDE Controller" --port 1 --device 1 --type dvddrive --medium host:"$VBOX_CDROM_DVD" --passthrough on
else
	"$VMM_PATH/VBoxManage" storageattach MyPocket7 --storagectl "IDE Controller" --port 1 --device 1 --type dvddrive --medium emptydrive
fi

if [ -n "$NIC_BRIDGED" ];then
	"$VMM_PATH/VBoxManage" modifyvm MyPocket7 $NIC_OPTIONS "$NIC_BRIDGED"
else
	"$VMM_PATH/VBoxManage" modifyvm MyPocket7 $NIC_OPTIONS
fi

"$VMM_PATH/VBoxManage" modifyvm MyPocket7 --nestedpaging off --vram 64 --pae off --ioapic on --bioslogoimagepath "config/splash_vbx.bmp" --bioslogodisplaytime 8000 --hwvirtex off --memory $VBOX_MEMORY --ostype Windows7 --audio coreaudio --audiocontroller ac97 --boot1 disk
"$VMM_PATH/VBoxManage" startvm MyPocket7
#"$VMM_PATH/VirtualBox" --startvm MyPocket7
