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