This optional config value is used in hooks to create domU resolv.conf. If unset, domU's resolv.conf is created by the guest distrib install.
149 lines
2.8 KiB
Bash
Executable File
149 lines
2.8 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# This script sets up the /etc/network/interface file for the new
|
|
# image.
|
|
#
|
|
# Steve
|
|
# --
|
|
# http://www.steve.org.uk/
|
|
|
|
|
|
prefix=$1
|
|
|
|
#
|
|
# Source our common functions
|
|
#
|
|
if [ -e /usr/lib/xen-tools/common.sh ]; then
|
|
. /usr/lib/xen-tools/common.sh
|
|
else
|
|
. ./hooks/common.sh
|
|
fi
|
|
|
|
|
|
#
|
|
# Log our start
|
|
#
|
|
logMessage Script $0 starting
|
|
|
|
|
|
#
|
|
# Make sure we have an /etc/network directory.
|
|
#
|
|
mkdir -p ${prefix}/etc/network
|
|
|
|
|
|
#
|
|
# A function to setup DHCP for our new image.
|
|
#
|
|
setupDynamicNetworking ()
|
|
{
|
|
#
|
|
# The host is using DHCP.
|
|
#
|
|
cat <<E_O_DHCP > ${prefix}/etc/network/interfaces
|
|
# This file describes the network interfaces available on your system
|
|
# and how to activate them. For more information, see interfaces(5).
|
|
|
|
# The loopback network interface
|
|
auto lo
|
|
iface lo inet loopback
|
|
|
|
# The primary network interface
|
|
auto eth0
|
|
iface eth0 inet dhcp
|
|
# post-up ethtool -K eth0 tx off
|
|
|
|
#
|
|
# The commented out line above will disable TCP checksumming which
|
|
# might resolve problems for some users. It is disabled by default
|
|
#
|
|
E_O_DHCP
|
|
}
|
|
|
|
|
|
|
|
#
|
|
# A function to setup static IP addresses for our new image.
|
|
#
|
|
setupStaticNetworking ()
|
|
{
|
|
#
|
|
# We have a static IP address
|
|
#
|
|
cat <<E_O_STATIC >${prefix}/etc/network/interfaces
|
|
# This file describes the network interfaces available on your system
|
|
# and how to activate them. For more information, see interfaces(5).
|
|
|
|
# The loopback network interface
|
|
auto lo
|
|
iface lo inet loopback
|
|
|
|
# The primary network interface
|
|
auto eth0
|
|
iface eth0 inet static
|
|
address ${ip1}
|
|
gateway ${gateway}
|
|
netmask ${netmask}
|
|
# post-up ethtool -K eth0 tx off
|
|
|
|
#
|
|
# The commented out line above will disable TCP checksumming which
|
|
# might resolve problems for some users. It is disabled by default
|
|
#
|
|
E_O_STATIC
|
|
|
|
interface=1
|
|
count=2
|
|
|
|
while [ "${count}" -le "${ip_count}" ]; do
|
|
|
|
value=\$ip${count}
|
|
value=`eval echo $value`
|
|
|
|
logMessage Adding etho:${interface}
|
|
|
|
cat <<E_O_STATIC >>${prefix}/etc/network/interfaces
|
|
auto eth0:${interface}
|
|
iface eth0:${interface} inet static
|
|
address ${value}
|
|
netmask ${netmask}
|
|
# post-up ethtool -K eth0 tx off
|
|
E_O_STATIC
|
|
count=`expr $count + 1`
|
|
interface=`expr $interface + 1`
|
|
done
|
|
|
|
#
|
|
# Hooks are run chrooted, hence the resolv.conf is moved
|
|
# temporarily to /etc/resolv.conf.old. Use that file, it
|
|
# will be restored after hooks are run.
|
|
#
|
|
if [ '*' != "*$nameserver" ]; then
|
|
rm -f ${prefix}/etc/resolv.conf.old
|
|
for ns in $nameserver; do
|
|
echo "nameserver $ns" >>${prefix}/etc/resolv.conf.old
|
|
done
|
|
fi
|
|
}
|
|
|
|
|
|
|
|
|
|
#
|
|
# Call the relevant function
|
|
#
|
|
if [ -z "${dhcp}" ]; then
|
|
logMessage "Setting up static networking"
|
|
setupStaticNetworking
|
|
|
|
else
|
|
logMessage "Setting up DHCP networking"
|
|
setupDynamicNetworking
|
|
fi
|
|
|
|
|
|
#
|
|
# Log our finish
|
|
#
|
|
logMessage Script $0 finished
|