John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # This creates an Ubuntu Server 32bit or 64bit template |
| 4 | # on Xenserver 5.6.x, 6.0.x and 6.1.x |
| 5 | # The template does a net install only |
| 6 | # |
| 7 | # Based on a script by: David Markey <david.markey@citrix.com> |
| 8 | # |
| 9 | |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 10 | set -o errexit |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 11 | set -o nounset |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 12 | set -o xtrace |
| 13 | |
| 14 | # This directory |
| 15 | BASE_DIR=$(cd $(dirname "$0") && pwd) |
| 16 | |
Bob Ball | d06d455 | 2014-05-15 21:12:50 +0100 | [diff] [blame] | 17 | # Source the top level functions |
| 18 | source $BASE_DIR/../../../functions |
| 19 | |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 20 | # For default setings see xenrc |
| 21 | source $BASE_DIR/../xenrc |
| 22 | |
| 23 | # Get the params |
| 24 | preseed_url=$1 |
| 25 | |
| 26 | # Delete template or skip template creation as required |
| 27 | previous_template=$(xe template-list name-label="$UBUNTU_INST_TEMPLATE_NAME" \ |
| 28 | params=uuid --minimal) |
| 29 | if [ -n "$previous_template" ]; then |
| 30 | if $CLEAN_TEMPLATES; then |
| 31 | xe template-param-clear param-name=other-config uuid=$previous_template |
| 32 | xe template-uninstall template-uuid=$previous_template force=true |
| 33 | else |
| 34 | echo "Template $UBUNTU_INST_TEMPLATE_NAME already present" |
| 35 | exit 0 |
| 36 | fi |
| 37 | fi |
| 38 | |
| 39 | # Get built-in template |
| 40 | builtin_name="Debian Squeeze 6.0 (32-bit)" |
| 41 | builtin_uuid=$(xe template-list name-label="$builtin_name" --minimal) |
| 42 | if [[ -z $builtin_uuid ]]; then |
Joe Gordon | 4640026 | 2013-06-30 04:32:27 -0700 | [diff] [blame] | 43 | echo "Can't find the Debian Squeeze 32bit template on your XenServer." |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | # Clone built-in template to create new template |
| 48 | new_uuid=$(xe vm-clone uuid=$builtin_uuid \ |
| 49 | new-name-label="$UBUNTU_INST_TEMPLATE_NAME") |
Stef T | f993b23 | 2012-11-08 10:46:48 -0500 | [diff] [blame] | 50 | disk_size=$(($OSDOMU_VDI_GB * 1024 * 1024 * 1024)) |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 51 | |
| 52 | # Some of these settings can be found in example preseed files |
| 53 | # however these need to be answered before the netinstall |
| 54 | # is ready to fetch the preseed file, and as such must be here |
| 55 | # to get a fully automated install |
| 56 | pvargs="-- quiet console=hvc0 partman/default_filesystem=ext3 \ |
| 57 | console-setup/ask_detect=false locale=${UBUNTU_INST_LOCALE} \ |
| 58 | keyboard-configuration/layoutcode=${UBUNTU_INST_KEYBOARD} \ |
Mate Lakat | 2f524bd | 2013-06-19 12:32:23 +0100 | [diff] [blame] | 59 | netcfg/choose_interface=eth0 \ |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 60 | netcfg/get_hostname=os netcfg/get_domain=os auto \ |
| 61 | url=${preseed_url}" |
| 62 | |
Mate Lakat | 0b3804b | 2013-05-07 16:58:17 +0100 | [diff] [blame] | 63 | if [ "$UBUNTU_INST_IP" != "dhcp" ]; then |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 64 | netcfgargs="netcfg/disable_autoconfig=true \ |
| 65 | netcfg/get_nameservers=${UBUNTU_INST_NAMESERVERS} \ |
| 66 | netcfg/get_ipaddress=${UBUNTU_INST_IP} \ |
| 67 | netcfg/get_netmask=${UBUNTU_INST_NETMASK} \ |
| 68 | netcfg/get_gateway=${UBUNTU_INST_GATEWAY} \ |
| 69 | netcfg/confirm_static=true" |
| 70 | pvargs="${pvargs} ${netcfgargs}" |
| 71 | fi |
| 72 | |
| 73 | xe template-param-set uuid=$new_uuid \ |
| 74 | other-config:install-methods=http \ |
Mate Lakat | d3740f7 | 2013-05-09 15:02:21 +0100 | [diff] [blame] | 75 | other-config:install-repository="http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY}" \ |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 76 | PV-args="$pvargs" \ |
| 77 | other-config:debian-release="$UBUNTU_INST_RELEASE" \ |
| 78 | other-config:default_template=true \ |
Stef T | f993b23 | 2012-11-08 10:46:48 -0500 | [diff] [blame] | 79 | other-config:disks='<provision><disk device="0" size="'$disk_size'" sr="" bootable="true" type="system"/></provision>' \ |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 80 | other-config:install-arch="$UBUNTU_INST_ARCH" |
| 81 | |
Mate Lakat | d3740f7 | 2013-05-09 15:02:21 +0100 | [diff] [blame] | 82 | if ! [ -z "$UBUNTU_INST_HTTP_PROXY" ]; then |
| 83 | xe template-param-set uuid=$new_uuid \ |
| 84 | other-config:install-proxy="$UBUNTU_INST_HTTP_PROXY" |
| 85 | fi |
| 86 | |
John Garbutt | d8f1a87 | 2012-06-26 11:16:38 +0100 | [diff] [blame] | 87 | echo "Ubuntu template installed uuid:$new_uuid" |