| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 1 | #!/usr/bin/env bash | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 2 |  | 
| Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 3 | # **build_uec_ramdisk.sh** | 
 | 4 |  | 
 | 5 | # Build RAM disk images based on UEC image | 
 | 6 |  | 
 | 7 | # Exit on error to stop unexpected errors | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 8 | set -o errexit | 
 | 9 |  | 
 | 10 | if [ ! "$#" -eq "1" ]; then | 
 | 11 |     echo "$0 builds a gziped Ubuntu OpenStack install" | 
 | 12 |     echo "usage: $0 dest" | 
 | 13 |     exit 1 | 
 | 14 | fi | 
 | 15 |  | 
 | 16 | # Make sure that we have the proper version of ubuntu (only works on oneiric) | 
 | 17 | if ! egrep -q "oneiric" /etc/lsb-release; then | 
 | 18 |     echo "This script only works with ubuntu oneiric." | 
 | 19 |     exit 1 | 
 | 20 | fi | 
 | 21 |  | 
 | 22 | # Clean up resources that may be in use | 
| Ian Wienand | aee18c7 | 2014-02-21 15:35:08 +1100 | [diff] [blame] | 23 | function cleanup { | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 24 |     set +o errexit | 
 | 25 |  | 
 | 26 |     if [ -n "$MNT_DIR" ]; then | 
 | 27 |         umount $MNT_DIR/dev | 
 | 28 |         umount $MNT_DIR | 
 | 29 |     fi | 
 | 30 |  | 
 | 31 |     if [ -n "$DEST_FILE_TMP" ]; then | 
 | 32 |         rm $DEST_FILE_TMP | 
 | 33 |     fi | 
 | 34 |  | 
 | 35 |     # Kill ourselves to signal parents | 
 | 36 |     trap 2; kill -2 $$ | 
 | 37 | } | 
 | 38 |  | 
 | 39 | trap cleanup SIGHUP SIGINT SIGTERM SIGQUIT EXIT | 
 | 40 |  | 
 | 41 | # Output dest image | 
 | 42 | DEST_FILE=$1 | 
 | 43 |  | 
 | 44 | # Keep track of the current directory | 
 | 45 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 46 | TOP_DIR=$(cd $TOOLS_DIR/..; pwd) | 
 | 47 |  | 
 | 48 | # Import common functions | 
 | 49 | . $TOP_DIR/functions | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 50 |  | 
 | 51 | cd $TOP_DIR | 
 | 52 |  | 
 | 53 | # Source params | 
 | 54 | source ./stackrc | 
 | 55 |  | 
 | 56 | DEST=${DEST:-/opt/stack} | 
 | 57 |  | 
 | 58 | # Ubuntu distro to install | 
 | 59 | DIST_NAME=${DIST_NAME:-oneiric} | 
 | 60 |  | 
 | 61 | # Configure how large the VM should be | 
 | 62 | GUEST_SIZE=${GUEST_SIZE:-2G} | 
 | 63 |  | 
| Dean Troyer | e62ba4d | 2012-06-27 22:07:34 -0500 | [diff] [blame] | 64 | # Exit on error to stop unexpected errors | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 65 | set -o errexit | 
 | 66 | set -o xtrace | 
 | 67 |  | 
 | 68 | # Abort if localrc is not set | 
 | 69 | if [ ! -e $TOP_DIR/localrc ]; then | 
 | 70 |     echo "You must have a localrc with ALL necessary passwords defined before proceeding." | 
 | 71 |     echo "See stack.sh for required passwords." | 
 | 72 |     exit 1 | 
 | 73 | fi | 
 | 74 |  | 
 | 75 | # Install deps if needed | 
 | 76 | DEPS="kvm libvirt-bin kpartx cloud-utils curl" | 
| Dean Troyer | 7f9aa71 | 2012-01-31 12:11:56 -0600 | [diff] [blame] | 77 | apt_get install -y --force-yes $DEPS | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 78 |  | 
 | 79 | # Where to store files and instances | 
 | 80 | CACHEDIR=${CACHEDIR:-/opt/stack/cache} | 
 | 81 | WORK_DIR=${WORK_DIR:-/opt/ramstack} | 
 | 82 |  | 
 | 83 | # Where to store images | 
 | 84 | image_dir=$WORK_DIR/images/$DIST_NAME | 
 | 85 | mkdir -p $image_dir | 
 | 86 |  | 
 | 87 | # Get the base image if it does not yet exist | 
 | 88 | if [ ! -e $image_dir/disk ]; then | 
 | 89 |     $TOOLS_DIR/get_uec_image.sh -r 2000M $DIST_NAME $image_dir/disk | 
 | 90 | fi | 
 | 91 |  | 
 | 92 | # Configure the root password of the vm to be the same as ``ADMIN_PASSWORD`` | 
 | 93 | ROOT_PASSWORD=${ADMIN_PASSWORD:-password} | 
 | 94 |  | 
 | 95 | # Name of our instance, used by libvirt | 
 | 96 | GUEST_NAME=${GUEST_NAME:-devstack} | 
 | 97 |  | 
 | 98 | # Pre-load the image with basic environment | 
 | 99 | if [ ! -e $image_dir/disk-primed ]; then | 
 | 100 |     cp $image_dir/disk $image_dir/disk-primed | 
