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