blob: 63d37a9d9b170b91f1c139772515cc6d062b19c2 [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 Troyera3379e02011-10-03 11:14:13 -050021# Option to use the version of devstack on which we are currently working
22USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1}
23
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070024# clean install of natty
Dean Troyer4cbb2672011-10-03 09:14:36 -050025if [ ! -d $CHROOTCACHE/natty-base ]; then
26 $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070027 # copy kernel modules...
28 # NOTE(ja): is there a better way to do this?
Dean Troyer4cbb2672011-10-03 09:14:36 -050029 cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules
Dean Troyer407ee7e2011-09-29 16:38:59 -050030 # a simple password - pass
Dean Troyer4cbb2672011-10-03 09:14:36 -050031 echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070032fi
33
34# prime natty with as many apt/pips as we can
Dean Troyer4cbb2672011-10-03 09:14:36 -050035if [ ! -d $CHROOTCACHE/natty-dev ]; then
36 rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/
37 chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"`
38 chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*`
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070039
40 # Create a stack user that is a member of the libvirtd group so that stack
41 # is able to interact with libvirt.
Dean Troyer4cbb2672011-10-03 09:14:36 -050042 chroot $CHROOTCACHE/natty-dev groupadd libvirtd
Dean Troyer11e5e6f2011-10-03 09:40:32 -050043 chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d $DEST -G libvirtd
44 mkdir -p $CHROOTCACHE/natty-dev/$DEST
45 chown stack $CHROOTCACHE/natty-dev/$DEST
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070046
47 # a simple password - pass
Dean Troyer4cbb2672011-10-03 09:14:36 -050048 echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070049
50 # and has sudo ability (in the future this should be limited to only what
51 # stack requires)
Dean Troyer4cbb2672011-10-03 09:14:36 -050052 echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070053fi
54
55# clone git repositories onto the system
56# ======================================
57
Dean Troyer4cbb2672011-10-03 09:14:36 -050058if [ ! -d $CHROOTCACHE/natty-stack ]; then
59 rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070060fi
61
62# git clone only if directory doesn't exist already. Since ``DEST`` might not
63# be owned by the installation user, we create the directory and change the
64# ownership to the proper user.
65function git_clone {
66
67 # clone new copy or fetch latest changes
Dean Troyer4cbb2672011-10-03 09:14:36 -050068 CHECKOUT=$CHROOTCACHE/natty-stack$2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070069 if [ ! -d $CHECKOUT ]; then
70 mkdir -p $CHECKOUT
71 git clone $1 $CHECKOUT
72 else
73 pushd $CHECKOUT
74 git fetch
75 popd
76 fi
77
78 # FIXME(ja): checkout specified version (should works for branches and tags)
79
80 pushd $CHECKOUT
81 # checkout the proper branch/tag
82 git checkout $3
83 # force our local version to be the same as the remote version
84 git reset --hard origin/$3
85 popd
86
87 # give ownership to the stack user
Dean Troyer4cbb2672011-10-03 09:14:36 -050088 chroot $CHROOTCACHE/natty-stack/ chown -R stack $2
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070089}
90
Dean Troyer11e5e6f2011-10-03 09:40:32 -050091git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH
92git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH
93git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH
94git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH
95git_clone $DASH_REPO $DEST/dash $DASH_BRANCH
96git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH
97git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -070098
Dean Troyer03412c82011-10-03 09:56:41 -050099# Use this version of devstack?
100if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then
Dean Troyer10db4452011-10-03 11:16:32 -0500101 rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack
Dean Troyer6994f942011-10-03 11:03:27 -0500102 cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack
Dean Troyer03412c82011-10-03 09:56:41 -0500103fi
104
Dean Troyercf9db8d2011-10-03 13:42:16 -0500105# Configure host network for DHCP
106mkdir -p $CHROOTCACHE/natty-stack/etc/network
Dean Troyerd4a3bac2011-10-03 21:16:27 -0500107cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF
Dean Troyercf9db8d2011-10-03 13:42:16 -0500108auto lo
109iface lo inet loopback
110
111auto eth0
112iface eth0 inet dhcp
113EOF
114
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700115# build a new image
Dean Troyer10db4452011-10-03 11:16:32 -0500116BASE=$CHROOTCACHE/build.$$
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700117IMG=$BASE.img
118MNT=$BASE/
119
Jesse Andrews236943f2011-09-28 18:38:10 -0700120# (quickly) create a 2GB blank filesystem
121dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700122# force it to be initialized as ext2
123mkfs.ext2 -F $IMG
124
125# mount blank image loopback and load it
126mkdir -p $MNT
127mount -o loop $IMG $MNT
Dean Troyer4cbb2672011-10-03 09:14:36 -0500128rsync -azH $CHROOTCACHE/natty-stack/ $MNT
Jesse Andrewsd31c4ea2011-09-28 02:30:57 -0700129
130# umount and cleanup
131umount $MNT
132rmdir $MNT
133
134# gzip into final location
135gzip -1 $IMG -c > $1
136