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