blob: f67547b0600f32b655220998ccfd53305aecfcb1 [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")
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
53pvargs="-- quiet console=hvc0 partman/default_filesystem=ext3 \
54console-setup/ask_detect=false locale=${UBUNTU_INST_LOCALE} \
55keyboard-configuration/layoutcode=${UBUNTU_INST_KEYBOARD} \
56netcfg/choose_interface=${HOST_IP_IFACE} \
57netcfg/get_hostname=os netcfg/get_domain=os auto \
58url=${preseed_url}"
59
60if [ "$NETINSTALLIP" != "dhcp" ]; then
61 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 \
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
78echo "Ubuntu template installed uuid:$new_uuid"