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