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