Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Dean Troyer | cc80654 | 2011-10-03 09:30:57 -0500 | [diff] [blame] | 3 | PROGDIR=`dirname $0` |
Dean Troyer | 4cbb267 | 2011-10-03 09:14:36 -0500 | [diff] [blame] | 4 | CHROOTCACHE=${CHROOTCACHE:-/root/cache} |
| 5 | |
Anthony Young | 2f14020 | 2011-09-26 13:02:40 -0700 | [diff] [blame] | 6 | # Source params |
| 7 | source ./stackrc |
| 8 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 9 | # TODO: make dest not hardcoded |
| 10 | |
| 11 | NAME=$1 |
Jesse Andrews | 1639ed6 | 2011-09-11 15:42:17 -0700 | [diff] [blame] | 12 | DEST="/nfs/$NAME" |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 13 | |
| 14 | # remove old nfs filesystem if one exists |
| 15 | rm -rf $DEST |
| 16 | |
Dean Troyer | cc80654 | 2011-10-03 09:30:57 -0500 | [diff] [blame] | 17 | # clean install of natty |
| 18 | if [ ! -d $CHROOTCACHE/natty-base ]; then |
| 19 | $PROGDIR/make_image.sh -C natty $CHROOTCACHE/natty-base |
| 20 | # copy kernel modules... |
| 21 | # NOTE(ja): is there a better way to do this? |
| 22 | cp -pr /lib/modules/`uname -r` $CHROOTCACHE/natty-base/lib/modules |
| 23 | # a simple password - pass |
| 24 | echo root:pass | chroot $CHROOTCACHE/natty-base chpasswd |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 25 | fi |
| 26 | |
Dean Troyer | cc80654 | 2011-10-03 09:30:57 -0500 | [diff] [blame] | 27 | # prime natty with as many apt/pips as we can |
| 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/*` |
| 32 | |
| 33 | # Create a stack user that is a member of the libvirtd group so that stack |
| 34 | # is able to interact with libvirt. |
| 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 |
Dean Troyer | cc80654 | 2011-10-03 09:30:57 -0500 | [diff] [blame] | 39 | |
| 40 | # a simple password - pass |
| 41 | echo stack:pass | chroot $CHROOTCACHE/natty-dev chpasswd |
| 42 | |
| 43 | # and has sudo ability (in the future this should be limited to only what |
| 44 | # stack requires) |
| 45 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $CHROOTCACHE/natty-dev/etc/sudoers |
| 46 | fi |
| 47 | |
| 48 | # clone git repositories onto the system |
| 49 | # ====================================== |
| 50 | |
| 51 | if [ ! -d $CHROOTCACHE/natty-stack ]; then |
| 52 | rsync -azH $CHROOTCACHE/natty-dev/ $CHROOTCACHE/natty-stack/ |
| 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 |
| 61 | CHECKOUT=$CHROOTCACHE/natty-stack$2 |
| 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 |
| 81 | chroot $CHROOTCACHE/natty-stack/ chown -R stack $2 |
| 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 $DASH_TAG |
| 89 | git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH |
| 90 | git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH |
Dean Troyer | cc80654 | 2011-10-03 09:30:57 -0500 | [diff] [blame] | 91 | |
Dean Troyer | 11e5e6f | 2011-10-03 09:40:32 -0500 | [diff] [blame^] | 92 | chroot $CHROOTCACHE/natty-stack mkdir -p $DEST/files |
| 93 | wget -c http://images.ansolabs.com/tty.tgz -O $CHROOTCACHE/natty-stack$DEST/files/tty.tgz |
Dean Troyer | cc80654 | 2011-10-03 09:30:57 -0500 | [diff] [blame] | 94 | |
| 95 | cp -pr $CHROOTCACHE/natty-stack $DEST |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 96 | |
| 97 | # set hostname |
| 98 | echo $NAME > $DEST/etc/hostname |
| 99 | echo "127.0.0.1 localhost $NAME" > $DEST/etc/hosts |
| 100 | |
| 101 | # copy kernel modules |
| 102 | cp -pr /lib/modules/`uname -r` $DEST/lib/modules |
| 103 | |
Jesse Andrews | 5f09820 | 2011-09-11 16:34:34 -0700 | [diff] [blame] | 104 | |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 105 | # copy openstack installer and requirement lists to a new directory. |
| 106 | mkdir -p $DEST/opt |
Jesse Andrews | 4d28218 | 2011-09-16 11:27:43 -0700 | [diff] [blame] | 107 | |
| 108 | # inject stack.sh and dependant files |
| 109 | cp -r files $DEST/opt/files |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 110 | cp stack.sh $DEST/opt/stack.sh |
Jesse Andrews | ba23cc7 | 2011-09-11 03:22:13 -0700 | [diff] [blame] | 111 | |
Jesse Andrews | 5f09820 | 2011-09-11 16:34:34 -0700 | [diff] [blame] | 112 | # injecting root's public ssh key if it exists |
| 113 | if [ -f /root/.ssh/id_rsa.pub ]; then |
| 114 | mkdir $DEST/root/.ssh |
| 115 | chmod 700 $DEST/root/.ssh |
| 116 | cp /root/.ssh/id_rsa.pub $DEST/root/.ssh/authorized_keys |
| 117 | fi |