blob: d4d6567a406bd2538fb3bfb9517fbdb019be82e3 [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
Bob Balld06d4552014-05-15 21:12:50 +010017# Source the top level functions
18source $BASE_DIR/../../../functions
19
John Garbuttd8f1a872012-06-26 11:16:38 +010020# For default setings see xenrc
21source $BASE_DIR/../xenrc
22
23# Get the params
24preseed_url=$1
25
26# Delete template or skip template creation as required
27previous_template=$(xe template-list name-label="$UBUNTU_INST_TEMPLATE_NAME" \
28 params=uuid --minimal)
29if [ -n "$previous_template" ]; then
30 if $CLEAN_TEMPLATES; then
31 xe template-param-clear param-name=other-config uuid=$previous_template
32 xe template-uninstall template-uuid=$previous_template force=true
33 else
34 echo "Template $UBUNTU_INST_TEMPLATE_NAME already present"
35 exit 0
36 fi
37fi
38
39# Get built-in template
40builtin_name="Debian Squeeze 6.0 (32-bit)"
41builtin_uuid=$(xe template-list name-label="$builtin_name" --minimal)
42if [[ -z $builtin_uuid ]]; then
Joe Gordon46400262013-06-30 04:32:27 -070043 echo "Can't find the Debian Squeeze 32bit template on your XenServer."
John Garbuttd8f1a872012-06-26 11:16:38 +010044 exit 1
45fi
46
47# Clone built-in template to create new template
48new_uuid=$(xe vm-clone uuid=$builtin_uuid \
49 new-name-label="$UBUNTU_INST_TEMPLATE_NAME")
Stef Tf993b232012-11-08 10:46:48 -050050disk_size=$(($OSDOMU_VDI_GB * 1024 * 1024 * 1024))
John Garbuttd8f1a872012-06-26 11:16:38 +010051
52# Some of these settings can be found in example preseed files
53# however these need to be answered before the netinstall
54# is ready to fetch the preseed file, and as such must be here
55# to get a fully automated install
56pvargs="-- quiet console=hvc0 partman/default_filesystem=ext3 \
57console-setup/ask_detect=false locale=${UBUNTU_INST_LOCALE} \
58keyboard-configuration/layoutcode=${UBUNTU_INST_KEYBOARD} \
Mate Lakat2f524bd2013-06-19 12:32:23 +010059netcfg/choose_interface=eth0 \
John Garbuttd8f1a872012-06-26 11:16:38 +010060netcfg/get_hostname=os netcfg/get_domain=os auto \
61url=${preseed_url}"
62
Mate Lakat0b3804b2013-05-07 16:58:17 +010063if [ "$UBUNTU_INST_IP" != "dhcp" ]; then
John Garbuttd8f1a872012-06-26 11:16:38 +010064 netcfgargs="netcfg/disable_autoconfig=true \
65netcfg/get_nameservers=${UBUNTU_INST_NAMESERVERS} \
66netcfg/get_ipaddress=${UBUNTU_INST_IP} \
67netcfg/get_netmask=${UBUNTU_INST_NETMASK} \
68netcfg/get_gateway=${UBUNTU_INST_GATEWAY} \
69netcfg/confirm_static=true"
70 pvargs="${pvargs} ${netcfgargs}"
71fi
72
73xe template-param-set uuid=$new_uuid \
74 other-config:install-methods=http \
Mate Lakatd3740f72013-05-09 15:02:21 +010075 other-config:install-repository="http://${UBUNTU_INST_HTTP_HOSTNAME}${UBUNTU_INST_HTTP_DIRECTORY}" \
John Garbuttd8f1a872012-06-26 11:16:38 +010076 PV-args="$pvargs" \
77 other-config:debian-release="$UBUNTU_INST_RELEASE" \
78 other-config:default_template=true \
Stef Tf993b232012-11-08 10:46:48 -050079 other-config:disks='<provision><disk device="0" size="'$disk_size'" sr="" bootable="true" type="system"/></provision>' \
John Garbuttd8f1a872012-06-26 11:16:38 +010080 other-config:install-arch="$UBUNTU_INST_ARCH"
81
Mate Lakatd3740f72013-05-09 15:02:21 +010082if ! [ -z "$UBUNTU_INST_HTTP_PROXY" ]; then
83 xe template-param-set uuid=$new_uuid \
84 other-config:install-proxy="$UBUNTU_INST_HTTP_PROXY"
85fi
86
John Garbuttd8f1a872012-06-26 11:16:38 +010087echo "Ubuntu template installed uuid:$new_uuid"