#!/usr/bin/env bash # Use stackrc.example if stackrc is missing if [ ! -e ./stackrc ]; then read -n1 -p "No stackrc present. Copy stackrc.example to stackrc? (y/n) " echo [[ $REPLY = [yY] ]] && cp stackrc.example stackrc|| { echo "Aborting: Missing stackrc"; exit 1; } fi # Source params source ./stackrc # Configurable params BRIDGE=${BRIDGE:-br0} CONTAINER=${CONTAINER:-STACK} CONTAINER_IP=${CONTAINER_IP:-192.168.1.50} CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24} CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0} CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1} NAMESERVER=${NAMESERVER:-$CONTAINER_GATEWAY} COPYENV=${COPYENV:-1} # Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova" STACKSH_PARAMS=${STACKSH_PARAMS:-} # Option to use the version of devstack on which we are currently working USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} # Warn users who aren't on natty if ! grep -q natty /etc/lsb-release; then echo "WARNING: this script has only been tested on natty" fi # Install deps apt-get install -y lxc debootstrap # Install cgroup-bin from source, since the packaging is buggy and possibly incompatible with our setup if ! which cgdelete | grep -q cgdelete; then apt-get install -y g++ bison flex libpam0g-dev wget http://sourceforge.net/projects/libcg/files/libcgroup/v0.37.1/libcgroup-0.37.1.tar.bz2/download -O /tmp/libcgroup-0.37.1.tar.bz2 cd /tmp && bunzip2 libcgroup-0.37.1.tar.bz2 && tar xfv libcgroup-0.37.1.tar cd libcgroup-0.37.1 ./configure make install ldconfig fi # Create lxc configuration LXC_CONF=/tmp/$CONTAINER.conf cat > $LXC_CONF <> $ROOTFS/etc/sudoers # Copy kernel modules mkdir -p $ROOTFS/lib/modules/`uname -r`/kernel cp -p /lib/modules/`uname -r`/modules.dep $ROOTFS/lib/modules/`uname -r`/ cp -pR /lib/modules/`uname -r`/kernel/net $ROOTFS/lib/modules/`uname -r`/kernel/ # Gracefully cp only if source file/dir exists function cp_it { if [ -e $1 ] || [ -d $1 ]; then cp -pr $1 $2 fi } # Copy over your ssh keys and env if desired if [ "$COPYENV" = "1" ]; then cp_it ~/.ssh $ROOTFS/opt/.ssh cp_it ~/.ssh/id_rsa.pub $ROOTFS/opt/.ssh/authorized_keys cp_it ~/.gitconfig $ROOTFS/opt/.gitconfig cp_it ~/.vimrc $ROOTFS/opt/.vimrc cp_it ~/.bashrc $ROOTFS/opt/.bashrc fi # Make our ip address hostnames look nice at the command prompt echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/opt/.bashrc echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile # Give stack ownership over /opt so it may do the work needed chroot $ROOTFS chown -R stack /opt # Configure instance network INTERFACES=$ROOTFS/etc/network/interfaces cat > $INTERFACES < $RUN_SH < /opt/run.sh.log EOF # Make the run.sh executable chmod 755 $RUN_SH # Make runner launch on boot RC_LOCAL=$ROOTFS/etc/rc.local cat > $RC_LOCAL <