#!/bin/bash #----------------------------------------------------------------------------- # /var/install/bin/xen-create-domain - create XEN domain from template # # Last Update: $Id$ # # Copyright (c) 2006-2012 the eisfair team, team(at)eisfair(dot)org # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. #----------------------------------------------------------------------------- # Load desired libs . /var/install/include/xenlib . /etc/config.d/base #exec 2> /tmp/xen-create-domain-trace$$.log #set -x read_dhcp_leases () { if [ "$IP_NET_1_STATIC_IP" = "no" ] then leasefile=/var/lib/dhcp3/dhclient.eth0.leases if [ -f $leasefile ] then IP_NET_1_NETMASK=`grep 'subnet-mask' $leasefile | awk 'BEGIN { RS=""; FS="\n" } { print $NF }' | sed -e 's#[^0-9.]##g'` IP_NET_1_GATEWAY=`grep 'router' $leasefile | awk 'BEGIN { RS=""; FS="\n" } { print $NF }' | sed -e 's#[^0-9.]##g'` DOMAIN_NAME=`grep 'domain-name' $leasefile | awk 'BEGIN { RS=""; FS="\n" } { print $NF }' | sed -e 's#^[^"]*##g' -e 's#[^"]*$##' -e 's#["]##g'` DNS_SERVER=`grep 'domain-name-servers' $leasefile | awk 'BEGIN { RS=""; FS="\n" } { print $NF }' | sed -e 's#[^0-9.]##g'` fi fi } cleanUpOnError () { cd # important for umount mecho --error "$1" ${swapImageCreated:-false} && { echo "Deleting swap image..." #remove $swapImage mecho --warn " -`lvremove -f $swapImage`" } ${diskImageCreated:-false} && { echo "Deleting disk image..." unMount "$mountpoint" mecho --warn " -`lvremove -f $diskImage`" } [ -d "$mountpoint" ] && remove "$mountpoint" remove "" exit 1 } cleanUpNormal() { cd # important for umount [ -d "$mountpoint" ] && { unMount "$mountpoint" remove "$mountpoint" # register created domain: registrate_domain $domainName } echo "Done." anykey } cleanUpOnERR () { cleanUpOnError "An error occoured! Aborting..." } cleanUpOnSIGINT () { cleanUpOnError "Ctrl-C pressed! Aborting..." } ### TODO: Validate input data in a nice(!) way networkTemplateScriptInput() { mecho --info "Collect network settings:" hostname=$domainName address=`askIP "question=an IP-Address (e.g. 192.168.0.100)" "type=ip-address"` netmask=`askIP "question=the Subnetmask" "proposal=$IP_NET_1_NETMASK" "type=subnet mask"` gateway=`askIP "question=the default gateway" "proposal=$IP_NET_1_GATEWAY" "type=default gateway"` searchdomain=`/var/install/bin/ask --tty --info "Please enter the Domain" "${DOMAIN_NAME}" "+"` nameserver=`askIP "question=the DNS" "proposal=$DNS_SERVER" "type=DNS"` } # Here it begins # main clrhome template="${*}" if [ -z "$template" ] then /var/install/bin/list-files.cui -t "Select a template" \ -p "$xenTemplatePath" \ -f '*.tar.gz' -f '*.tar.bz2' \ -o 1 \ -q 'Use template >>%ls<