#!/bin/sh # Network Link hotplug agent for use with netplugd # requiring the netlink daemon from http://www.red-bean.com/~bos/ # installed and configured like described in Linux-Magazin 09/2006 # # netlinkd hotplug params include: # ACTION=%s [add or remove] # INTERFACE=%s # # HISTORY: # # 17-Jul-2006 Initial version of this hotplug agent. cd /etc/hotplug . ./hotplug.functions # DEBUG=yes export DEBUG if [ "${INTERFACE}" = "" ]; then mesg Bad NET_LINK invocation: \$INTERFACE is not set exit 1 fi case $ACTION in add|register) if [ -x /sbin/ifup ]; then if grep -q "^allow-hotplug[[:space:]].*${INTERFACE}" /etc/network/interfaces; then # this $INTERFACE is marked as class hotplug if ps -C ifup ho args | grep -q "$INTERFACE"; then debug_mesg "Already ifup-ing that interface" else start-stop-daemon --start --background \ --pidfile /var/run/hotplug.net.ifup.bogus \ --startas /etc/hotplug/net.ifup -- "$INTERFACE" fi exit 0 fi else mesg "E: /sbin/ifup not found. You need to install the ifupdown package." fi ;; remove|unregister) if [ -x /sbin/ifdown ]; then if ps -C ifdown ho args | grep -q $INTERFACE; then debug_mesg "Already ifdown-ing interface $INTERFACE" elif [ ! -e /etc/hotplug/.run/net.enable ]; then debug_mesg "The net.enable flag does not exist, $INTERFACE not removed" else debug_mesg "Invoking ifdown $INTERFACE" if [ -e /var/run/netplugd.${INTERFACE} ]; then kill `cat /var/run/netplugd.${INTERFACE}` fi ifdown "${INTERFACE}" ifconfig ${INTERFACE} 0.0.0.0 up start-stop-daemon --start --background \ --pidfile /var/run/netplugd.${INTERFACE} \ --exec /sbin/netplugd -- -i ${INTERFACE} -p /var/run/netplug fi exit 0 else mesg "E: /sbin/ifdown not found. You need to install the ifupdown package" fi ;; *) debug_mesg NET_LINK $ACTION event not supported exit 1 ;; esac