blob: 3bd704ba9c1dee68ad82aed9aa4f0a2f4c88803c [file] [log] [blame]
Jesse Andrewsd7326d22011-11-20 10:02:26 -08001#!/usr/bin/env bash
2# build_uec_ramdisk.sh - Build RAM disk images based on UEC image
3
4# exit on error to stop unexpected errors
5set -o errexit
6
7if [ ! "$#" -eq "1" ]; then
8 echo "$0 builds a gziped Ubuntu OpenStack install"
9 echo "usage: $0 dest"
10 exit 1
11fi
12
13# Make sure that we have the proper version of ubuntu (only works on oneiric)
14if ! egrep -q "oneiric" /etc/lsb-release; then
15 echo "This script only works with ubuntu oneiric."
16 exit 1
17fi
18
19# Clean up resources that may be in use
20cleanup() {
21 set +o errexit
22
23 if [ -n "$MNT_DIR" ]; then
24 umount $MNT_DIR/dev
25 umount $MNT_DIR
26 fi
27
28 if [ -n "$DEST_FILE_TMP" ]; then
29 rm $DEST_FILE_TMP
30 fi
31
32 # Kill ourselves to signal parents
33 trap 2; kill -2 $$
34}
35
36trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT
37
38# Output dest image
39DEST_FILE=$1
40
41# Keep track of the current directory
42TOOLS_DIR=$(cd $(dirname "$0") && pwd)
43TOP_DIR=`cd $TOOLS_DIR/..; pwd`
44
45cd $TOP_DIR
46
47# Source params
48source ./stackrc
49
50DEST=${DEST:-/opt/stack}
51
52# Ubuntu distro to install
53DIST_NAME=${DIST_NAME:-oneiric}
54
55# Configure how large the VM should be
56GUEST_SIZE=${GUEST_SIZE:-2G}
57
58# exit on error to stop unexpected errors
59set -o errexit
60set -o xtrace
61
62# Abort if localrc is not set
63if [ ! -e $TOP_DIR/localrc ]; then
64 echo "You must have a localrc with ALL necessary passwords defined before proceeding."
65 echo "See stack.sh for required passwords."
66 exit 1
67fi
68
69# Install deps if needed
70DEPS="kvm libvirt-bin kpartx cloud-utils curl"
71apt-get install -y --force-yes $DEPS
72
73# Where to store files and instances
74CACHEDIR=${CACHEDIR:-/opt/stack/cache}
75WORK_DIR=${WORK_DIR:-/opt/ramstack}
76
77# Where to store images
78image_dir=$WORK_DIR/images/$DIST_NAME
79mkdir -p $image_dir
80
81# Get the base image if it does not yet exist
82if [ ! -e $image_dir/disk ]; then
83 $TOOLS_DIR/get_uec_image.sh -r 2000M $DIST_NAME $image_dir/disk
84fi
85
86# Configure the root password of the vm to be the same as ``ADMIN_PASSWORD``
87ROOT_PASSWORD=${ADMIN_PASSWORD:-password}
88
89# Name of our instance, used by libvirt
90GUEST_NAME=${GUEST_NAME:-devstack}
91
92# Pre-load the image with basic environment
93if [ ! -e $image_dir/disk-primed ]; then
94 cp $image_dir/disk $image_dir/disk-primed
95 $TOOLS_DIR/warm_apts_and_pips_for_uec.sh $image_dir/disk-primed
96 $TOOLS_DIR/copy_dev_environment_to_uec.sh $image_dir/disk-primed
97fi
98
99# Back to devstack
100cd $TOP_DIR
101
102DEST_FILE_TMP=`mktemp $DEST_FILE.XXXXXX`
103MNT_DIR=`mktemp -d --tmpdir mntXXXXXXXX`
104cp $image_dir/disk-primed $DEST_FILE_TMP
105mount -t ext4 -o loop $DEST_FILE_TMP $MNT_DIR
106mount -o bind /dev /$MNT_DIR/dev
107cp -p /etc/resolv.conf $MNT_DIR/etc/resolv.conf
108echo root:$ROOT_PASSWORD | chroot $MNT_DIR chpasswd
109touch $MNT_DIR/$DEST/.ramdisk
110
111# We need to install a non-virtual kernel and modules to boot from
112if [ ! -r "`ls $MNT_DIR/boot/vmlinuz-*-generic | head -1`" ]; then
113 chroot $MNT_DIR apt-get install -y linux-generic
114fi
115
116# git clone only if directory doesn't exist already. Since ``DEST`` might not
117# be owned by the installation user, we create the directory and change the
118# ownership to the proper user.
119function git_clone {
120
121 # clone new copy or fetch latest changes
122 CHECKOUT=${MNT_DIR}$2
123 if [ ! -d $CHECKOUT ]; then
124 mkdir -p $CHECKOUT
125 git clone $1 $CHECKOUT
126 else
127 pushd $CHECKOUT
128 git fetch
129 popd
130 fi
131
132 # FIXME(ja): checkout specified version (should works for branches and tags)
133
134 pushd $CHECKOUT
135 # checkout the proper branch/tag
136 git checkout $3
137 # force our local version to be the same as the remote version
138 git reset --hard origin/$3
139 popd
140
141 # give ownership to the stack user
142 chroot $MNT_DIR chown -R stack $2
143}
144
145git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
146git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
147git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
148git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
149git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH
150git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
151git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Dean Troyerf79cc422011-12-01 10:21:42 -0600152git_clone $CITEST_REPO $DEST/tempest $CITEST_BRANCH
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800153
154# Use this version of devstack
155rm -rf $MNT_DIR/$DEST/devstack
156cp -pr $TOP_DIR $MNT_DIR/$DEST/devstack
157chroot $MNT_DIR chown -R stack $DEST/devstack
158
159# Configure host network for DHCP
160mkdir -p $MNT_DIR/etc/network
161cat > $MNT_DIR/etc/network/interfaces <<EOF
162auto lo
163iface lo inet loopback
164
165auto eth0
166iface eth0 inet dhcp
167EOF
168
169# Set hostname
170echo "ramstack" >$MNT_DIR/etc/hostname
171echo "127.0.0.1 localhost ramstack" >$MNT_DIR/etc/hosts
172
173# Configure the runner
174RUN_SH=$MNT_DIR/$DEST/run.sh
175cat > $RUN_SH <<EOF
176#!/usr/bin/env bash
177
178# Get IP range
179set \`ip addr show dev eth0 | grep inet\`
180PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
181export FLOATING_RANGE="\$PREFIX.224/27"
182
183# Kill any existing screens
184killall screen
185
186# Run stack.sh
187cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
188echo >> $DEST/run.sh.log
189echo >> $DEST/run.sh.log
190echo "All done! Time to start clicking." >> $DEST/run.sh.log
191EOF
192
193# Make the run.sh executable
194chmod 755 $RUN_SH
195chroot $MNT_DIR chown stack $DEST/run.sh
196
197umount $MNT_DIR/dev
198umount $MNT_DIR
199rmdir $MNT_DIR
200mv $DEST_FILE_TMP $DEST_FILE
201rm -f $DEST_FILE_TMP
202
203trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT