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