blob: ca7bdd5f0052ce4f8f456bc960ab387429a86316 [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 Troyer407ee7e2011-09-29 16:38:59 -050010PROGDIR=`dirname $0`
Dean Troyerd4a3bac2011-10-03 21:16:27 -050011CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack}
Dean Troyer407ee7e2011-09-29 16:38:59 -050012
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070013# Source params
14source ./stackrc
15
Dean Troyer03412c82011-10-03 09:56:41 -050016# Store cwd
17CWD=`pwd`
18
Dean Troyer11e5e6f2011-10-03 09:40:32 -050019DEST=${DEST:-/opt/stack}
20
Dean Troyer8f851e72011-10-11 20:22:23 -050021# Param string to pass to stack.sh. Like "EC2_DMZ_HOST=192.168.1.1 MYSQL_USER=nova"
22STACKSH_PARAMS=${STACKSH_PARAMS:-}
23
Dean Troyera3379e02011-10-03 11:14:13 -050024# Option to use the version of devstack on which we are currently working
25USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
26
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070027# clean install of natty
Dean Troyer4cbb2672011-10-03 09:14:36 -050028if [ ! -d $CHROOTCACHE/natty-base ]; then
29 $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070030 # copy kernel modules...
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070031 # NOTE(ja): is there a better way to do this?
Dean Troyer4cbb2672011-10-03 09:14:36 -050032 cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
Dean Troyer407ee7e2011-09-29 16:38:59 -050033 # a simple password - pass
Dean Troyer4cbb2672011-10-03 09:14:36 -050034 echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070035fi
36
37# prime natty with as many apt/pips as we can
Dean Troyer4cbb2672011-10-03 09:14:36 -050038if [ ! -d $CHROOTCACHE/natty-dev ]; then
39 rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
40 chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
41 chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070042
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070043 # Create a stack user that is a member of the libvirtd group so that stack
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070044 # is able to interact with libvirt.
Dean Troyer4cbb2672011-10-03 09:14:36 -050045 chroot $CHROOTCACHE/natty-dev groupadd libvirtd
Dean Troyer11e5e6f2011-10-03 09:40:32 -050046 chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
47 mkdir -p $CHROOTCACHE/natty-dev/$DEST
Dean Troyer288f3bd2011-10-13 15:50:44 -050048 chroot $CHROOTCACHE/natty-dev chown stack $DEST
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070049
50 # a simple password - pass
Dean Troyer4cbb2672011-10-03 09:14:36 -050051 echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070052
Vishvananda Ishaya9b353672011-10-20 10:07:10 -070053 # and has sudo ability (in the future this should be limited to only what
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070054 # stack requires)
Dean Troyer4cbb2672011-10-03 09:14:36 -050055 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070056fi
57
58# clone git repositories onto the system
59# ======================================
60
Dean Troyer4cbb2672011-10-03 09:14:36 -050061if [ ! -d $CHROOTCACHE/natty-stack ]; then
62 rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070063fi
64
65# git clone only if directory doesn't exist already. Since ``DEST`` might not
66# be owned by the installation user, we create the directory and change the
67# ownership to the proper user.
68function git_clone {
69
70 # clone new copy or fetch latest changes
Dean Troyer4cbb2672011-10-03 09:14:36 -050071 CHECKOUT=$CHROOTCACHE/natty-stack$2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070072 if [ ! -d $CHECKOUT ]; then
73 mkdir -p $CHECKOUT
74 git clone $1 $CHECKOUT
75 else
76 pushd $CHECKOUT
77 git fetch
78 popd
79 fi
80
81 # FIXME(ja): checkout specified version (should works for branches and tags)
82
83 pushd $CHECKOUT
84 # checkout the proper branch/tag
85 git checkout $3
86 # force our local version to be the same as the remote version
87 git reset --hard origin/$3
88 popd
89
90 # give ownership to the stack user
Dean Troyer4cbb2672011-10-03 09:14:36 -050091 chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070092}
93
Dean Troyer11e5e6f2011-10-03 09:40:32 -050094git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
95git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
96git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
97git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
98git_clone $DASH_REPO $DEST/dash $DASH_BRANCH
99git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
100git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700101
Dean Troyer03412c82011-10-03 09:56:41 -0500102# Use this version of devstack?
103if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
Dean Troyer10db4452011-10-03 11:16:32 -0500104 rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack
Dean Troyer6994f942011-10-03 11:03:27 -0500105 cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack
Dean Troyer03412c82011-10-03 09:56:41 -0500106fi
107
Dean Troyercf9db8d2011-10-03 13:42:16 -0500108# Configure host network for DHCP
109mkdir -p $CHROOTCACHE/natty-stack/etc/network
Dean Troyerd4a3bac2011-10-03 21:16:27 -0500110cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF
Dean Troyercf9db8d2011-10-03 13:42:16 -0500111auto lo
112iface lo inet loopback
113
114auto eth0
115iface eth0 inet dhcp
116EOF
117
Dean Troyer288f3bd2011-10-13 15:50:44 -0500118# Set hostname
119echo "ramstack" >$CHROOTCACHE/natty-stack/etc/hostname
120echo "127.0.0.1 localhost ramstack" >$CHROOTCACHE/natty-stack/etc/hosts
121
Dean Troyer8f851e72011-10-11 20:22:23 -0500122# Configure the runner
123RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh
124cat > $RUN_SH <<EOF
125#!/usr/bin/env bash
126
Dean Troyer7c076ee2011-10-13 13:20:13 -0500127# Get IP range
128set \`ip addr show dev eth0 | grep inet\`
129PREFIX=\`echo \$2 | cut -d. -f1,2,3\`
130export FLOATING_RANGE="\$PREFIX.224/27"
131
Dean Troyer8f851e72011-10-11 20:22:23 -0500132# Kill any existing screens
133killall screen
134
135# Run stack.sh
136cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
137echo >> $DEST/run.sh.log
138echo >> $DEST/run.sh.log
139echo "All done! Time to start clicking." >> $DEST/run.sh.log
140EOF
141
142# Make the run.sh executable
143chmod 755 $RUN_SH
Dean Troyer7c076ee2011-10-13 13:20:13 -0500144chroot $CHROOTCACHE/natty-stack chown stack $DEST/run.sh
Dean Troyer8f851e72011-10-11 20:22:23 -0500145
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700146# build a new image
Dean Troyer10db4452011-10-03 11:16:32 -0500147BASE=$CHROOTCACHE/build.$$
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700148IMG=$BASE.img
149MNT=$BASE/
150
Jesse Andrews236943f2011-09-28 18:38:10 -0700151# (quickly) create a 2GB blank filesystem
152dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700153# force it to be initialized as ext2
154mkfs.ext2 -F $IMG
155
156# mount blank image loopback and load it
157mkdir -p $MNT
158mount -o loop $IMG $MNT
Dean Troyer4cbb2672011-10-03 09:14:36 -0500159rsync -azH $CHROOTCACHE/natty-stack/ $MNT
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700160
161# umount and cleanup
162umount $MNT
163rmdir $MNT
164
165# gzip into final location
166gzip -1 $IMG -c > $1
167