blob: 43b6decd9025645d076521b15f1186f0bc8fe0bd [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
10# Exit on errors
11set -o errexit
12# Echo commands
13set -o xtrace
14
15# This directory
16BASE_DIR=$(cd $(dirname "$0") && pwd)
17
18# For default setings see xenrc
19source $BASE_DIR/../xenrc
20
21# Get the params
22preseed_url=$1
23
24# Delete template or skip template creation as required
25previous_template=$(xe template-list name-label="$UBUNTU_INST_TEMPLATE_NAME" \
26 params=uuid --minimal)
27if [ -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
35fi
36
37# Get built-in template
38builtin_name="Debian Squeeze 6.0 (32-bit)"
39builtin_uuid=$(xe template-list name-label="$builtin_name" --minimal)
40if [[ -z $builtin_uuid ]]; then
41 echo "Cant find the Debian Squeeze 32bit template on your XenServer."
42 exit 1
43fi
44
45# Clone built-in template to create new template
46new_uuid=$(xe vm-clone uuid=$builtin_uuid \
47 new-name-label="$UBUNTU_INST_TEMPLATE_NAME")
Stef Tf993b232012-11-08 10:46:48 -050048disk_size=$(($OSDOMU_VDI_GB * 1024 * 1024 * 1024))
John Garbuttd8f1a872012-06-26 11:16:38 +010049
50# Some of these settings can be found in example preseed files
51# however these need to be answered before the netinstall
52# is ready to fetch the preseed file, and as such must be here
53# to get a fully automated install
54pvargs="-- quiet console=hvc0 partman/default_filesystem=ext3 \
55console-setup/ask_detect=false locale=${UBUNTU_INST_LOCALE} \
56keyboard-configuration/layoutcode=${UBUNTU_INST_KEYBOARD} \
57netcfg/choose_interface=${HOST_IP_IFACE} \
58netcfg/get_hostname=os netcfg/get_domain=os auto \
59url=${preseed_url}"
60
61if [ "$NETINSTALLIP" != "dhcp" ]; then
62 netcfgargs="netcfg/disable_autoconfig=true \
63netcfg/get_nameservers=${UBUNTU_INST_NAMESERVERS} \
64netcfg/get_ipaddress=${UBUNTU_INST_IP} \
65netcfg/get_netmask=${UBUNTU_INST_NETMASK} \
66netcfg/get_gateway=${UBUNTU_INST_GATEWAY} \
67netcfg/confirm_static=true"
68 pvargs="${pvargs} ${netcfgargs}"
69fi
70
71xe template-param-set uuid=$new_uuid \
72 other-config:install-methods=http \
73 other-config:install-repository="$UBUNTU_INST_REPOSITORY" \
74 PV-args="$pvargs" \
75 other-config:debian-release="$UBUNTU_INST_RELEASE" \
76 other-config:default_template=true \
Stef Tf993b232012-11-08 10:46:48 -050077 other-config:disks='<provision><disk device="0" size="'$disk_size'" sr="" bootable="true" type="system"/></provision>' \
John Garbuttd8f1a872012-06-26 11:16:38 +010078 other-config:install-arch="$UBUNTU_INST_ARCH"
79
80echo "Ubuntu template installed uuid:$new_uuid"