Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | if [ ! "$#" -eq "1" ]; then |
| 4 | echo "$0 builds a gziped natty openstack install" |
| 5 | echo "usage: $0 dest" |
| 6 | exit 1 |
| 7 | fi |
| 8 | |
Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 9 | PROGDIR=`dirname $0` |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 10 | CHROOTCACHE=${CHROOTCACHE:-/root/cache} |
Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 11 | |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 12 | # Source params |
| 13 | source ./stackrc |
| 14 | |
| 15 | # clean install of natty |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 16 | if [ ! -d $CHROOTCACHE/natty-base ]; then |
| 17 | $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 18 | # copy kernel modules... |
| 19 | # NOTE(ja): is there a better way to do this? |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 20 | cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules |
Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 21 | # a simple password - pass |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 22 | echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 23 | fi |
| 24 | |
| 25 | # prime natty with as many apt/pips as we can |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 26 | if [ ! -d $CHROOTCACHE/natty-dev ]; then |
| 27 | rsync -azH $CHROOTCACHE/natty-base/ $CHROOTCACHE/natty-dev/ |
| 28 | chroot $CHROOTCACHE/natty-dev apt-get install -y `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
| 29 | chroot $CHROOTCACHE/natty-dev pip install `cat files/pips/*` |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 30 | |
| 31 | # Create a stack user that is a member of the libvirtd group so that stack |
| 32 | # is able to interact with libvirt. |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 33 | chroot $CHROOTCACHE/natty-dev groupadd libvirtd |
| 34 | chroot $CHROOTCACHE/natty-dev useradd stack -s /bin/bash -d /opt -G libvirtd |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 35 | |
| 36 | # a simple password - pass |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 37 | echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 38 | |
| 39 | # and has sudo ability (in the future this should be limited to only what |
| 40 | # stack requires) |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 41 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 42 | fi |
| 43 | |
| 44 | # clone git repositories onto the system |
| 45 | # ====================================== |
| 46 | |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 47 | if [ ! -d $CHROOTCACHE/natty-stack ]; then |
| 48 | rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/ |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 49 | fi |
| 50 | |
| 51 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 52 | # be owned by the installation user, we create the directory and change the |
| 53 | # ownership to the proper user. |
| 54 | function git_clone { |
| 55 | |
| 56 | # clone new copy or fetch latest changes |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 57 | CHECKOUT=$CHROOTCACHE/natty-stack$2 |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 58 | if [ ! -d $CHECKOUT ]; then |
| 59 | mkdir -p $CHECKOUT |
| 60 | git clone $1 $CHECKOUT |
| 61 | else |
| 62 | pushd $CHECKOUT |
| 63 | git fetch |
| 64 | popd |
| 65 | fi |
| 66 | |
| 67 | # FIXME(ja): checkout specified version (should works for branches and tags) |
| 68 | |
| 69 | pushd $CHECKOUT |
| 70 | # checkout the proper branch/tag |
| 71 | git checkout $3 |
| 72 | # force our local version to be the same as the remote version |
| 73 | git reset --hard origin/$3 |
| 74 | popd |
| 75 | |
| 76 | # give ownership to the stack user |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 77 | chroot $CHROOTCACHE/natty-stack/ chown -R stack $2 |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | git_clone $NOVA_REPO /opt/stack/nova $NOVA_BRANCH |
| 81 | git_clone $GLANCE_REPO /opt/stack/glance $GLANCE_BRANCH |
| 82 | git_clone $KEYSTONE_REPO /opt/stack/keystone $KEYSTONE_BRANCH |
| 83 | git_clone $NOVNC_REPO /opt/stack/novnc $NOVNC_BRANCH |
| 84 | git_clone $DASH_REPO /opt/stack/dash $DASH_BRANCH |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 85 | git_clone $NOVACLIENT_REPO /opt/stack/python-novaclient $NOVACLIENT_BRANCH |
| 86 | git_clone $OPENSTACKX_REPO /opt/stack/openstackx $OPENSTACKX_BRANCH |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 87 | |
| 88 | # build a new image |
| 89 | BASE=build.$$ |
| 90 | IMG=$BASE.img |
| 91 | MNT=$BASE/ |
| 92 | |
Jesse Andrews | 236943f | 2011-09-28 18:38:10 -0700 | [diff] [blame] | 93 | # (quickly) create a 2GB blank filesystem |
| 94 | dd bs=1 count=1 seek=$((2*1024*1024*1024)) if=/dev/zero of=$IMG |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 95 | # force it to be initialized as ext2 |
| 96 | mkfs.ext2 -F $IMG |
| 97 | |
| 98 | # mount blank image loopback and load it |
| 99 | mkdir -p $MNT |
| 100 | mount -o loop $IMG $MNT |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame^] | 101 | rsync -azH $CHROOTCACHE/natty-stack/ $MNT |
Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 102 | |
| 103 | # umount and cleanup |
| 104 | umount $MNT |
| 105 | rmdir $MNT |
| 106 | |
| 107 | # gzip into final location |
| 108 | gzip -1 $IMG -c > $1 |
| 109 | |