#!/bin/bash
# Copyright ©2007-2008 Hugo Mills <hugo@carfax.org.uk>
# Licensed under GPLv2. See the file COPYING for full details.

CONFDIR=/etc/vamos

if [ -f ${CONFDIR}/vamos.conf ]; then
    . ${CONFDIR}/vamos.conf
fi

if [ -z "${ACCELERATION}" ]; then ACCELERATION=none; fi
case ${ACCELERATION} in
    kqemu)
	modprobe kqemu
	;;
    kvm)
	CPUMAKER=$(grep ^vendor_id /proc/cpuinfo | head -1 | cut -d: -f2)
	case ${CPUMAKER} in
	    GenuineIntel)
		modprobe kvm-intel
		;;
	    AuthenticAMD)
		modprobe kvm-amd
		;;
	    *)
		echo CPU manufacturer unknown: Not loading kvm modules
	esac
	;;
    *)
	;;
esac

# Actually, this can probably be devolved to distro config
for brconf in $(ls ${CONFDIR}/bridges/* | egrep -v "[^[:alnum:]_-]") ; do
    ID=
    INTERFACES=

    if [ -f ${brconf} ]; then
	. ${brconf}

        # Setup the bridge
	brctl addbr vm-br${ID}
        # Add host ethernet adapter to the bridge
	for IF in ${INTERFACES}; do
	    brctl addif vm-br${ID} ${IF}
            # Remove IP address from host ethernet device
	    ifconfig ${IF} 0.0.0.0 up
	done
        # Grab an IP address from DHCP for the bridge
	dhclient vm-br${ID}
    fi
done
