blob: 31b370e82ad9b4334e96d85420639b0cad90de23 [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
Anthony Younge2c3a372011-09-12 23:25:37 -070058apt-get update
59apt-get -y --force-yes install git-core vim-nox sudo
Anthony Young72d69632011-09-12 21:09:55 -070060git clone git://github.com/cloudbuilders/nfs-stack.git /root/nfs-stack
61EOF
62
63chmod 700 $INSTALL_SH
64
65# Make installer run on boot
66RC_LOCAL=$ROOTFS/etc/rc.local
67cat > $RC_LOCAL <<EOF
68#!/bin/sh -e
69/root/install.sh
70EOF
71
Anthony Young5f6c93b2011-09-13 00:04:57 -070072# Setup cache
Anthony Younge2c3a372011-09-12 23:25:37 -070073# FIXME - use proper fstab mount
74CWD=`pwd`
Anthony Young5f6c93b2011-09-13 00:04:57 -070075CACHEDIR=$CWD/cache/
76mkdir -p $CACHEDIR/apt
77mkdir -p $CACHEDIR/pip
78cp -pr $CACHEDIR/apt/* $ROOTFS/var/cache/apt/
79cp -pr $CACHEDIR/pip/* $ROOTFS/var/cache/pip/
Anthony Younge2c3a372011-09-12 23:25:37 -070080
Anthony Young72d69632011-09-12 21:09:55 -070081# Configure cgroup directory
82mkdir -p /cgroup
83mount none -t cgroup /cgroup
84
85# Start our container
86lxc-start -d -n $CONTAINER