blob: b7a8eff9527e14258922a81b63adc124cecc4460 [file] [log] [blame]
John Garbuttd8f1a872012-06-26 11:16:38 +01001#!/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 Garbuttd8f1a872012-06-26 11:16:38 +010010set -o errexit
Mate Lakat0b3804b2013-05-07 16:58:17 +010011set -o nounset
John Garbuttd8f1a872012-06-26 11:16:38 +010012set -o xtrace
13
14# This directory
15BASE_DIR=$(cd $(dirname "$0") && pwd)
16
17# For default setings see xenrc
18source $BASE_DIR/../xenrc
19
20# Get the params
21preseed_url=$1
22
23# Delete template or skip template creation as required
24previous_template=$(xe template-list name-label="$UBUNTU_INST_TEMPLATE_NAME" \
25 params=uuid --minimal)
26if [ -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
34fi
35
36# Get built-in template
37builtin_name="Debian Squeeze 6.0 (32-bit)"
38builtin_uuid=$(xe template-list name-label="$builtin_name" --minimal)
39if [[ -z $builtin_uuid ]]; then
40 echo "Cant find the Debian Squeeze 32bit template on your XenServer."
41 exit 1
42fi
43
44# Clone built-in template to create new template
45new_uuid=$(xe vm-clone uuid=$builtin_uuid \
46 new-name-label="$UBUNTU_INST_TEMPLATE_NAME")
Stef Tf993b232012-11-08 10:46:48 -050047disk_size=$(($OSDOMU_VDI_GB * 1024 * 1024 * 1024))
John Garbuttd8f1a872012-06-26 11:16:38 +010048
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
53pvargs="-- quiet console=hvc0 partman/default_filesystem=ext3 \
54console-setup/ask_detect=false locale=${UBUNTU_INST_LOCALE} \
55keyboard-configuration/layoutcode=${UBUNTU_INST_KEYBOARD} \
Mate Lakat0b3804b2013-05-07 16:58:17 +010056netcfg/choose_interface=${UBUNTU_INST_IFACE} \
John Garbuttd8f1a872012-06-26 11:16:38 +010057netcfg/get_hostname=os netcfg/get_domain=os auto \
58url=${preseed_url}"
59
Mate Lakat0b3804b2013-05-07 16:58:17 +010060if [ "$UBUNTU_INST_IP" != "dhcp" ]; then
John Garbuttd8f1a872012-06-26 11:16:38 +010061 netcfgargs="netcfg/disable_autoconfig=true \
62netcfg/get_nameservers=${UBUNTU_INST_NAMESERVERS} \
63netcfg/get_ipaddress=${UBUNTU_INST_IP} \
64netcfg/get_netmask=${UBUNTU_INST_NETMASK} \
65netcfg/get_gateway=${UBUNTU_INST_GATEWAY} \
66netcfg/confirm_static=true"
67 pvargs="${pvargs} ${netcfgargs}"
68fi
69
70xe template-param-set uuid=$new_uuid \
71 other-config:install-methods=http \
Mate Lakatd3740f72013-05-09 15:02:21 +010072 other-config:install-repository="http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY}" \
John Garbuttd8f1a872012-06-26 11:16:38 +010073 PV-args="$pvargs" \
74 other-config:debian-release="$UBUNTU_INST_RELEASE" \
75 other-config:default_template=true \
Stef Tf993b232012-11-08 10:46:48 -050076 other-config:disks='<provision><disk device="0" size="'$disk_size'" sr="" bootable="true" type="system"/></provision>' \
John Garbuttd8f1a872012-06-26 11:16:38 +010077 other-config:install-arch="$UBUNTU_INST_ARCH"
78
Mate Lakatd3740f72013-05-09 15:02:21 +010079if ! [ -z "$UBUNTU_INST_HTTP_PROXY" ]; then
80 xe template-param-set uuid=$new_uuid \
81 other-config:install-proxy="$UBUNTU_INST_HTTP_PROXY"
82fi
83
John Garbuttd8f1a872012-06-26 11:16:38 +010084echo "Ubuntu template installed uuid:$new_uuid"