Description: set hwaddr in debian template
Author: Serge Hallyn <serge.hallyn@ubuntu.com>
Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1080681
Forwarded: no

Index: lxc-0.9.0/templates/lxc-debian.in
===================================================================
--- lxc-0.9.0.orig/templates/lxc-debian.in	2013-02-18 01:47:43.000000000 -0600
+++ lxc-0.9.0/templates/lxc-debian.in	2013-06-11 07:55:35.287708781 -0500
@@ -202,6 +202,13 @@
     rootfs=$2
     hostname=$3
 
+    # if there is exactly one veth network entry, make sure it has an
+    # associated hwaddr.
+    nics=`grep -e '^lxc\.network\.type[ \t]*=[ \t]*veth' $path/config | wc -l`
+    if [ $nics -eq 1 ]; then
+        grep -q "^lxc.network.hwaddr" $path/config || sed -i -e "/^lxc\.network\.type[ \t]*=[ \t]*veth/a lxc.network.hwaddr = 00:16:3e:$(openssl rand -hex 3| sed 's/\(..\)/\1:/g; s/.$//')" $path/config
+    fi
+
     grep -q "^lxc.rootfs" $path/config 2>/dev/null || echo "lxc.rootfs = $rootfs" >> $path/config
     cat <<EOF >> $path/config
 lxc.tty = 4
