blob: 8d5ef42288658a54e90fbadf24efe031264002d9 [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
Anthony Younge2c3a372011-09-12 23:25:37 -070016FSTAB=/tmp/fstab
17cat > $FSTAB <<EOF
18none /var/lib/lxc/$CONTAINER/dev/pts devpts defaults 0 0
19none /var/lib/lxc/$CONTAINER/proc proc defaults 0 0
20none /var/lib/lxc/$CONTAINER/sys sysfs defaults 0 0
21none /var/lib/lxc/$CONTAINER/var/lock tmpfs defaults 0 0
22none /var/lib/lxc/$CONTAINER/var/run tmpfs defaults 0 0
23/var/cache/apt/ $APTCACHEDIR none bind 0 0
24EOF
25
Anthony Young72d69632011-09-12 21:09:55 -070026# Create network configuration
27NET_CONF=/tmp/net.conf
28cat > $NET_CONF <<EOF
29lxc.network.type = veth
30lxc.network.link = $BRIDGE
31lxc.network.flags = up
32lxc.network.ipv4 = $CONTAINER_CIDR
Anthony Younge2c3a372011-09-12 23:25:37 -070033lxc.mount = $FSTAB
Anthony Young72d69632011-09-12 21:09:55 -070034EOF
35
36# Configure the network
37lxc-create -n $CONTAINER -t natty -f $NET_CONF
38
39# Where our container lives
40ROOTFS=/var/lib/lxc/$CONTAINER/rootfs/
41
42# Copy over your ssh keys if desired
43if [ $COPYENV ]; then
44 cp -pr ~/.ssh $ROOTFS/root/.ssh
45 cp -pr ~/.gitconfig $ROOTFS/root/.gitconfig
46 cp -pr ~/.vimrc $ROOTFS/root/.vimrc
47 cp -pr ~/.bashrc $ROOTFS/root/.bashrc
48fi
49
50# Configure instance network
51INTERFACES=$ROOTFS/etc/network/interfaces
52cat > $INTERFACES <<EOF
53auto lo
54iface lo inet loopback
55
56auto eth0
57iface eth0 inet static
58 address $CONTAINER_IP
59 netmask $CONTAINER_NETMASK
60 gateway $CONTAINER_GATEWAY
61EOF
62
63# Configure the first run installer
64INSTALL_SH=$ROOTFS/root/install.sh
65cat > $INSTALL_SH <<EOF
66#!/bin/bash
67echo "nameserver $NAMESERVER" | resolvconf -a eth0
68sleep 1
Anthony Younge2c3a372011-09-12 23:25:37 -070069apt-get update
70apt-get -y --force-yes install git-core vim-nox sudo
Anthony Young72d69632011-09-12 21:09:55 -070071git clone git://github.com/cloudbuilders/nfs-stack.git /root/nfs-stack
72EOF
73
74chmod 700 $INSTALL_SH
75
76# Make installer run on boot
77RC_LOCAL=$ROOTFS/etc/rc.local
78cat > $RC_LOCAL <<EOF
79#!/bin/sh -e
80/root/install.sh
81EOF
82
Anthony Younge2c3a372011-09-12 23:25:37 -070083# Setup apt cache
84# FIXME - use proper fstab mount
85CWD=`pwd`
86APTCACHEDIR=$CWD/cache/apt
87mkdir -p $APTCACHEDIR
88cp -pr $APTCACHEDIR/* $ROOTFS/var/cache/apt/
89
Anthony Young72d69632011-09-12 21:09:55 -070090# Configure cgroup directory
91mkdir -p /cgroup
92mount none -t cgroup /cgroup
93
94# Start our container
95lxc-start -d -n $CONTAINER