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 | |
| 10 | # Exit on errors |
| 11 | set -o errexit |
| 12 | # Echo commands |
| 13 | set -o xtrace |
| 14 | |
| 15 | # This directory |
| 16 | BASE_DIR=$(cd $(dirname "$0") && pwd) |
| 17 | |
| 18 | # For default setings see xenrc |
| 19 | source $BASE_DIR/../xenrc |
| 20 | |
| 21 | # Get the params |
| 22 | preseed_url=$1 |
| 23 | |
| 24 | # Delete template or skip template creation as required |
| 25 | previous_template=$(xe template-list name-label="$UBUNTU_INST_TEMPLATE_NAME" \ |
| 26 | params=uuid --minimal) |
| 27 | if [ -n "$previous_template" ]; then |
| 28 | if $CLEAN_TEMPLATES; then |
| 29 | xe template-param-clear param-name=other-config uuid=$previous_template |
| 30 | xe template-uninstall template-uuid=$previous_template force=true |
| 31 | else |
| 32 | echo "Template $UBUNTU_INST_TEMPLATE_NAME already present" |
| 33 | exit 0 |
| 34 | fi |
| 35 | fi |
| 36 | |
| 37 | # Get built-in template |
| 38 | builtin_name="Debian Squeeze 6.0 (32-bit)" |
| 39 | builtin_uuid=$(xe template-list name-label="$builtin_name" --minimal) |
| 40 | if [[ -z $builtin_uuid ]]; then |
| 41 | echo "Cant find the Debian Squeeze 32bit template on your XenServer." |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | # Clone built-in template to create new template |
| 46 | new_uuid=$(xe vm-clone uuid=$builtin_uuid \ |
| 47 | new-name-label="$UBUNTU_INST_TEMPLATE_NAME") |
| 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} \ |
| 56 | netcfg/choose_interface=${HOST_IP_IFACE} \ |
| 57 | netcfg/get_hostname=os netcfg/get_domain=os auto \ |
| 58 | url=${preseed_url}" |
| 59 | |
| 60 | if [ "$NETINSTALLIP" != "dhcp" ]; then |
| 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 \ |
| 72 | other-config:install-repository="$UBUNTU_INST_REPOSITORY" \ |
| 73 | PV-args="$pvargs" \ |
| 74 | other-config:debian-release="$UBUNTU_INST_RELEASE" \ |
| 75 | other-config:default_template=true \ |
| 76 | other-config:install-arch="$UBUNTU_INST_ARCH" |
| 77 | |
| 78 | echo "Ubuntu template installed uuid:$new_uuid" |