#!/sbin/runscript # Copyright 1999-2004 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 # $Header: /var/cvsroot/gentoo-x86/sys-apps/ifplugd/files/ifplugd.init,v 1.4 2006/04/06 12:23:08 uberlord Exp $ #NB: Config is in /etc/conf.d/ifplugd depend() { use pcmcia } opts="stop start status" get_start_interfaces() { if [[ -n ${INTERFACES} ]]; then echo "${INTERFACES}" return fi INTERFACES=" $(sed -n -e 's/^[ \t]*\(.*\):.*/\1/p' /proc/net/dev | xargs) " local exclude iface if [[ -f /proc/net/wireless && ${WIRELESS_INTERFACES} == "no" ]]; then exclude="$(sed -n -e 's/^[ \t]*\(.*\):.*/\1/p' /proc/net/wireless \ | xargs)" fi # Exclude ifplugd started by other scripts - like net.xxx if [[ -d "${svcdir}/daemons" ]]; then exclude="${exclude} $( grep "\"/var/run/ifplugd.*.pid\"" "${svcdir}"/daemons/* 2>/dev/null \ | grep -v "${svcdir}/daemons/ifplugd:" \ | sed -n -e 's/.*ifplugd\.\(.*\)\.pid.*/\1/p' )" fi exclude=" lo ${exclude} " for iface in ${exclude}; do INTERFACES="${INTERFACES// ${iface} / }" done echo "${INTERFACES}" } get_running_interfaces() { local exclude="" INTERFACES="$( cd /var/run ls ifplugd.*.pid 2>/dev/null | sed -n -e 's/^ifplugd.\(.*\).pid$/\1/p' | xargs )" if [[ -d "${svcdir}/daemons" ]]; then local exclude=$( grep "\"/var/run/ifplugd.*.pid\"" "${svcdir}"/daemons/* 2>/dev/null \ | grep -v "${svcdir}/daemons/ifplugd:" \ | sed -n -e 's/.*ifplugd\.\(.*\)\.pid.*/\1/p' ) fi INTERFACES=" ${INTERFACES} " for iface in ${exclude}; do INTERFACES=${INTERFACES// ${iface} / } done echo "${INTERFACES}" } # Check if an option is set for a given interface. # $1 is interface, $2 is option name, $3 is preset is_set() { [[ $(get_opt "$@") == "yes" ]] } # Expand an option value for a given interface. # $1 is interface, $2 is option name, $3 is preset get_opt() { local iface="$1" option="$2" preset="$3" eval preset=\"\${${option}:=${preset}}\" eval echo \"\${${option}_${iface}:=${preset}}\" } # Handle starting for all interfaces start() { local iface oneworked=false einfo "Starting ifplugd: " eindent for iface in $(get_start_interfaces); do ebegin "${iface}" local args="" pidfile="/var/run/ifplugd.${iface}.pid" if [[ -e ${pidfile} ]] ; then local running=false if [[ $(type -t is_daemon_running) == "function" ]] ; then is_daemon_running /usr/sbin/ifplugd "${pidfile}" && running=true else local pid="$(< "${pidfile}")" [[ " $(pidof /sbin/ifplugd) " == *" ${pid} "* ]] && running=true fi if ${running} ; then eindent einfo "ifplugd is already running on ${iface}" eend 0 eoutdent oneworked=true continue fi fi is_set "${iface}" AUTO yes || args="${args}a" is_set "${iface}" BEEP yes || args="${args}b" is_set "${iface}" IGNORE_FAIL yes && args="${args}f" is_set "${iface}" IGNORE_FAIL_POSITIVE yes || args="${args}F" is_set "${iface}" IGNORE_RETVAL yes && args="${args}I" is_set "${iface}" SHUTDOWN yes || args="${args}q" is_set "${iface}" WAIT_ON_FORK yes && args="${args}w" is_set "${iface}" MONITOR yes || args="${args}M" [[ -n ${args} ]] && args="-${args}" args="${args} -t$(get_opt "${iface}" POLL_TIME 1)" args="${args} -u$(get_opt "${iface}" DELAY_UP 0)" args="${args} -d$(get_opt "${iface}" DELAY_DOWN 5)" args="${args} -m$(get_opt "${iface}" API_MODE auto)" args="${args} $(get_opt "${iface}" ARGS '')" start-stop-daemon --start --exec /usr/sbin/ifplugd \ --pidfile "/var/run/ifplugd.${iface}.pid" \ -- --iface="${iface}" ${args} local r="$?" if is_set "${iface}" WAIT_ON_FORK yes ; then [[ ${r} -le 2 ]] else [[ ${r} == "0" ]] fi eend $? && oneworked=true done ${oneworked} } stop() { local iface allstopped=true einfo "Stopping ifplugd: " eindent for iface in $(get_running_interfaces); do ebegin "${iface}" start-stop-daemon --stop --exec /usr/sbin/ifplugd \ --pidfile "/var/run/ifplugd.${iface}.pid" eend $? || allstopped=false done ${allstopped} } status() { local iface service_started "${myservice}" || return 0 for iface in $(get_running_interfaces); do einfo "$(/usr/sbin/ifplugstatus ${iface})" done } # vim:ts=4