| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 1 | #!/bin/bash | 
 | 2 |  | 
 | 3 | # This script is run by install_os_domU.sh | 
 | 4 | # | 
 | 5 | # Parameters: | 
 | 6 | # - $GUEST_NAME - hostname for the DomU VM | 
 | 7 | # | 
 | 8 | # It modifies the ubuntu image created by install_os_domU.sh | 
 | 9 | # | 
 | 10 | # This script is responsible for cusomtizing the fresh ubuntu | 
 | 11 | # image so on boot it runs the prepare_guest.sh script | 
 | 12 | # that modifies the VM so it is ready to run stack.sh. | 
 | 13 | # It does this by mounting the disk image of the VM. | 
 | 14 | # | 
 | 15 | # The resultant image is started by install_os_domU.sh, | 
 | 16 | # and once the VM has shutdown, build_xva.sh is run | 
 | 17 |  | 
 | 18 | # Exit on errors | 
 | 19 | set -o errexit | 
 | 20 | # Echo commands | 
 | 21 | set -o xtrace | 
 | 22 |  | 
 | 23 | # This directory | 
 | 24 | TOP_DIR=$(cd $(dirname "$0") && pwd) | 
 | 25 |  | 
 | 26 | # Include onexit commands | 
 | 27 | . $TOP_DIR/scripts/on_exit.sh | 
 | 28 |  | 
 | 29 | # Source params - override xenrc params in your localrc to suite your taste | 
 | 30 | source xenrc | 
 | 31 |  | 
 | 32 | # | 
 | 33 | # Parameters | 
 | 34 | # | 
 | 35 | GUEST_NAME="$1" | 
 | 36 |  | 
 | 37 | # Mount the VDI | 
 | 38 | STAGING_DIR=$($TOP_DIR/scripts/manage-vdi open $GUEST_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*") | 
 | 39 | add_on_exit "$TOP_DIR/scripts/manage-vdi close $GUEST_NAME 0 1" | 
 | 40 |  | 
 | 41 | # Make sure we have a stage | 
 | 42 | if [ ! -d $STAGING_DIR/etc ]; then | 
 | 43 |     echo "Stage is not properly set up!" | 
 | 44 |     exit 1 | 
 | 45 | fi | 
 | 46 |  | 
| John Garbutt | b6c8714 | 2012-08-02 12:34:03 +0100 | [diff] [blame] | 47 | # Copy XenServer tools deb into the VM | 
 | 48 | ISO_DIR="/opt/xensource/packages/iso" | 
 | 49 | XS_TOOLS_FILE_NAME="xs-tools.deb" | 
 | 50 | XS_TOOLS_PATH="/root/$XS_TOOLS_FILE_NAME" | 
 | 51 | if [ -e "$ISO_DIR" ]; then | 
 | 52 |     TOOLS_ISO=$(ls $ISO_DIR/xs-tools-*.iso) | 
 | 53 |     TMP_DIR=/tmp/temp.$RANDOM | 
 | 54 |     mkdir -p $TMP_DIR | 
 | 55 |     mount -o loop $TOOLS_ISO $TMP_DIR | 
 | 56 |     DEB_FILE=$(ls $TMP_DIR/Linux/*amd64.deb) | 
 | 57 |     echo "Copying XenServer tools into VM from: $DEB_FILE" | 
 | 58 |     cp $DEB_FILE "${STAGING_DIR}${XS_TOOLS_PATH}" | 
 | 59 |     umount $TMP_DIR | 
 | 60 |     rm -rf $TMP_DIR | 
 | 61 | else | 
 | 62 |     echo "WARNING: no XenServer tools found, falling back to 5.6 tools" | 
 | 63 |     TOOLS_URL="http://images.ansolabs.com/xen/xe-guest-utilities_5.6.100-651_amd64.deb" | 
 | 64 |     wget $TOOLS_URL -O $XS_TOOLS_FILE_NAME | 
 | 65 |     cp $XS_TOOLS_FILE_NAME "${STAGING_DIR}${XS_TOOLS_PATH}" | 
 | 66 |     rm -rf $XS_TOOLS_FILE_NAME | 
 | 67 | fi | 
 | 68 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 69 | # Copy prepare_guest.sh to VM | 
 | 70 | mkdir -p $STAGING_DIR/opt/stack/ | 
 | 71 | cp $TOP_DIR/prepare_guest.sh $STAGING_DIR/opt/stack/prepare_guest.sh | 
 | 72 |  | 
 | 73 | # backup rc.local | 
 | 74 | cp $STAGING_DIR/etc/rc.local $STAGING_DIR/etc/rc.local.preparebackup | 
 | 75 |  | 
 | 76 | # run prepare_guest.sh on boot | 
 | 77 | cat <<EOF >$STAGING_DIR/etc/rc.local | 
| John Garbutt | b6c8714 | 2012-08-02 12:34:03 +0100 | [diff] [blame] | 78 | GUEST_PASSWORD=$GUEST_PASSWORD STAGING_DIR=/ \ | 
 | 79 |     DO_TGZ=0 XS_TOOLS_PATH=$XS_TOOLS_PATH \ | 
 | 80 |     bash /opt/stack/prepare_guest.sh > /opt/stack/prepare_guest.log 2>&1 | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 81 | EOF |