a variety of tweaks for lxc stackiness
diff --git a/build_lxc.sh b/build_lxc.sh
index 1a2cea3..d247818 100755
--- a/build_lxc.sh
+++ b/build_lxc.sh
@@ -12,9 +12,19 @@
 
 # Destroy any existing container
 lxc-stop -n $CONTAINER
-sleep 1
+sleep 2
 lxc-destroy -n $CONTAINER
-sleep 1
+sleep 2
+
+CACHEDIR=/var/cache/lxc/natty/rootfs-amd64
+if [ "$WARMCACHE" = "1" ]; then
+    if [ -d $CACHEDIR ]; then
+        # Pre-cache files
+        chroot $CACHEDIR apt-get update
+        chroot $CACHEDIR apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
+        chroot $CACHEDIR pip install `cat pips/*`
+    fi
+fi
 
 # Create network configuration
 NET_CONF=/tmp/net.conf
@@ -27,14 +37,7 @@
 
 # Configure the network
 lxc-create -n $CONTAINER -t natty -f $NET_CONF
-
-if [ "$WARMCACHE" = "1" ]; then
-    # Pre-cache files
-    BASECACHE=/var/cache/lxc/natty/rootfs-amd64
-    chroot $BASECACHE apt-get update
-    chroot $BASECACHE apt-get install -y `cat apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
-    chroot $BASECACHE pip install `cat pips/*`
-fi
+sleep 2
 
 # Where our container lives
 ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
@@ -67,9 +70,27 @@
 #!/bin/bash
 echo "nameserver $NAMESERVER" | resolvconf -a eth0
 sleep 1
+# Create a stack user that is a member of the libvirtd group so that stack 
+# is able to interact with libvirt.
+groupadd libvirtd
+useradd stack -s /bin/bash -d /opt -G libvirtd
+
+# a simple password - pass
+echo stack:pass | chpasswd
+
+# give stack ownership over /opt so it may do the work needed
+chown -R stack /opt
+
+# and has sudo ability (in the future this should be limited to only what 
+# stack requires)
+
+echo "stack ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
+
+# Install and run stack.sh
 apt-get update
 apt-get -y --force-yes install git-core vim-nox sudo
-git clone git://github.com/cloudbuilders/nfs-stack.git /root/nfs-stack
+su -c "git clone git://github.com/cloudbuilders/nfs-stack.git /opt/nfs-stack" stack
+su -c "cd /opt/nfs-stack && ./stack.sh" stack
 EOF
 
 chmod 700 $INSTALL_SH
@@ -81,20 +102,9 @@
 /root/install.sh
 EOF
 
-# Setup cache
-# FIXME - use proper fstab mount
-CWD=`pwd`
-CACHEDIR=$CWD/cache/
-mkdir -p $CACHEDIR/apt
-mkdir -p $CACHEDIR/pip
-cp -pr $CACHEDIR/apt/* $ROOTFS/var/cache/apt/
-cp -pr $CACHEDIR/pip/* $ROOTFS/var/cache/pip/
-
 # Configure cgroup directory
-if [ ! -d /cgroup ] ; then
-    mkdir -p /cgroup
-    mount none -t cgroup /cgroup
-fi
+mkdir -p /cgroup
+mount none -t cgroup /cgroup
 
 # Start our container
 lxc-start -d -n $CONTAINER