blob: 4f1686cf31d0550822caf9cd85199ea5ee056b5c [file] [log] [blame]
Anthony Young72d69632011-09-12 21:09:55 -07001#!/bin/bash
2# Configurable params
3BRIDGE=${BRIDGE:-br0}
4CONTAINER=${CONTAINER:-TESTER}
5CONTAINER_IP=${CONTAINER_IP:-192.168.1.50}
6CONTAINER_CIDR=${CONTAINER_CIDR:-$CONTAINER_IP/24}
7CONTAINER_NETMASK=${CONTAINER_NETMASK:-255.255.255.0}
8CONTAINER_GATEWAY=${CONTAINER_GATEWAY:-192.168.1.1}
9NAMESERVER=${NAMESERVER:-192.168.1.1}
10COPYENV=${COPYENV:-1}
11
12# Destroy any existing container
13lxc-stop -n $CONTAINER
14lxc-destroy -n $CONTAINER
15
16# Create network configuration
17NET_CONF=/tmp/net.conf
18cat > $NET_CONF <<EOF
19lxc.network.type = veth
20lxc.network.link = $BRIDGE
21lxc.network.flags = up
22lxc.network.ipv4 = $CONTAINER_CIDR
23EOF
24
25# Configure the network
26lxc-create -n $CONTAINER -t natty -f $NET_CONF
27
28# Where our container lives
29ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
30
31# Copy over your ssh keys if desired
32if [ $COPYENV ]; then
33 cp -pr ~/.ssh $ROOTFS/root/.ssh
34 cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig
35 cp -pr ~/.vimrc $ROOTFS/root/.vimrc
36 cp -pr ~/.bashrc $ROOTFS/root/.bashrc
37fi
38
39# Configure instance network
40INTERFACES=$ROOTFS/etc/network/interfaces
41cat > $INTERFACES <<EOF
42auto lo
43iface lo inet loopback
44
45auto eth0
46iface eth0 inet static
47 address $CONTAINER_IP
48 netmask $CONTAINER_NETMASK
49 gateway $CONTAINER_GATEWAY
50EOF
51
52# Configure the first run installer
53INSTALL_SH=$ROOTFS/root/install.sh
54cat > $INSTALL_SH <<EOF
55#!/bin/bash
56echo "nameserver $NAMESERVER" | resolvconf -a eth0
57sleep 1
58apt-get -y --force-yes install git-core vim-nox
59git clone git://github.com/cloudbuilders/nfs-stack.git /root/nfs-stack
60EOF
61
62chmod 700 $INSTALL_SH
63
64# Make installer run on boot
65RC_LOCAL=$ROOTFS/etc/rc.local
66cat > $RC_LOCAL <<EOF
67#!/bin/sh -e
68/root/install.sh
69EOF
70
71# Configure cgroup directory
72mkdir -p /cgroup
73mount none -t cgroup /cgroup
74
75# Start our container
76lxc-start -d -n $CONTAINER