| 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 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 18 | set -o errexit | 
| Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 19 | set -o nounset | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 20 | set -o xtrace | 
|  | 21 |  | 
|  | 22 | # This directory | 
|  | 23 | TOP_DIR=$(cd $(dirname "$0") && pwd) | 
|  | 24 |  | 
| Bob Ball | c643ebb | 2014-02-02 09:16:20 +0000 | [diff] [blame] | 25 | # Source lower level functions | 
|  | 26 | . $TOP_DIR/../../functions | 
|  | 27 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 28 | # Include onexit commands | 
|  | 29 | . $TOP_DIR/scripts/on_exit.sh | 
|  | 30 |  | 
| Bob Ball | c643ebb | 2014-02-02 09:16:20 +0000 | [diff] [blame] | 31 | # xapi functions | 
|  | 32 | . $TOP_DIR/functions | 
|  | 33 |  | 
|  | 34 | # Determine what system we are running on. | 
|  | 35 | # Might not be XenServer if we're using xenserver-core | 
|  | 36 | GetDistro | 
|  | 37 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 38 | # Source params - override xenrc params in your localrc to suite your taste | 
|  | 39 | source xenrc | 
|  | 40 |  | 
|  | 41 | # | 
|  | 42 | # Parameters | 
|  | 43 | # | 
|  | 44 | GUEST_NAME="$1" | 
|  | 45 |  | 
|  | 46 | # Mount the VDI | 
|  | 47 | STAGING_DIR=$($TOP_DIR/scripts/manage-vdi open $GUEST_NAME 0 1 | grep -o "/tmp/tmp.[[:alnum:]]*") | 
|  | 48 | add_on_exit "$TOP_DIR/scripts/manage-vdi close $GUEST_NAME 0 1" | 
|  | 49 |  | 
|  | 50 | # Make sure we have a stage | 
|  | 51 | if [ ! -d $STAGING_DIR/etc ]; then | 
|  | 52 | echo "Stage is not properly set up!" | 
|  | 53 | exit 1 | 
|  | 54 | fi | 
|  | 55 |  | 
| John Garbutt | b6c8714 | 2012-08-02 12:34:03 +0100 | [diff] [blame] | 56 | # Copy XenServer tools deb into the VM | 
|  | 57 | ISO_DIR="/opt/xensource/packages/iso" | 
|  | 58 | XS_TOOLS_FILE_NAME="xs-tools.deb" | 
|  | 59 | XS_TOOLS_PATH="/root/$XS_TOOLS_FILE_NAME" | 
|  | 60 | if [ -e "$ISO_DIR" ]; then | 
| Andrew Melton | 98ab500 | 2012-09-06 15:18:11 -0400 | [diff] [blame] | 61 | TOOLS_ISO=$(ls -1 $ISO_DIR/xs-tools-*.iso | head -1) | 
| John Garbutt | b6c8714 | 2012-08-02 12:34:03 +0100 | [diff] [blame] | 62 | TMP_DIR=/tmp/temp.$RANDOM | 
|  | 63 | mkdir -p $TMP_DIR | 
|  | 64 | mount -o loop $TOOLS_ISO $TMP_DIR | 
|  | 65 | DEB_FILE=$(ls $TMP_DIR/Linux/*amd64.deb) | 
|  | 66 | echo "Copying XenServer tools into VM from: $DEB_FILE" | 
|  | 67 | cp $DEB_FILE "${STAGING_DIR}${XS_TOOLS_PATH}" | 
|  | 68 | umount $TMP_DIR | 
|  | 69 | rm -rf $TMP_DIR | 
|  | 70 | else | 
|  | 71 | echo "WARNING: no XenServer tools found, falling back to 5.6 tools" | 
| Mate Lakat | da33982 | 2012-11-14 12:45:10 +0000 | [diff] [blame] | 72 | TOOLS_URL="https://github.com/downloads/citrix-openstack/warehouse/xe-guest-utilities_5.6.100-651_amd64.deb" | 
| Bob Ball | 8230296 | 2014-06-24 11:15:50 +0100 | [diff] [blame] | 73 | curl --no-sessionid -L -o "$XS_TOOLS_FILE_NAME" $TOOLS_URL | 
| John Garbutt | b6c8714 | 2012-08-02 12:34:03 +0100 | [diff] [blame] | 74 | cp $XS_TOOLS_FILE_NAME "${STAGING_DIR}${XS_TOOLS_PATH}" | 
|  | 75 | rm -rf $XS_TOOLS_FILE_NAME | 
|  | 76 | fi | 
|  | 77 |  | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 78 | # Copy prepare_guest.sh to VM | 
|  | 79 | mkdir -p $STAGING_DIR/opt/stack/ | 
|  | 80 | cp $TOP_DIR/prepare_guest.sh $STAGING_DIR/opt/stack/prepare_guest.sh | 
|  | 81 |  | 
|  | 82 | # backup rc.local | 
|  | 83 | cp $STAGING_DIR/etc/rc.local $STAGING_DIR/etc/rc.local.preparebackup | 
|  | 84 |  | 
|  | 85 | # run prepare_guest.sh on boot | 
|  | 86 | cat <<EOF >$STAGING_DIR/etc/rc.local | 
| Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 87 | #!/bin/sh -e | 
|  | 88 | bash /opt/stack/prepare_guest.sh \\ | 
| Mate Lakat | d15c8a0 | 2014-02-04 12:38:14 +0000 | [diff] [blame] | 89 | "$GUEST_PASSWORD" "$XS_TOOLS_PATH" "$STACK_USER" "$DOMZERO_USER" \\ | 
| Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 90 | > /opt/stack/prepare_guest.log 2>&1 | 
| John Garbutt | daadf74 | 2012-04-27 18:28:28 +0100 | [diff] [blame] | 91 | EOF | 
| Bob Ball | 60fcfb5 | 2013-12-23 17:23:47 +0000 | [diff] [blame] | 92 |  | 
|  | 93 | # Need to set barrier=0 to avoid a Xen bug | 
|  | 94 | # https://bugs.launchpad.net/ubuntu/+source/linux/+bug/824089 | 
|  | 95 | sed -i -e 's/errors=/barrier=0,errors=/' $STAGING_DIR/etc/fstab |