#!/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/win7-X17-59186-english-64bit-professional.iso
ISO=/home/vm/iso/'Windows XP PROFESSIONAL SP3 Jan 2015 + SATA Drivers [TechTools.net].iso'
[ "x$1" == "x" ] || ISO="$1"

ipfwd=",guestfwd=tcp:10.0.2.34:23-tcp:127.0.0.1:2323"
ipfwd=""

#exec /usr/bin/qemu-system-x86_64 \
exec /usr/bin/qemu-system-x86_64-gtk \
	-name w7vm \
	-machine pc-i440fx-2.4,accel=kvm,usb=off \
	-enable-kvm \
	-cpu host \
	-smp 1 \
	-m 1024 \
	-hda hdd/sda \
	-cdrom "$ISO" \
	-usbdevice tablet \
	-soundhw ac97 \
	-rtc base=utc \
	-realtime mlock=off \
	-msg timestamp=on \
	-netdev user,id=n0"$ipfwd" \
	-device rtl8139,netdev=n0
	
	# device doesn't appear
	#-net nic,model=rtl8139 \
	#-net bridge,br=qemu

	# doesnt work at all
	#-netdev bridge,br=qemu,id=n0 \
	#-device rtl8139,netdev=n0

	# works but host is not visible
	#-netdev user,id=n0 \
	#-device rtl8139,netdev=n0 \

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

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

	#-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

