Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | # exit on error to stop unexpected errors |
| 4 | set -o errexit |
| 5 | |
| 6 | # Make sure that we have the proper version of ubuntu |
| 7 | UBUNTU_VERSION=`cat /etc/lsb-release | grep CODENAME | sed 's/.*=//g'` |
| 8 | if [ ! "oneiric" = "$UBUNTU_VERSION" ]; then |
| 9 | if [ ! "natty" = "$UBUNTU_VERSION" ]; then |
| 10 | echo "This script only works with oneiric and natty" |
| 11 | exit 1 |
| 12 | fi |
| 13 | fi |
| 14 | |
| 15 | # Echo commands |
| 16 | set -o xtrace |
| 17 | |
| 18 | # Keep track of the current directory |
| 19 | TOOLS_DIR=$(cd $(dirname "$0") && pwd) |
Jesse Andrews | 3198974 | 2011-10-30 18:56:05 -0700 | [diff] [blame] | 20 | TOP_DIR=`cd $TOOLS_DIR/..; pwd` |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 21 | |
| 22 | # Where to store files and instances |
Jesse Andrews | b0559b2 | 2011-10-30 19:46:54 -0700 | [diff] [blame] | 23 | WORK_DIR=${WORK_DIR:-/opt/kvmstack} |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 24 | |
| 25 | # Where to store images |
| 26 | IMAGES_DIR=$WORK_DIR/images |
| 27 | |
| 28 | # Create images dir |
| 29 | mkdir -p $IMAGES_DIR |
| 30 | |
| 31 | # Abort if localrc is not set |
| 32 | if [ ! -e $TOP_DIR/localrc ]; then |
| 33 | echo "You must have a localrc with ALL necessary passwords defined before proceeding." |
| 34 | echo "See stack.sh for required passwords." |
| 35 | exit 1 |
| 36 | fi |
| 37 | |
Jesse Andrews | 7fa5613 | 2011-10-30 18:43:54 -0700 | [diff] [blame] | 38 | cd $TOP_DIR |
| 39 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 40 | # Source params |
| 41 | source ./stackrc |
| 42 | |
| 43 | # Configure the root password of the vm to be the same as ``ADMIN_PASSWORD`` |
| 44 | ROOT_PASSWORD=${ADMIN_PASSWORD:-password} |
| 45 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 46 | # Base image (natty by default) |
| 47 | DIST_NAME=${DIST_NAME:-natty} |
| 48 | IMAGE_FNAME=$DIST_NAME.raw |
| 49 | |
| 50 | # Name of our instance, used by libvirt |
| 51 | GUEST_NAME=${GUEST_NAME:-devstack} |
| 52 | |
| 53 | # Original version of built image |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 54 | BASE_IMAGE=$IMAGES_DIR/$DIST_NAME.raw |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 55 | |
| 56 | # Copy of base image, which we pre-install with tasty treats |
| 57 | VM_IMAGE=$IMAGES_DIR/$DIST_NAME.$GUEST_NAME.raw |
| 58 | |
| 59 | # Mop up after previous runs |
| 60 | virsh destroy $GUEST_NAME || true |
| 61 | |
| 62 | # Where this vm is stored |
| 63 | VM_DIR=$WORK_DIR/instances/$GUEST_NAME |
| 64 | |
| 65 | # Create vm dir |
| 66 | mkdir -p $VM_DIR |
| 67 | |
| 68 | # Mount point into copied base image |
| 69 | COPY_DIR=$VM_DIR/copy |
| 70 | mkdir -p $COPY_DIR |
| 71 | |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 72 | # Get the base image if it does not yet exist |
| 73 | if [ ! -e $BASE_IMAGE ]; then |
| 74 | $TOOLS_DIR/get_uec_image.sh -f raw -r 5000 $DIST_NAME $BASE_IMAGE |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 75 | fi |
| 76 | |
| 77 | # Create a copy of the base image |
| 78 | if [ ! -e $VM_IMAGE ]; then |
| 79 | cp -p $BASE_IMAGE $VM_IMAGE |
| 80 | fi |
| 81 | |
| 82 | # Unmount the copied base image |
| 83 | function unmount_images() { |
| 84 | # unmount the filesystem |
| 85 | while df | grep -q $COPY_DIR; do |
| 86 | umount $COPY_DIR || echo 'ok' |
| 87 | sleep 1 |
| 88 | done |
| 89 | } |
| 90 | |
| 91 | # Unmount from failed runs |
| 92 | unmount_images |
| 93 | |
| 94 | # Ctrl-c catcher |
| 95 | function kill_unmount() { |
| 96 | unmount_images |
| 97 | exit 1 |
| 98 | } |
| 99 | |
| 100 | # Install deps if needed |
| 101 | dpkg -l kvm libvirt-bin kpartx || apt-get install -y --force-yes kvm libvirt-bin kpartx |
| 102 | |
| 103 | # Let Ctrl-c kill tail and exit |
| 104 | trap kill_unmount SIGINT |
| 105 | |
| 106 | # Where Openstack code will live in image |
| 107 | DEST=${DEST:-/opt/stack} |
| 108 | |
| 109 | # Mount the file system |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 110 | # For some reason, UEC-based images want 255 heads * 63 sectors * 512 byte sectors = 8225280 |
| 111 | mount -t ext4 -o loop,offset=8225280 $VM_IMAGE $COPY_DIR |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 112 | |
| 113 | # git clone only if directory doesn't exist already. Since ``DEST`` might not |
| 114 | # be owned by the installation user, we create the directory and change the |
| 115 | # ownership to the proper user. |
| 116 | function git_clone { |
| 117 | if [ ! -d $2 ]; then |
| 118 | sudo mkdir $2 |
| 119 | sudo chown `whoami` $2 |
| 120 | git clone $1 $2 |
| 121 | cd $2 |
| 122 | # This checkout syntax works for both branches and tags |
| 123 | git checkout $3 |
| 124 | fi |
| 125 | } |
| 126 | |
| 127 | # Make sure that base requirements are installed |
| 128 | cp /etc/resolv.conf $COPY_DIR/etc/resolv.conf |
| 129 | chroot $COPY_DIR apt-get update |
| 130 | chroot $COPY_DIR apt-get install -y --force-yes `cat files/apts/* | cut -d\# -f1 | egrep -v "(rabbitmq|libvirt-bin|mysql-server)"` |
| 131 | chroot $COPY_DIR apt-get install -y --download-only rabbitmq-server libvirt-bin mysql-server |
| 132 | chroot $COPY_DIR pip install `cat files/pips/*` |
| 133 | |
| 134 | # Clean out code repos if directed to do so |
| 135 | if [ "$CLEAN" = "1" ]; then |
| 136 | rm -rf $COPY_DIR/$DEST |
| 137 | fi |
| 138 | |
| 139 | # Cache openstack code |
| 140 | mkdir -p $COPY_DIR/$DEST |
| 141 | git_clone $NOVA_REPO $COPY_DIR/$DEST/nova $NOVA_BRANCH |
| 142 | git_clone $GLANCE_REPO $COPY_DIR/$DEST/glance $GLANCE_BRANCH |
| 143 | git_clone $KEYSTONE_REPO $COPY_DIR/$DESTkeystone $KEYSTONE_BRANCH |
| 144 | git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH |
| 145 | git_clone $HORIZON_REPO $COPY_DIR/$DEST/horizon $HORIZON_BRANCH $HORIZON_TAG |
| 146 | git_clone $NOVACLIENT_REPO $COPY_DIR/$DEST/python-novaclient $NOVACLIENT_BRANCH |
| 147 | git_clone $OPENSTACKX_REPO $COPY_DIR/$DEST/openstackx $OPENSTACKX_BRANCH |
| 148 | git_clone $KEYSTONE_REPO $COPY_DIR/$DEST/keystone $KEYSTONE_BRANCH |
| 149 | git_clone $NOVNC_REPO $COPY_DIR/$DEST/noVNC $NOVNC_BRANCH |
| 150 | |
| 151 | # Back to devstack |
| 152 | cd $TOP_DIR |
| 153 | |
| 154 | # Unmount the filesystems |
| 155 | unmount_images |
| 156 | |
| 157 | # Network configuration variables |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 158 | GUEST_NETWORK=${GUEST_NETWORK:-1} |
| 159 | |
| 160 | GUEST_IP=${GUEST_IP:-192.168.$GUEST_NETWORK.50} |
| 161 | GUEST_CIDR=${GUEST_CIDR:-$GUEST_IP/24} |
| 162 | GUEST_NETMASK=${GUEST_NETMASK:-255.255.255.0} |
| 163 | GUEST_GATEWAY=${GUEST_GATEWAY:-192.168.$GUEST_NETWORK.1} |
| 164 | GUEST_MAC=${GUEST_MAC:-"02:16:3e:07:69:`printf '%02X' $GUEST_NETWORK`"} |
| 165 | GUEST_RAM=${GUEST_RAM:-1524288} |
| 166 | GUEST_CORES=${GUEST_CORES:-1} |
| 167 | |
| 168 | # libvirt.xml configuration |
| 169 | NET_XML=$VM_DIR/net.xml |
| 170 | cat > $NET_XML <<EOF |
| 171 | <network> |
| 172 | <name>devstack-$GUEST_NETWORK</name> |
| 173 | <bridge name="stackbr%d" /> |
| 174 | <forward/> |
| 175 | <ip address="$GUEST_GATEWAY" netmask="$GUEST_NETMASK" /> |
| 176 | </network> |
| 177 | EOF |
| 178 | |
| 179 | virsh net-destroy devstack-$GUEST_NETWORK || true |
| 180 | virsh net-create $VM_DIR/net.xml |
| 181 | |
| 182 | # libvirt.xml configuration |
| 183 | LIBVIRT_XML=$VM_DIR/libvirt.xml |
| 184 | cat > $LIBVIRT_XML <<EOF |
| 185 | <domain type='kvm'> |
| 186 | <name>$GUEST_NAME</name> |
| 187 | <memory>$GUEST_RAM</memory> |
| 188 | <os> |
| 189 | <type>hvm</type> |
| 190 | <bootmenu enable='yes'/> |
| 191 | </os> |
| 192 | <features> |
| 193 | <acpi/> |
| 194 | </features> |
| 195 | <vcpu>$GUEST_CORES</vcpu> |
| 196 | <devices> |
| 197 | <disk type='file'> |
| 198 | <driver type='qcow2'/> |
| 199 | <source file='$VM_DIR/disk'/> |
| 200 | <target dev='vda' bus='virtio'/> |
| 201 | </disk> |
| 202 | |
| 203 | <interface type='network'> |
| 204 | <source network='devstack-$GUEST_NETWORK'/> |
| 205 | </interface> |
| 206 | |
| 207 | <!-- The order is significant here. File must be defined first --> |
| 208 | <serial type="file"> |
| 209 | <source path='$VM_DIR/console.log'/> |
| 210 | <target port='1'/> |
| 211 | </serial> |
| 212 | |
| 213 | <console type='pty' tty='/dev/pts/2'> |
| 214 | <source path='/dev/pts/2'/> |
| 215 | <target port='0'/> |
| 216 | </console> |
| 217 | |
| 218 | <serial type='pty'> |
| 219 | <source path='/dev/pts/2'/> |
| 220 | <target port='0'/> |
| 221 | </serial> |
| 222 | |
| 223 | <graphics type='vnc' port='-1' autoport='yes' keymap='en-us' listen='0.0.0.0'/> |
| 224 | </devices> |
| 225 | </domain> |
| 226 | EOF |
| 227 | |
| 228 | # Mount point for instance fs |
| 229 | ROOTFS=$VM_DIR/root |
| 230 | mkdir -p $ROOTFS |
| 231 | |
| 232 | # Make sure we have nbd-ness |
| 233 | modprobe nbd max_part=63 |
| 234 | |
| 235 | # Which NBD device to use? |
| 236 | NBD=${NBD:-/dev/nbd5} |
| 237 | |
| 238 | # Clean up from previous runs |
| 239 | umount $ROOTFS || echo 'ok' |
| 240 | qemu-nbd -d $NBD || echo 'ok' |
| 241 | |
| 242 | # Clean up old runs |
| 243 | cd $VM_DIR |
| 244 | rm -f $VM_DIR/disk |
| 245 | |
| 246 | # Create our instance fs |
| 247 | qemu-img create -f qcow2 -b $VM_IMAGE disk |
| 248 | |
| 249 | # Connect our nbd and wait till it is mountable |
| 250 | qemu-nbd -c $NBD disk |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 251 | if ! timeout 60 sh -c "while ! [ -e ${NBD}p1 ]; do sleep 1; done"; then |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 252 | echo "Couldn't connect $NBD" |
| 253 | exit 1 |
| 254 | fi |
| 255 | |
| 256 | # Mount the instance |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 257 | mount ${NBD}p1 $ROOTFS |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 258 | |
| 259 | # Configure instance network |
| 260 | INTERFACES=$ROOTFS/etc/network/interfaces |
| 261 | cat > $INTERFACES <<EOF |
| 262 | auto lo |
| 263 | iface lo inet loopback |
| 264 | |
| 265 | auto eth0 |
| 266 | iface eth0 inet static |
| 267 | address $GUEST_IP |
| 268 | netmask $GUEST_NETMASK |
| 269 | gateway $GUEST_GATEWAY |
| 270 | EOF |
| 271 | |
| 272 | # User configuration for the instance |
| 273 | chroot $ROOTFS groupadd libvirtd || true |
| 274 | chroot $ROOTFS useradd stack -s /bin/bash -d $DEST -G libvirtd |
Jesse Andrews | 5f894cd | 2011-10-30 19:52:50 -0700 | [diff] [blame] | 275 | cp -pr $TOP_DIR $ROOTFS/$DEST/devstack |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 276 | echo "root:$ROOT_PASSWORD" | chroot $ROOTFS chpasswd |
| 277 | echo "stack:pass" | chroot $ROOTFS chpasswd |
| 278 | echo "stack ALL=(ALL) NOPASSWD: ALL" >> $ROOTFS/etc/sudoers |
| 279 | |
| 280 | # Gracefully cp only if source file/dir exists |
| 281 | function cp_it { |
| 282 | if [ -e $1 ] || [ -d $1 ]; then |
| 283 | cp -pRL $1 $2 |
| 284 | fi |
| 285 | } |
| 286 | |
| 287 | # Copy over your ssh keys and env if desired |
| 288 | COPYENV=${COPYENV:-1} |
| 289 | if [ "$COPYENV" = "1" ]; then |
| 290 | cp_it ~/.ssh $ROOTFS/$DEST/.ssh |
| 291 | cp_it ~/.ssh/id_rsa.pub $ROOTFS/$DEST/.ssh/authorized_keys |
| 292 | cp_it ~/.gitconfig $ROOTFS/$DEST/.gitconfig |
| 293 | cp_it ~/.vimrc $ROOTFS/$DEST/.vimrc |
| 294 | cp_it ~/.bashrc $ROOTFS/$DEST/.bashrc |
| 295 | fi |
| 296 | |
| 297 | # pre-cache uec images |
| 298 | for image_url in ${IMAGE_URLS//,/ }; do |
| 299 | IMAGE_FNAME=`basename "$image_url"` |
| 300 | if [ ! -f $IMAGES_DIR/$IMAGE_FNAME ]; then |
| 301 | wget -c $image_url -O $IMAGES_DIR/$IMAGE_FNAME |
| 302 | fi |
| 303 | cp $IMAGES_DIR/$IMAGE_FNAME $ROOTFS/$DEST/devstack/files |
| 304 | done |
| 305 | |
| 306 | # Configure the runner |
| 307 | RUN_SH=$ROOTFS/$DEST/run.sh |
| 308 | cat > $RUN_SH <<EOF |
| 309 | #!/usr/bin/env bash |
| 310 | |
| 311 | # Kill any existing screens |
| 312 | killall screen |
| 313 | |
| 314 | # Install and run stack.sh |
| 315 | sudo apt-get update |
| 316 | sudo apt-get -y --force-yes install git-core vim-nox sudo |
| 317 | if [ ! -d "$DEST/devstack" ]; then |
| 318 | git clone git://github.com/cloudbuilders/devstack.git $DEST/devstack |
| 319 | fi |
| 320 | cd $DEST/devstack && $STACKSH_PARAMS FORCE=yes ./stack.sh > /$DEST/run.sh.log |
| 321 | echo >> /$DEST/run.sh.log |
| 322 | echo >> /$DEST/run.sh.log |
| 323 | echo "All done! Time to start clicking." >> /$DEST/run.sh.log |
| 324 | cat $DEST/run.sh.log |
| 325 | EOF |
| 326 | chmod 755 $RUN_SH |
| 327 | |
| 328 | # Make runner launch on boot |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 329 | RC_LOCAL=$ROOTFS/etc/init.d/zlocal |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 330 | cat > $RC_LOCAL <<EOF |
| 331 | #!/bin/sh -e |
| 332 | # Reboot if this is our first run to enable console log on $DIST_NAME :( |
| 333 | if [ ! -e /root/firstlaunch ]; then |
| 334 | touch /root/firstlaunch |
| 335 | reboot -f |
| 336 | exit 0 |
| 337 | fi |
Jesse Andrews | ddcc36d | 2011-10-30 22:41:23 -0700 | [diff] [blame^] | 338 | # cloud-init overwrites the hostname with ubuntuhost |
| 339 | echo $GUEST_NAME > /etc/hostname |
| 340 | hostname $GUEST_NAME |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 341 | su -c "$DEST/run.sh" stack |
| 342 | EOF |
| 343 | chmod +x $RC_LOCAL |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 344 | chroot $ROOTFS sudo update-rc.d zlocal defaults 99 |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 345 | |
| 346 | # Make our ip address hostnames look nice at the command prompt |
| 347 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/$DEST/.bashrc |
| 348 | echo "export PS1='${debian_chroot:+($debian_chroot)}\\u@\\H:\\w\\$ '" >> $ROOTFS/etc/profile |
| 349 | |
| 350 | # Give stack ownership over $DEST so it may do the work needed |
| 351 | chroot $ROOTFS chown -R stack $DEST |
| 352 | |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 353 | # GRUB 2 wants to see /dev |
| 354 | mount -o bind /dev $ROOTFS/dev |
| 355 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 356 | # Change boot params so that we get a console log |
| 357 | sudo sed -e "s/quiet splash/splash console=ttyS0 console=ttyS1,19200n8/g" -i $ROOTFS/boot/grub/menu.lst |
| 358 | sudo sed -e "s/^hiddenmenu//g" -i $ROOTFS/boot/grub/menu.lst |
| 359 | |
| 360 | # Set the hostname |
| 361 | echo $GUEST_NAME > $ROOTFS/etc/hostname |
| 362 | |
| 363 | # We need the hostname to resolve for rabbit to launch |
| 364 | if ! grep -q $GUEST_NAME $ROOTFS/etc/hosts; then |
| 365 | echo "$GUEST_IP $GUEST_NAME" >> $ROOTFS/etc/hosts |
| 366 | fi |
| 367 | |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 368 | # Change boot params so that we get a console log |
| 369 | G_DEV_UUID=`blkid -t LABEL=cloudimg-rootfs -s UUID -o value | head -1` |
| 370 | sed -e "s/GRUB_TIMEOUT=.*$/GRUB_TIMEOUT=3/" -i $ROOTFS/etc/default/grub |
Jesse Andrews | 2c5201b | 2011-10-30 20:44:26 -0700 | [diff] [blame] | 371 | sed -e "s,GRUB_CMDLINE_LINUX_DEFAULT=.*$,GRUB_CMDLINE_LINUX_DEFAULT=\"console=ttyS0 console=tty0 ds=nocloud ubuntu-pass=pass\",g" -i $ROOTFS/etc/default/grub |
Jesse Andrews | 2b7d221 | 2011-10-30 19:37:56 -0700 | [diff] [blame] | 372 | sed -e 's/[#]*GRUB_TERMINAL=.*$/GRUB_TERMINAL="serial console"/' -i $ROOTFS/etc/default/grub |
| 373 | echo 'GRUB_SERIAL_COMMAND="serial --unit=0"' >>$ROOTFS/etc/default/grub |
| 374 | echo 'GRUB_DISABLE_OS_PROBER=true' >>$ROOTFS/etc/default/grub |
| 375 | echo "GRUB_DEVICE_UUID=$G_DEV_UUID" >>$ROOTFS/etc/default/grub |
| 376 | |
| 377 | chroot $ROOTFS update-grub |
| 378 | umount $ROOTFS/dev |
| 379 | |
| 380 | # Pre-generate ssh host keys and allow password login |
| 381 | chroot $ROOTFS dpkg-reconfigure openssh-server |
| 382 | sed -e 's/^PasswordAuthentication.*$/PasswordAuthentication yes/' -i $ROOTFS/etc/ssh/sshd_config |
| 383 | |
Jesse Andrews | e97a2e7 | 2011-10-30 18:37:49 -0700 | [diff] [blame] | 384 | # Unmount |
| 385 | umount $ROOTFS || echo 'ok' |
| 386 | qemu-nbd -d $NBD |
| 387 | |
| 388 | # Create the instance |
| 389 | cd $VM_DIR && virsh create libvirt.xml |
| 390 | |
| 391 | # Tail the console log till we are done |
| 392 | WAIT_TILL_LAUNCH=${WAIT_TILL_LAUNCH:-1} |
| 393 | if [ "$WAIT_TILL_LAUNCH" = "1" ]; then |
| 394 | # Done creating the container, let's tail the log |
| 395 | echo |
| 396 | echo "=============================================================" |
| 397 | echo " -- YAY! --" |
| 398 | echo "=============================================================" |
| 399 | echo |
| 400 | echo "We're done launching the vm, about to start tailing the" |
| 401 | echo "stack.sh log. It will take a second or two to start." |
| 402 | echo |
| 403 | echo "Just CTRL-C at any time to stop tailing." |
| 404 | |
| 405 | while [ ! -e "$VM_DIR/console.log" ]; do |
| 406 | sleep 1 |
| 407 | done |
| 408 | |
| 409 | tail -F $VM_DIR/console.log & |
| 410 | |
| 411 | TAIL_PID=$! |
| 412 | |
| 413 | function kill_tail() { |
| 414 | kill $TAIL_PID |
| 415 | exit 1 |
| 416 | } |
| 417 | |
| 418 | # Let Ctrl-c kill tail and exit |
| 419 | trap kill_tail SIGINT |
| 420 | |
| 421 | echo "Waiting stack.sh to finish..." |
| 422 | while ! cat $VM_DIR/console.log | grep -q 'All done' ; do |
| 423 | sleep 5 |
| 424 | done |
| 425 | |
| 426 | kill $TAIL_PID |
| 427 | |
| 428 | if grep -q "stack.sh failed" $VM_DIR/console.log; then |
| 429 | exit 1 |
| 430 | fi |
| 431 | echo "" |
| 432 | echo "Finished - Zip-a-dee Doo-dah!" |
| 433 | fi |