| Vincent Untz | 7c3053d | 2012-11-29 09:19:16 +0100 | [diff] [blame] | 101 |     $TOOLS_DIR/warm_apts_for_uec.sh $image_dir/disk-primed | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 102 |     $TOOLS_DIR/copy_dev_environment_to_uec.sh $image_dir/disk-primed | 
 | 103 | fi | 
 | 104 |  | 
 | 105 | # Back to devstack | 
 | 106 | cd $TOP_DIR | 
 | 107 |  | 
 | 108 | DEST_FILE_TMP=`mktemp $DEST_FILE.XXXXXX` | 
 | 109 | MNT_DIR=`mktemp -d --tmpdir mntXXXXXXXX` | 
 | 110 | cp $image_dir/disk-primed $DEST_FILE_TMP | 
 | 111 | mount -t ext4 -o loop $DEST_FILE_TMP $MNT_DIR | 
 | 112 | mount -o bind /dev /$MNT_DIR/dev | 
 | 113 | cp -p /etc/resolv.conf $MNT_DIR/etc/resolv.conf | 
 | 114 | echo root:$ROOT_PASSWORD | chroot $MNT_DIR chpasswd | 
 | 115 | touch $MNT_DIR/$DEST/.ramdisk | 
 | 116 |  | 
 | 117 | # We need to install a non-virtual kernel and modules to boot from | 
 | 118 | if [ ! -r "`ls $MNT_DIR/boot/vmlinuz-*-generic | head -1`" ]; then | 
 | 119 |     chroot $MNT_DIR apt-get install -y linux-generic | 
 | 120 | fi | 
 | 121 |  | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 122 | git_clone $NOVA_REPO $DEST/nova $NOVA_BRANCH | 
 | 123 | git_clone $GLANCE_REPO $DEST/glance $GLANCE_BRANCH | 
 | 124 | git_clone $KEYSTONE_REPO $DEST/keystone $KEYSTONE_BRANCH | 
 | 125 | git_clone $NOVNC_REPO $DEST/novnc $NOVNC_BRANCH | 
 | 126 | git_clone $HORIZON_REPO $DEST/horizon $HORIZON_BRANCH | 
 | 127 | git_clone $NOVACLIENT_REPO $DEST/python-novaclient $NOVACLIENT_BRANCH | 
 | 128 | git_clone $OPENSTACKX_REPO $DEST/openstackx $OPENSTACKX_BRANCH | 
| Dean Troyer | 608bb12 | 2012-01-10 14:43:17 -0600 | [diff] [blame] | 129 | git_clone $TEMPEST_REPO $DEST/tempest $TEMPEST_BRANCH | 
| Jesse Andrews | d7326d2 | 2011-11-20 10:02:26 -0800 | [diff] [blame] | 130 |  | 
 | 131 | # Use this version of devstack | 
 | 132 | rm -rf $MNT_DIR/$DEST/devstack | 
 | 133 | cp -pr $TOP_DIR $MNT_DIR/$DEST/devstack | 
 | 134 | chroot $MNT_DIR chown -R stack $DEST/devstack | 
 | 135 |  | 
 | 136 | # Configure host network for DHCP | 
 | 137 | mkdir -p $MNT_DIR/etc/network | 
 | 138 | cat > $MNT_DIR/etc/network/interfaces <<EOF | 
 | 139 | auto lo | 
 | 140 | iface lo inet loopback | 
 | 141 |  | 
 | 142 | auto eth0 | 
 | 143 | iface eth0 inet dhcp | 
 | 144 | EOF | 
 | 145 |  | 
 | 146 | # Set hostname | 
 | 147 | echo "ramstack" >$MNT_DIR/etc/hostname | 
 | 148 | echo "127.0.0.1		localhost	ramstack" >$MNT_DIR/etc/hosts | 
 | 149 |  | 
 | 150 | # Configure the runner | 
 | 151 | RUN_SH=$MNT_DIR/$DEST/run.sh | 
 | 152 | cat > $RUN_SH <<EOF | 
 | 153 | #!/usr/bin/env bash | 
 | 154 |  | 
 | 155 | # Get IP range | 
 | 156 | set \`ip addr show dev eth0 | grep inet\` | 
 | 157 | PREFIX=\`echo \$2 | cut -d. -f1,2,3\` | 
 | 158 | export FLOATING_RANGE="\$PREFIX.224/27" | 
 | 159 |  | 
 | 160 | # Kill any existing screens | 
 | 161 | killall screen | 
 | 162 |  | 
 | 163 | # Run stack.sh | 
 | 164 | cd $DEST/devstack && \$STACKSH_PARAMS ./stack.sh > $DEST/run.sh.log | 
 | 165 | echo >> $DEST/run.sh.log | 
 | 166 | echo >> $DEST/run.sh.log | 
 | 167 | echo "All done! Time to start clicking." >> $DEST/run.sh.log | 
 | 168 | EOF | 
 | 169 |  | 
 | 170 | # Make the run.sh executable | 
 | 171 | chmod 755 $RUN_SH | 
 | 172 | chroot $MNT_DIR chown stack $DEST/run.sh | 
 | 173 |  | 
 | 174 | umount $MNT_DIR/dev | 
 | 175 | umount $MNT_DIR | 
 | 176 | rmdir $MNT_DIR | 
 | 177 | mv $DEST_FILE_TMP $DEST_FILE | 
 | 178 | rm -f $DEST_FILE_TMP | 
 | 179 |  | 
 | 180 | trap - SIGHUP SIGINT SIGTERM SIGQUIT EXIT |