PageRenderTime 101ms CodeModel.GetById 88ms app.highlight 9ms RepoModel.GetById 2ms app.codeStats 0ms

/rc0.d/K20ifplugd

http://github.com/brinkman83/bashrc
Shell | 153 lines | 111 code | 15 blank | 27 comment | 31 complexity | b7ca12521dfa63e8da61bee98a086d22 MD5 | raw file
  1#!/bin/sh
  2# $Id: ifplugd.init.in 43 2003-09-13 11:25:11Z lennart $
  3
  4# This file is part of ifplugd.
  5#
  6# ifplugd is free software; you can redistribute it and/or modify it under
  7# the terms of the GNU General Public License as published by the Free
  8# Software Foundation; either version 2 of the License, or (at your
  9# option) any later version.
 10#
 11# ifplugd is distributed in the hope that it will be useful, but WITHOUT
 12# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 14# for more details.
 15#
 16# You should have received a copy of the GNU General Public License
 17# along with ifplugd; if not, write to the Free Software Foundation,
 18# Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 19
 20### BEGIN INIT INFO
 21# Provides:          ifplugd
 22# Required-Start:    $network $remote_fs
 23# Required-Stop:     $network $remote_fs
 24# Default-Start:     2 3 4 5
 25# Default-Stop:      0 1 6
 26# Short-Description: Brings up/down network automatically
 27# Description:       Brings networks interfaces up and down automatically when
 28#                    the cable is removed / inserted
 29### END INIT INFO
 30
 31DAEMON_NAME=ifplugd
 32CFG=/etc/default/$DAEMON_NAME
 33DESC="Network Interface Plugging Daemon"
 34IFPLUGD=/usr/sbin/$DAEMON_NAME
 35test -x $IFPLUGD || exit 0
 36
 37if [ `id -u` != "0" ] && [ "$1" = "start" -o "$1" = "stop" ] ; then
 38  echo "You must be root to start, stop or restart ifplugd."
 39  exit 1
 40fi
 41
 42[ -f $CFG ] && . $CFG
 43
 44VERB="$1"
 45shift
 46
 47[ $# -ne 0 ] && INTERFACES="$@"
 48
 49all_interfaces () {
 50    for IFPATH in /sys/class/net/* ; do
 51        IFNAME="${IFPATH#/sys/class/net/}"
 52
 53        [ -e "$IFPATH/device" ] || continue
 54
 55        if [ -f "$IFPATH/type" ] ; then
 56            grep --quiet '^1$' "$IFPATH/type" || continue
 57        fi
 58
 59        case "$IFNAME" in
 60            eth*|wlan*)
 61                echo $IFNAME
 62                ;;
 63        esac
 64    done
 65}
 66
 67[ "x$INTERFACES" = "xauto" -o "x$INTERFACES" = "xall" ] && INTERFACES="$(all_interfaces)"
 68
 69. /lib/lsb/init-functions
 70
 71case "$VERB" in
 72    start)
 73        [ "$INTERFACES" ] || exit 0
 74        log_action_begin_msg "$DESC"
 75        for IF in $INTERFACES ; do
 76            if [ ! -e /sys/class/net/$IF ] || \
 77               $IFPLUGD -c -i $IF >/dev/null ; then
 78                log_action_cont_msg "skip $IF"
 79                continue
 80            fi
 81            log_action_cont_msg "start $IF"
 82            IF1=$(echo $IF | sed "s/-/_/")
 83            A=$(eval echo \$\{ARGS_${IF1}\})
 84            [ -z "$A" ] && A="$ARGS"
 85            $IFPLUGD -i $IF $A
 86        done
 87        log_action_end_msg 0
 88        ;;
 89    stop)
 90        [ "$INTERFACES" ] || exit 0
 91        log_action_begin_msg "$DESC"
 92        for IF in $INTERFACES ; do 
 93            if [ ! -e /sys/class/net/$IF ] || \
 94               ! $IFPLUGD -c -i $IF >/dev/null ; then
 95                log_action_cont_msg "skip $IF"
 96                continue
 97            fi
 98            log_action_cont_msg "stop $IF"
 99            $IFPLUGD -k --wait-on-kill -i $IF
100        done
101        log_action_end_msg 0
102        ;;
103    status)
104        [ "$INTERFACES" -o "$HOTPLUG_INTERFACES" ] || exit 0
105        for IF in $INTERFACES $HOTPLUG_INTERFACES ; do
106            if [ ! -e /sys/class/net/$IF ] ; then
107                log_action_msg "$IF: device $IF is either not present or not functional"
108                continue
109            fi
110            log_begin_msg "$IF: "
111            $IFPLUGD -c -i $IF
112        done
113        ;;
114    suspend)
115        [ "$INTERFACES" -o "$HOTPLUG_INTERFACES" ] || exit 0
116        log_action_begin_msg "$DESC"
117        for IF in $INTERFACES $HOTPLUG_INTERFACES ; do
118            if [ ! -e /sys/class/net/$IF ] || \
119               ! $IFPLUGD -c -i $IF >/dev/null ; then
120                log_action_cont_msg "skip $IF"
121                continue
122            fi
123            log_action_cont_msg "suspend $IF"
124            $IFPLUGD -S -i $IF
125        done
126        log_action_end_msg 0
127        ;;
128    resume)
129        [ "$INTERFACES" -o "$HOTPLUG_INTERFACES" ] || exit 0
130        log_action_begin_msg "$DESC"
131        for IF in $INTERFACES $HOTPLUG_INTERFACES ; do
132            if [ ! -e /sys/class/net/$IF ] || \
133               ! $IFPLUGD -c -i $IF >/dev/null ; then
134                log_action_cont_msg "skip $IF"
135                continue
136            fi
137            log_action_cont_msg "resume $IF"
138            $IFPLUGD -R -i $IF
139        done
140        log_action_end_msg 0
141        ;;
142    force-reload|restart)
143        [ "$INTERFACES" ] || exit 0
144        $0 stop $INTERFACES
145        sleep 3
146        $0 start $INTERFACES
147        ;;
148    *)
149        echo "Usage: $0 {start|stop|restart|force-reload|status|suspend|resume}"
150        exit 1
151esac
152
153exit 0