#!/bin/bash
set -e
set -x
export LC_ALL=C

# http://iki.fi/lindi/qemu-network.txt
iface=""
function cleanup() {
    sudo tunctl -d $iface
    exit 0
}
trap cleanup 1 2 3 15
img="$1"
if [ "$img" = "" ]; then
    img="img"
fi
userid="`whoami`"
iface="`sudo tunctl -b -u $userid`"
args="-hda $img -boot c"
args+=" -net nic,vlan=9,macaddr=52:54:00:12:35:09"
args+=" -net tap,vlan=9,ifname=$iface,script=/etc/qemu-ifup"
args+=" -m 256 -vnc :49 -monitor stdio"
args+=" -S"
qemu $args "$@"
cleanup
