2007-11-23 18:12:37 +01:00
|
|
|
{nettools, modprobe, wirelesstools, bash, writeText, config}:
|
2007-02-12 17:00:55 +01:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2007-11-23 18:12:37 +01:00
|
|
|
cfg = config.networking;
|
|
|
|
|
2007-02-12 17:00:55 +01:00
|
|
|
# !!! use XML
|
2007-11-23 18:12:37 +01:00
|
|
|
names = map (i: i.name) cfg.interfaces;
|
|
|
|
ipAddresses = map (i: if i ? ipAddress then i.ipAddress else "dhcp") cfg.interfaces;
|
|
|
|
subnetMasks = map (i: if i ? subnetMask then i.subnetMask else "default") cfg.interfaces;
|
|
|
|
essids = map (i: if i ? essid then i.essid else "default") cfg.interfaces;
|
|
|
|
wepKeys = map (i: if i ? wepKey then i.wepKey else "nokey") cfg.interfaces;
|
2007-02-12 17:00:55 +01:00
|
|
|
|
|
|
|
in
|
2006-11-20 18:06:44 +01:00
|
|
|
|
|
|
|
{
|
|
|
|
name = "network-interfaces";
|
|
|
|
|
|
|
|
job = "
|
2006-11-20 18:28:08 +01:00
|
|
|
start on hardware-scan
|
2006-11-20 18:06:44 +01:00
|
|
|
stop on shutdown
|
|
|
|
|
|
|
|
start script
|
2007-05-24 16:50:17 +02:00
|
|
|
export PATH=${modprobe}/sbin:$PATH
|
|
|
|
modprobe af_packet || true
|
2006-11-24 17:31:01 +01:00
|
|
|
|
2006-11-20 18:06:44 +01:00
|
|
|
for i in $(cd /sys/class/net && ls -d *); do
|
|
|
|
echo \"Bringing up network device $i...\"
|
|
|
|
${nettools}/sbin/ifconfig $i up || true
|
|
|
|
done
|
2006-11-24 17:31:01 +01:00
|
|
|
|
2007-02-12 17:00:55 +01:00
|
|
|
# Configure the manually specified interfaces.
|
|
|
|
names=(${toString names})
|
|
|
|
ipAddresses=(${toString ipAddresses})
|
2007-02-28 15:19:20 +01:00
|
|
|
subnetMasks=(${toString subnetMasks})
|
2007-03-04 01:40:59 +01:00
|
|
|
essids=(${toString essids})
|
|
|
|
wepKeys=(${toString wepKeys})
|
2007-02-20 16:14:48 +01:00
|
|
|
|
2007-02-12 17:00:55 +01:00
|
|
|
for ((n = 0; n < \${#names[*]}; n++)); do
|
|
|
|
name=\${names[$n]}
|
|
|
|
ipAddress=\${ipAddresses[$n]}
|
2007-02-28 15:19:20 +01:00
|
|
|
subnetMask=\${subnetMasks[$n]}
|
2007-03-04 01:40:59 +01:00
|
|
|
essid=\${essids[$n]}
|
|
|
|
wepKey=\${wepKeys[$n]}
|
|
|
|
|
|
|
|
# Set wireless networking stuff.
|
2007-05-24 16:50:17 +02:00
|
|
|
if test \"$essid\" != default; then
|
2007-03-16 15:46:56 +01:00
|
|
|
${wirelesstools}/sbin/iwconfig \"$name\" essid \"$essid\" || true
|
2007-03-04 01:40:59 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
if test \"$wepKey\" != nokey; then
|
2007-03-16 15:46:56 +01:00
|
|
|
${wirelesstools}/sbin/iwconfig \"$name\" key \"$(cat \"$wepKey\")\" || true
|
2007-03-04 01:40:59 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Set IP address / netmask.
|
|
|
|
if test \"$ipAddress\" != dhcp; then
|
|
|
|
echo \"Configuring interface $name...\"
|
|
|
|
extraFlags=
|
|
|
|
if test \"$subnetMask\" != default; then
|
|
|
|
extraFlags=\"$extraFlags netmask $subnetMask\"
|
|
|
|
fi
|
|
|
|
${nettools}/sbin/ifconfig \"$name\" \"$ipAddress\" $extraFlags || true
|
2007-02-28 15:19:20 +01:00
|
|
|
fi
|
2007-03-04 01:40:59 +01:00
|
|
|
|
2007-02-12 17:00:55 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
# Set the nameservers.
|
2007-11-23 18:12:37 +01:00
|
|
|
if test -n \"${toString cfg.nameservers}\"; then
|
2007-02-12 17:00:55 +01:00
|
|
|
rm -f /etc/resolv.conf
|
2007-11-23 18:12:37 +01:00
|
|
|
if test -n \"${cfg.domain}\"; then
|
|
|
|
echo \"domain ${cfg.domain}\" >> /etc/resolv.conf
|
|
|
|
fi
|
|
|
|
for i in ${toString cfg.nameservers}; do
|
2007-02-12 17:00:55 +01:00
|
|
|
echo \"nameserver $i\" >> /etc/resolv.conf
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the default gateway.
|
2007-11-23 18:12:37 +01:00
|
|
|
if test -n \"${cfg.defaultGateway}\"; then
|
|
|
|
${nettools}/sbin/route add default gw \"${cfg.defaultGateway}\" || true
|
2007-02-12 17:00:55 +01:00
|
|
|
fi
|
|
|
|
|
2007-05-24 16:50:17 +02:00
|
|
|
# Run any user-specified commands.
|
2007-11-23 18:12:37 +01:00
|
|
|
${bash}/bin/sh ${writeText "local-net-cmds" cfg.localCommands} || true
|
2007-05-24 16:50:17 +02:00
|
|
|
|
2006-11-20 18:06:44 +01:00
|
|
|
end script
|
|
|
|
|
|
|
|
# Hack: Upstart doesn't yet support what we want: a service that
|
|
|
|
# doesn't have a running process associated with it.
|
2007-04-10 16:18:15 +02:00
|
|
|
respawn sleep 100000
|
2006-11-20 18:06:44 +01:00
|
|
|
|
|
|
|
stop script
|
|
|
|
for i in $(cd /sys/class/net && ls -d *); do
|
2006-11-24 17:31:01 +01:00
|
|
|
echo \"Taking down network device $i...\"
|
2006-11-20 18:06:44 +01:00
|
|
|
${nettools}/sbin/ifconfig $i down || true
|
|
|
|
done
|
|
|
|
end script
|
|
|
|
|
|
|
|
";
|
|
|
|
|
|
|
|
}
|