ifdown 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin /sbin/ifdown
  4. #
  5. # Description : Interface Down
  6. #
  7. # Authors : Nathan Coulson - nathan@linuxfromscratch.org
  8. # Kevin P. Fleming - kpfleming@linuxfromscratch.org
  9. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.0
  12. #
  13. # Notes : the IFCONFIG variable is passed to the scripts found
  14. # in the /lib/boot directory, to indicate what file the
  15. # service should source to get environmental variables.
  16. #
  17. ########################################################################
  18. file=/etc/sysconfig/ifconfig.${1}
  19. # Skip backup files
  20. [ "${file}" = "${file%""~""}" ] || exit 0
  21. . /lib/boot/functions
  22. if [ ! -r "${file}" ]; then
  23. boot_mesg "${file} is missing or cannot be accessed." ${WARNING}
  24. echo_warning
  25. exit 1
  26. fi
  27. . ${file}
  28. if [ "$IFACE" = "" ]; then
  29. boot_mesg "${file} does not define an interface [IFACE]." ${FAILURE}
  30. echo_failure
  31. exit 1
  32. fi
  33. # This will run the service script, if SERVICE is set
  34. if [ -n "${SERVICE}" -a -x "/lib/boot/${SERVICE}" ]; then
  35. if ip link show ${IFACE} > /dev/null 2>&1; then
  36. IFCONFIG=${file} /lib/boot/${SERVICE} ${IFACE} down
  37. else
  38. boot_mesg "Interface ${1} doesn't exist." ${WARNING}
  39. echo_warning
  40. fi
  41. else
  42. boot_mesg "Unable to process ${file}. Either" ${FAILURE}
  43. boot_mesg "the SERVICE variable was not set"
  44. boot_mesg "or the specified service cannot be executed."
  45. echo_failure
  46. exit 1
  47. fi
  48. link_status=`ip link show ${IFACE} 2>/dev/null`
  49. if [ -n "${link_status}" ]; then
  50. if echo "${link_status}" | grep -q UP; then
  51. boot_mesg "Bringing down the ${IFACE} interface..."
  52. ip link set ${IFACE} down
  53. evaluate_retval
  54. fi
  55. fi
  56. # End /sbin/ifdown