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