blob: 146e3fccd7b5f2dc0446d426962cb97ae592df99 [file] [log] [blame]
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -07001#!/bin/bash
Dean Troyer56119512011-10-11 19:39:34 -05002# build_ramdisk.sh - Build RAM disk images
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -07003
4if [ ! "$#" -eq "1" ]; then
5 echo "$0 builds a gziped natty openstack install"
6 echo "usage: $0 dest"
7 exit 1
8fi
9
Dean Troyera6466e02011-10-25 17:53:24 -050010IMG_FILE=$1
11
Dean Troyer407ee7e2011-09-29 16:38:59 -050012PROGDIR=`dirname $0`
Dean Troyerd4a3bac2011-10-03 21:16:27 -050013CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
Dean Troyer407ee7e2011-09-29 16:38:59 -050014
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070015# Source params
16source ./stackrc
17
Dean Troyer03412c82011-10-03 09:56:41 -050018# Store cwd
19CWD=`pwd`
20
Dean Troyer11e5e6f2011-10-03 09:40:32 -050021DEST=${DEST:-/opt/stack}
22
Dean Troyer8f851e72011-10-11 20:22:23 -050023# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
24STACKSH_PARAMS=${STACKSH_PARAMS:-}
25
Dean Troyera3379e02011-10-03 11:14:13 -050026# Option to use the version of devstack on which we are currently working
27USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
28
Dean Troyera6466e02011-10-25 17:53:24 -050029# Set up nbd
30modprobe nbd max_part=63
31NBD=${NBD:-/dev/nbd9}
32NBD_DEV=`basename $NBD`
33
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070034# clean install of natty
Dean Troyera6466e02011-10-25 17:53:24 -050035if [ ! -r $CHROOTCACHE/natty-base.img ]; then
36 $PROGDIR/get_uec_image.sh natty $CHROOTCACHE/natty-base.img
37# # copy kernel modules...
38# # NOTE(ja): is there a better way to do this?
39# cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
40# # a simple password - pass
41# echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070042fi
43
44# prime natty with as many apt/pips as we can
Dean Troyera6466e02011-10-25 17:53:24 -050045if [ ! -r $CHROOTCACHE/natty-dev.img ]; then
46 cp -p $CHROOTCACHE/natty-base.img $CHROOTCACHE/natty-dev.img
47
48 qemu-nbd -c $NBD $CHROOTCACHE/natty-dev.img
49 if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
50 echo "Couldn't connect $NBD"
51 exit 1
52 fi
53 MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
54 mount -t ext4 ${NBD}p1 $MNTDIR
55 cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
56
57 chroot $MNTDIR apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
58 chroot $MNTDIR pip install `cat files/pips/*`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070059
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070060 # Create a stack user that is a member of the libvirtd group so that stack
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070061 # is able to interact with libvirt.
Dean Troyera6466e02011-10-25 17:53:24 -050062 chroot $MNTDIR groupadd libvirtd
63 chroot $MNTDIR useradd stack -s /bin/bash -d $DEST -G libvirtd
64 mkdir -p $MNTDIR/$DEST
65 chroot $MNTDIR chown stack $DEST
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070066
67 # a simple password - pass
Dean Troyera6466e02011-10-25 17:53:24 -050068 echo stack:pass | chroot $MNTDIR chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070069
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070070 # and has sudo ability (in the future this should be limited to only what
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070071 # stack requires)
Dean Troyera6466e02011-10-25 17:53:24 -050072 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $MNTDIR/etc/sudoers
73
74 umount $MNTDIR
75 rmdir $MNTDIR
76 qemu-nbd -d $NBD
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070077fi
78
79# clone git repositories onto the system
80# ======================================
81
Dean Troyera6466e02011-10-25 17:53:24 -050082if [ ! -r $IMG_FILE ]; then
83 qemu-img convert -O raw $CHROOTCACHE/natty-dev.img $IMG_FILE
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070084fi
85
Dean Troyera6466e02011-10-25 17:53:24 -050086qemu-nbd -c $NBD $IMG_FILE
87if ! timeout 60 sh -c "while ! [ -e /sys/block/$NBD_DEV/pid ]; do sleep 1; done"; then
88 echo "Couldn't connect $NBD"
89 exit 1
90fi
91MNTDIR=`mktemp -d --tmpdir mntXXXXXXXX`
92mount -t ext4 ${NBD}p1 $MNTDIR
93cp -p /etc/resolv.conf $MNTDIR/etc/resolv.conf
94
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070095# git clone only if directory doesn't exist already. Since ``DEST`` might not
96# be owned by the installation user, we create the directory and change the
97# ownership to the proper user.
98function git_clone {
99
100 # clone new copy or fetch latest changes
Dean Troyera6466e02011-10-25 17:53:24 -0500101 CHECKOUT=${MNTDIR}$2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700102 if [ ! -d $CHECKOUT ]; then
103 mkdir -p $CHECKOUT
104 git clone $1 $CHECKOUT
105 else
106 pushd $CHECKOUT
107 git fetch
108 popd
109 fi
110
111 # FIXME(ja): checkout specified version (should works for branches and tags)
112
113 pushd $CHECKOUT
114 # checkout the proper branch/tag
115 git checkout $3
116 # force our local version to be the same as the remote version
117 git reset --hard origin/$3
118 popd
119
120 # give ownership to the stack user
Dean Troyera6466e02011-10-25 17:53:24 -0500121 chroot $MNTDIR chown -R stack $2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700122}
123
Dean Troyer11e5e6f2011-10-03 09:40:32 -0500124git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
125git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
126git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
127git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
128git_clone $DASH_REPO $DEST/dash $DASH_BRANCH
129git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
130git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700131
Dean Troyerb5da5192011-10-17 13:32:06 -0500132# Use this version of devstack
Dean Troyera6466e02011-10-25 17:53:24 -0500133rm -rf $MNTDIR/$DEST/devstack
134cp -pr $CWD $MNTDIR/$DEST/devstack
135chroot $MNTDIR chown -R stack $DEST/devstack
Dean Troyer03412c82011-10-03 09:56:41 -0500136
Dean Troyercf9db8d2011-10-03 13:42:16 -0500137# Configure host network for DHCP
Dean Troyera6466e02011-10-25 17:53:24 -0500138mkdir -p $MNTDIR/etc/network
139cat > $MNTDIR/etc/network/interfaces <<EOF
Dean Troyercf9db8d2011-10-03 13:42:16 -0500140auto lo
141iface lo inet loopback
142
143auto eth0
144iface eth0 inet dhcp
145EOF
146
Dean Troyer288f3bd2011-10-13 15:50:44 -0500147# Set hostname
Dean Troyera6466e02011-10-25 17:53:24 -0500148echo "ramstack" >$MNTDIR/etc/hostname
149echo "127.0.0.1 localhost ramstack" >$MNTDIR/etc/hosts
Dean Troyer288f3bd2011-10-13 15:50:44 -0500150
Dean Troyer8f851e72011-10-11 20:22:23 -0500151# Configure the runner
Dean Troyera6466e02011-10-25 17:53:24 -0500152RUN_SH=$MNTDIR/$DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500153cat > $RUN_SH <<EOF
154#!/usr/bin/env bash
155
Dean Troyer7c076ee2011-10-13 13:20:13 -0500156# Get IP range
157set \`ip addr show dev eth0 | grep inet\`
158PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
159export FLOATING_RANGE="\$PREFIX.224/27"
160
Dean Troyer8f851e72011-10-11 20:22:23 -0500161# Kill any existing screens
162killall screen
163
164# Run stack.sh
165cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
166echo >> $DEST/run.sh.log
167echo >> $DEST/run.sh.log
168echo "All done! Time to start clicking." >> $DEST/run.sh.log
169EOF
170
171# Make the run.sh executable
172chmod 755 $RUN_SH
Dean Troyera6466e02011-10-25 17:53:24 -0500173chroot $MNTDIR chown stack $DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500174
Dean Troyera6466e02011-10-25 17:53:24 -0500175umount $MNTDIR
176rmdir $MNTDIR
177qemu-nbd -d $NBD
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700178
Dean Troyera6466e02011-10-25 17:53:24 -0500179gzip -1 $IMG_FILE