"target" is also the name used in the debian installer for the installation target while "prefix" is too ambiguous.
135 lines
2.3 KiB
Bash
Executable File
135 lines
2.3 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# This script sets up the networking on the new gentoo image.
|
|
#
|
|
# Steve
|
|
# --
|
|
# http://www.steve.org.uk/
|
|
|
|
|
|
TARGET=$1
|
|
|
|
#
|
|
# Source our common functions
|
|
#
|
|
if [ -e /usr/share/xen-tools/common.sh ]; then
|
|
. /usr/share/xen-tools/common.sh
|
|
else
|
|
. ./hooks/common.sh
|
|
fi
|
|
|
|
|
|
#
|
|
# Log our start
|
|
#
|
|
logMessage Script $0 starting
|
|
|
|
|
|
#
|
|
# Make sure we have an /etc/conf.d directory.
|
|
#
|
|
mkdir -p ${TARGET}/etc/conf.d
|
|
|
|
|
|
#
|
|
# A function to setup DHCP for our new image.
|
|
#
|
|
setupDynamicNetworking ()
|
|
{
|
|
#
|
|
# The host is using DHCP.
|
|
#
|
|
cat <<E_O_DHCP > ${TARGET}/etc/conf.d/net
|
|
# /etc/conf.d/net:
|
|
# Global config file for net.* rc-scripts
|
|
#
|
|
# Setup DHCP for the first ethernet interface
|
|
#
|
|
config_eth0=( "dhcp" )
|
|
|
|
E_O_DHCP
|
|
}
|
|
|
|
|
|
|
|
#
|
|
# A function to setup static IP addresses for our new image.
|
|
#
|
|
setupStaticNetworking ()
|
|
{
|
|
#
|
|
# if $p2p is set then add a "pointopoint" setting.
|
|
#
|
|
point='';
|
|
if [ ! -z "${p2p}" ]; then
|
|
point="pointopoint ${p2p}"
|
|
else
|
|
point=''
|
|
fi
|
|
|
|
#
|
|
# We have a static IP address
|
|
#
|
|
cat <<E_O_STATIC >${TARGET}/etc/conf.d/net
|
|
#
|
|
# First ethernet interface
|
|
#
|
|
config_eth0=( "${ip1} ${point} netmask ${netmask}" )
|
|
routes_eth0=( "default via ${gateway}" )
|
|
|
|
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 >>${TARGET}/etc/conf.d/net
|
|
config_eth0:${interface}=( "{value} netmask "${netmask}" )
|
|
|
|
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 ${TARGET}/etc/resolv.conf.old
|
|
for ns in $nameserver; do
|
|
echo "nameserver $ns" >>${TARGET}/etc/resolv.conf.old
|
|
done
|
|
else
|
|
cp /etc/resolv.conf ${TARGET}/etc/resolv.conf.old
|
|
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
|