#!/bin/bash
modprobe tun
modprobe kvm
modprobe kvm-intel
chgrp kvm /dev/kvm
chmod 660 /dev/kvm
#ip tuntap create mode tap owner $(id vm -u) persist dev tun
chgrp kvm /dev/net/tun
chmod 660 /dev/net/tun

chmod u+s /usr/lib/qemu/qemu-bridge-helper
echo 1 | tee /proc/sys/net/ipv4/ip_forward
brctl addbr qemu
ip addr add 192.168.17.1/24 dev qemu
ip link set qemu up

iptables -I FORWARD -m physdev --physdev-is-bridged -j ACCEPT
iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i qemu -o wlan0 -j ACCEPT

su -c 'xhost +SI:localuser:vm' ed

