blob: b9f4afde578c65862b3b96aff57bf7479c9b17e2 [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
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070030 # copy kernel modules...
31 # 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
43 # Create a stack user that is a member of the libvirtd group so that stack
44 # 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
48 chown stack $CHROOTCACHE/natty-dev/$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
53 # and has sudo ability (in the future this should be limited to only what
54 # 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 Troyer8f851e72011-10-11 20:22:23 -0500118# Configure the runner
119RUN_SH=$CHROOTCACHE/natty-stack/$DEST/run.sh
120cat > $RUN_SH <<EOF
121#!/usr/bin/env bash
122
123# Pre-empt download of natty image
124tar czf $DEST/devstack/files/natty.tgz /etc/hosts
125touch $DEST/devstack/files/images/natty-server-cloudimg-amd64-vmlinuz-virtual
126touch $DEST/devstack/files/images/natty-server-cloudimg-amd64.img
127
128# Kill any existing screens
129killall screen
130
131# Run stack.sh
132cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log
133echo >> $DEST/run.sh.log
134echo >> $DEST/run.sh.log
135echo "All done! Time to start clicking." >> $DEST/run.sh.log
136EOF
137
138# Make the run.sh executable
139chmod 755 $RUN_SH
140
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700141# build a new image
Dean Troyer10db4452011-10-03 11:16:32 -0500142BASE=$CHROOTCACHE/build.$$
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700143IMG=$BASE.img
144MNT=$BASE/
145
Jesse Andrews236943f2011-09-28 18:38:10 -0700146# (quickly) create a 2GB blank filesystem
147dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700148# force it to be initialized as ext2
149mkfs.ext2 -F $IMG
150
151# mount blank image loopback and load it
152mkdir -p $MNT
153mount -o loop $IMG $MNT
Dean Troyer4cbb2672011-10-03 09:14:36 -0500154rsync -azH $CHROOTCACHE/natty-stack/ $MNT
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700155
156# umount and cleanup
157umount $MNT
158rmdir $MNT
159
160# gzip into final location
161gzip -1 $IMG -c > $1
162