| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 1 | #!/bin/bash | 
| Dean Troyer | 5611951 | 2011-10-11 19:39:34 -0500 | [diff] [blame] | 2 | # build_ramdisk.sh - Build RAM disk images | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 3 |  | 
|  | 4 | if [ ! "$#" -eq "1" ]; then | 
|  | 5 | echo "$0 builds a gziped natty openstack install" | 
|  | 6 | echo "usage: $0 dest" | 
|  | 7 | exit 1 | 
|  | 8 | fi | 
|  | 9 |  | 
| Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 10 | PROGDIR=`dirname $0` | 
| Dean Troyer | d4a3bac | 2011-10-03 21:16:27 -0500 | [diff] [blame] | 11 | CHROOTCACHE=${CHROOTCACHE:-/var/cache/devstack} | 
| Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 12 |  | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 13 | # Source params | 
|  | 14 | source ./stackrc | 
|  | 15 |  | 
| Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 16 | # Store cwd | 
|  | 17 | CWD=`pwd` | 
|  | 18 |  | 
| Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 19 | DEST=${DEST:-/opt/stack} | 
|  | 20 |  | 
| Dean Troyer | a3379e0 | 2011-10-03 11:14:13 -0500 | [diff] [blame] | 21 | # Option to use the version of devstack on which we are currently working | 
|  | 22 | USE_CURRENT_DEVSTACK=${USE_CURRENT_DEVSTACK:-1} | 
|  | 23 |  | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 24 | # clean install of natty | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 25 | if [ ! -d $CHROOTCACHE/natty-base ]; then | 
|  | 26 | $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 27 | # copy kernel modules... | 
|  | 28 | # NOTE(ja): is there a better way to do this? | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 29 | cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules | 
| Dean Troyer | 407ee7e | 2011-09-29 16:38:59 -0500 | [diff] [blame] | 30 | # a simple password - pass | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 31 | echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 32 | fi | 
|  | 33 |  | 
|  | 34 | # prime natty with as many apt/pips as we can | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 35 | if [ ! -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 Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 39 |  | 
|  | 40 | # Create a stack user that is a member of the libvirtd group so that stack | 
|  | 41 | # is able to interact with libvirt. | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 42 | chroot $CHROOTCACHE/natty-dev groupadd libvirtd | 
| Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 43 | 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 Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 46 |  | 
|  | 47 | # a simple password - pass | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 48 | echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 49 |  | 
|  | 50 | # and has sudo ability (in the future this should be limited to only what | 
|  | 51 | # stack requires) | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 52 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 53 | fi | 
|  | 54 |  | 
|  | 55 | # clone git repositories onto the system | 
|  | 56 | # ====================================== | 
|  | 57 |  | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 58 | if [ ! -d $CHROOTCACHE/natty-stack ]; then | 
|  | 59 | rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/ | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 60 | fi | 
|  | 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. | 
|  | 65 | function git_clone { | 
|  | 66 |  | 
|  | 67 | # clone new copy or fetch latest changes | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 68 | CHECKOUT=$CHROOTCACHE/natty-stack$2 | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 69 | 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 Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 88 | chroot $CHROOTCACHE/natty-stack/ chown -R stack $2 | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 89 | } | 
|  | 90 |  | 
| Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame] | 91 | git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH | 
|  | 92 | git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH | 
|  | 93 | git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH | 
|  | 94 | git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH | 
|  | 95 | git_clone $DASH_REPO $DEST/dash $DASH_BRANCH | 
|  | 96 | git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH | 
|  | 97 | git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 98 |  | 
| Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 99 | # Use this version of devstack? | 
|  | 100 | if [ "$USE_CURRENT_DEVSTACK" = "1" ]; then | 
| Dean Troyer | 10db445 | 2011-10-03 11:16:32 -0500 | [diff] [blame] | 101 | rm -rf $CHROOTCACHE/natty-stack/$DEST/devstack | 
| Dean Troyer | 6994f94 | 2011-10-03 11:03:27 -0500 | [diff] [blame] | 102 | cp -pr $CWD $CHROOTCACHE/natty-stack/$DEST/devstack | 
| Dean Troyer | 03412c8 | 2011-10-03 09:56:41 -0500 | [diff] [blame] | 103 | fi | 
|  | 104 |  | 
| Dean Troyer | cf9db8d | 2011-10-03 13:42:16 -0500 | [diff] [blame] | 105 | # Configure host network for DHCP | 
|  | 106 | mkdir -p $CHROOTCACHE/natty-stack/etc/network | 
| Dean Troyer | d4a3bac | 2011-10-03 21:16:27 -0500 | [diff] [blame] | 107 | cat > $CHROOTCACHE/natty-stack/etc/network/interfaces <<EOF | 
| Dean Troyer | cf9db8d | 2011-10-03 13:42:16 -0500 | [diff] [blame] | 108 | auto lo | 
|  | 109 | iface lo inet loopback | 
|  | 110 |  | 
|  | 111 | auto eth0 | 
|  | 112 | iface eth0 inet dhcp | 
|  | 113 | EOF | 
|  | 114 |  | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 115 | # build a new image | 
| Dean Troyer | 10db445 | 2011-10-03 11:16:32 -0500 | [diff] [blame] | 116 | BASE=$CHROOTCACHE/build.$$ | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 117 | IMG=$BASE.img | 
|  | 118 | MNT=$BASE/ | 
|  | 119 |  | 
| Jesse Andrews | 236943f | 2011-09-28 18:38:10 -0700 | [diff] [blame] | 120 | # (quickly) create a 2GB blank filesystem | 
|  | 121 | 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] | 122 | # force it to be initialized as ext2 | 
|  | 123 | mkfs.ext2 -F $IMG | 
|  | 124 |  | 
|  | 125 | # mount blank image loopback and load it | 
|  | 126 | mkdir -p $MNT | 
|  | 127 | mount -o loop $IMG $MNT | 
| Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 128 | rsync -azH $CHROOTCACHE/natty-stack/ $MNT | 
| Jesse Andrews | d31c4ea | 2011-09-28 02:30:57 -0700 | [diff] [blame] | 129 |  | 
|  | 130 | # umount and cleanup | 
|  | 131 | umount $MNT | 
|  | 132 | rmdir $MNT | 
|  | 133 |  | 
|  | 134 | # gzip into final location | 
|  | 135 | gzip -1 $IMG -c > $1 | 
|  | 136 |  |