#!/bin/bash
[ "$(id -un)" == "vm" ] ||
{
	echo wrong user
	#exit 1
}
ISO=/home/ed/iso/debian-8.2.0-i386-netinst.iso
ISO=/home/ed/iso/alpine-3.2.3-x86.iso
ISO=/home/vm/iso/VS2010Express1.iso
ISO=/home/vm/iso/win7-X17-59186-english-64bit-professional.iso
[ "x$1" == "x" ] || ISO="$1"



#exec /usr/bin/qemu-system-x86_64 \
exec /usr/bin/qemu-system-x86_64-gtk \
	-name w7vm \
	-machine type=q35,accel=kvm \
	-enable-kvm \
	-cpu host \
	-smp 2 \
	-m 4096 \
	-hda hdd-spice/sda \
	-cdrom "$ISO" \
	-usbdevice tablet \
	-soundhw hda \
	-rtc base=utc \
	-realtime mlock=off \
	-runas vm \
	-vga qxl \
	-device virtio-serial-pci \
	-device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
	-chardev spicevmc,id=spicechannel0,name=vdagent \
	-device ich9-usb-ehci1,id=usb \
	-chardev spicevmc,name=usbredir,id=usbredirchardev1 \
	-device usb-redir,chardev=usbredirchardev1,id=usbredirdev1 \
	-spice unix,addr=/tmp/vm_spice.socket,disable-ticketing \
	-msg timestamp=on \
	-net nic \
	-net bridge,br=qemu

	# forward without spice
	# dmesg: New USB device found, idVendor=05ac, idProduct=12aa
	# lsusb: Bus 001 Device 007: ID 05ac:12aa
	#-machine pc-i440fx-2.4,accel=kvm,usb=off \
	#-machine type=q35,accel=kvm \
	# -usb \
	# -device usb-host,$(lsusb | grep 05ac:12aa | sed -r 's/^Bus 0*/hostbus=/;s/ Device 0*/,hostaddr=/;s/:.*//') \

	# linux guest
	#-net nic,model=virtio \
	#-net bridge,br=qemu
	
	# running as root

	#-vnc 127.0.0.1:0

	# ed
	#-net nic \
	#-net bridge,br=qemu \

	# aaron
	#-net nic,model=virtio \
	#-net tap,script=no,ifname=keet \

	# attempt at sharedfolder
	#-fsdev local,security_model=passthrough,id=fsdev0,path=/home/vm/share \
	#-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare \

	# libvirt nat
	#-netdev tap,fd=21,id=hostnet0 \
	#-device virtio-net-pci,netdev=hostnet0,id=net0,mac=52:54:00:88:62:b6,bus=pci.0,addr=0x3 \

exit 0



ifconfig
cat <<fds
# for gui, ed@nitor:
ssh ao -L 5900:127.0.0.1:5900

# GUEST /etc/network/interfaces
auto eth0
iface eth0 inet static
	address 10.217.143.93
	netmask 255.255.255.0
	gateway 10.217.143.92
	hostname keet

# GUEST route fix (shouldn't be needed)
ip route del *
ip route add default via 10.217.143.92

# Alpine stuff
ROOTFS=btrfs BOOTFS=ext2 SWAP_SIZE=0 setup-alpine
fds

# self-composed version
qemu-system-i386 \
	-cpu host \
	-smp 2\
	-m 4096\
	-name keetbox\
	-cdrom /home/ed/debian-8.2.0-i386-netinst.iso\
	-hda hdd\
	-fsdev local,security_model=passthrough,id=fsdev0,path=/home/vm/share\
	-device virtio-9p-pci,id=fs0,fsdev=fsdev0,mount_tag=hostshare\
	-enable-kvm\
	-usbdevice tablet\
	-vnc 0.0.0.0:0 \
	-netdev tap,helper=/usr/lib/qemu/qemu-bridge-helper,id=hn0 \
	-device virtio-net-pci,netdev=hn0,id=nic1
	#-netdev bridge,id=hn0 -device virtio-net-pci,netdev=hn0,id=nic1

