2006-11-20 18:06:44 +01:00
|
|
|
# !!! Don't like it that I have to pass the kernel here.
|
2007-03-04 01:40:59 +01:00
|
|
|
{ nettools, kernel, module_init_tools, wirelesstools
|
2007-02-12 17:00:55 +01:00
|
|
|
, nameservers, defaultGateway, interfaces
|
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
# !!! use XML
|
|
|
|
names = map (i: i.name) interfaces;
|
2007-03-04 01:40:59 +01:00
|
|
|
ipAddresses = map (i: if i ? ipAddress then i.ipAddress else "dhcp") interfaces;
|
2007-02-28 15:19:20 +01:00
|
|
|
subnetMasks = map (i: if i ? subnetMask then i.subnetMask else "default") interfaces;
|
2007-03-04 01:40:59 +01:00
|
|
|
essids = map (i: if i ? essid then i.essid else "default") interfaces;
|
|
|
|
wepKeys = map (i: if i ? wepKey then i.wepKey else "nokey") 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
|
|
|
|
export MODULE_DIR=${kernel}/lib/modules/
|
|
|
|
|
2006-11-20 18:28:08 +01:00
|
|
|
${module_init_tools}/sbin/modprobe af_packet
|
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.
|
|
|
|
if test \"$essid\" != dhcp; then
|
|
|
|
${wirelesstools}/sbin/iwconfig \"$name\" essid \"$essid\"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test \"$wepKey\" != nokey; then
|
|
|
|
${wirelesstools}/sbin/iwconfig \"$name\" key \"$(cat \"$wepKey\")\"
|
|
|
|
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.
|
|
|
|
if test -n \"${toString nameservers}\"; then
|
|
|
|
rm -f /etc/resolv.conf
|
|
|
|
for i in ${toString nameservers}; do
|
|
|
|
echo \"nameserver $i\" >> /etc/resolv.conf
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Set the default gateway.
|
|
|
|
if test -n \"${defaultGateway}\"; then
|
|
|
|
${nettools}/sbin/route add default gw \"${defaultGateway}\" || true
|
|
|
|
fi
|
|
|
|
|
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.
|
|
|
|
respawn sleep 10000
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
";
|
|
|
|
|
|
|
|
}
|