netplug-script 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/sh
  2. #
  3. # netplug - policy agent for netplugd
  4. #
  5. # Copyright 2003 Key Research, Inc.
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License, version 2, as
  9. # published by the Free Software Foundation. You are forbidden from
  10. # redistributing or modifying it under the terms of any other license,
  11. # including other versions of the GNU General Public License.
  12. #
  13. # This program is distributed in the hope that it will be useful, but
  14. # WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. # General Public License for more details.
  17. PATH=/usr/bin:/bin:/usr/sbin:/sbin
  18. export PATH
  19. dev="$1"
  20. action="$2"
  21. case "$action" in
  22. in)
  23. if [ -x /sbin/ifup ]; then
  24. exec /sbin/ifup $dev
  25. else
  26. echo "Please teach me how to plug in an interface!" 1>&2
  27. exit 1
  28. fi
  29. ;;
  30. out)
  31. if [ -x /sbin/ifdown ]; then
  32. # At least on Fedora Core 1, the call to ip addr flush infloops
  33. # /sbin/ifdown $dev && exec /sbin/ip addr flush $dev
  34. exec /sbin/ifdown $dev
  35. else
  36. echo "Please teach me how to unplug an interface!" 1>&2
  37. exit 1
  38. fi
  39. ;;
  40. probe)
  41. # exec /sbin/ip link set $dev up >/dev/null 2>&1
  42. if [ -x /sbin/ifconfig ]; then
  43. exec /sbin/ifconfig $dev up >/dev/null 2>&1
  44. else
  45. echo "Failed to probe an interface!" 1>&2
  46. exit 1
  47. fi
  48. ;;
  49. *)
  50. echo "I have been called with a funny action of '%s'!" 1>&2
  51. exit 1
  52. ;;
  53. esac