blob: 32f90c05c063953140b23bd837125a44e1be3da0 [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)
Dean Troyer7f9aa712012-01-31 12:11:56 -060043TOP_DIR=$(cd $TOOLS_DIR/..; pwd)
44
45# Import common functions
46. $TOP_DIR/functions
Jesse Andrewsd7326d22011-11-20 10:02:26 -080047
48cd $TOP_DIR
49
50# Source params
51source ./stackrc
52
53DEST=${DEST:-/opt/stack}
54
55# Ubuntu distro to install
56DIST_NAME=${DIST_NAME:-oneiric}
57
58# Configure how large the VM should be
59GUEST_SIZE=${GUEST_SIZE:-2G}
60
61# exit on error to stop unexpected errors
62set -o errexit
63set -o xtrace
64
65# Abort if localrc is not set
66if [ ! -e $TOP_DIR/localrc ]; then
67 echo "You must have a localrc with ALL necessary passwords defined before proceeding."
68 echo "See stack.sh for required passwords."
69 exit 1
70fi
71
72# Install deps if needed
73DEPS="kvm libvirt-bin kpartx cloud-utils curl"
Dean Troyer7f9aa712012-01-31 12:11:56 -060074apt_get install -y --force-yes $DEPS
Jesse Andrewsd7326d22011-11-20 10:02:26 -080075
76# Where to store files and instances
77CACHEDIR=${CACHEDIR:-/opt/stack/cache}
78WORK_DIR=${WORK_DIR:-/opt/ramstack}
79
80# Where to store images
81image_dir=$WORK_DIR/images/$DIST_NAME
82mkdir -p $image_dir
83
84# Get the base image if it does not yet exist
85if [ ! -e $image_dir/disk ]; then
86 $TOOLS_DIR/get_uec_image.sh -r 2000M $DIST_NAME $image_dir/disk
87fi
88
89# Configure the root password of the vm to be the same as ``ADMIN_PASSWORD``
90ROOT_PASSWORD=${ADMIN_PASSWORD:-password}
91
92# Name of our instance, used by libvirt
93GUEST_NAME=${GUEST_NAME:-devstack}
94
95# Pre-load the image with basic environment
96if [ ! -e $image_dir/disk-primed ]; then
97 cp $image_dir/disk $image_dir/disk-primed
98 $TOOLS_DIR/warm_apts_and_pips_for_uec.sh $image_dir/disk-primed
99 $TOOLS_DIR/copy_dev_environment_to_uec.sh $image_dir/disk-primed
100fi
101
102# Back to devstack
103cd $TOP_DIR
104
105DEST_FILE_TMP=`mktemp $DEST_FILE.XXXXXX`
106MNT_DIR=`mktemp -d --tmpdir mntXXXXXXXX`
107cp $image_dir/disk-primed $DEST_FILE_TMP
108mount -t ext4 -o loop $DEST_FILE_TMP $MNT_DIR
109mount -o bind /dev /$MNT_DIR/dev
110cp -p /etc/resolv.conf $MNT_DIR/etc/resolv.conf
111echo root:$ROOT_PASSWORD | chroot $MNT_DIR chpasswd
112touch $MNT_DIR/$DEST/.ramdisk
113
114# We need to install a non-virtual kernel and modules to boot from
115if [ ! -r "`ls $MNT_DIR/boot/vmlinuz-*-generic | head -1`" ]; then
116 chroot $MNT_DIR apt-get install -y linux-generic
117fi
118
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800119git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
120git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
121git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
122git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
123git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH
124git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
125git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Dean Troyer608bb122012-01-10 14:43:17 -0600126git_clone $TEMPEST_REPO $DEST/tempest $TEMPEST_BRANCH
Jesse Andrewsd7326d22011-11-20 10:02:26 -0800127
128# Use this version of devstack
129rm -rf $MNT_DIR/$DEST/devstack
130cp -pr $TOP_DIR $MNT_DIR/$DEST/devstack
131chroot $MNT_DIR chown -R stack $DEST/devstack
132
133# Configure host network for DHCP
134mkdir -p $MNT_DIR/etc/network
135cat > $MNT_DIR/etc/network/interfaces <<EOF
136auto lo
137iface lo inet loopback
138
139auto eth0
140iface eth0 inet dhcp
141EOF
142
143# Set hostname
144echo "ramstack" >$MNT_DIR/etc/hostname
145echo "127.0.0.1 localhost ramstack" >$MNT_DIR/etc/hosts
146
147# Configure the runner
148RUN_SH=$MNT_DIR/$DEST/run.sh
149cat > $RUN_SH <<EOF
150#!/usr/bin/env bash
151
152# Get IP range
153set \`ip addr show dev eth0 | grep inet\`
154PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
155export FLOATING_RANGE="\$PREFIX.224/27"
156
157# Kill any existing screens
158killall screen
159
160# Run stack.sh
161cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
162echo >> $DEST/run.sh.log
163echo >> $DEST/run.sh.log
164echo "All done! Time to start clicking." >> $DEST/run.sh.log
165EOF
166
167# Make the run.sh executable
168chmod 755 $RUN_SH
169chroot $MNT_DIR chown stack $DEST/run.sh
170
171umount $MNT_DIR/dev
172umount $MNT_DIR
173rmdir $MNT_DIR
174mv $DEST_FILE_TMP $DEST_FILE
175rm -f $DEST_FILE_TMP
176
177trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT