ifdown 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/bin/bash
  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/services directory, to indicate what file the
  15. # service should source to get interface specifications.
  16. #
  17. ########################################################################
  18. RELEASE="7.0"
  19. USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
  20. VERSTR="LFS ifdown, version ${RELEASE}"
  21. while [ $# -gt 0 ]; do
  22. case "$1" in
  23. --help | -h) help="y"; break ;;
  24. --version | -V) echo "${VERSTR}"; exit 0 ;;
  25. -*) echo "ifup: ${1}: invalid option" >&2
  26. echo "${USAGE}" >& 2
  27. exit 2 ;;
  28. *) break ;;
  29. esac
  30. done
  31. if [ -n "$help" ]; then
  32. echo "${VERSTR}"
  33. echo "${USAGE}"
  34. echo
  35. cat << HERE_EOF
  36. ifdown is used to bring down a network interface. The interface
  37. parameter, e.g. eth0 or eth0:2, must match the trailing part of the
  38. interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2.
  39. HERE_EOF
  40. exit 0
  41. fi
  42. file=/etc/sysconfig/ifconfig.${1}
  43. # Skip backup files
  44. [ "${file}" = "${file%""~""}" ] || exit 0
  45. . /lib/lsb/init-functions
  46. if [ ! -r "${file}" ]; then
  47. log_warning_msg "${file} is missing or cannot be accessed."
  48. exit 1
  49. fi
  50. . ${file}
  51. # We only need to first service to bring down the interface
  52. S=`echo ${SERVICE} | cut -f1 -d" "`
  53. if ip link show ${1} > /dev/null 2>&1; then
  54. if [ -n "${S}" -a -x "/lib/services/${S}" ]; then
  55. IFCONFIG=${file} /lib/services/${S} ${1} down
  56. else
  57. MSG="Unable to process ${file}. Either "
  58. MSG="${MSG}the SERVICE variable was not set "
  59. MSG="${MSG}or the specified service cannot be executed."
  60. log_failure_msg "$MSG"
  61. exit 1
  62. fi
  63. else
  64. log_warning_msg "Interface ${1} doesn't exist."
  65. fi
  66. # Leave the interface up if there are additional interfaces in the device
  67. link_status=`ip link show ${1} 2>/dev/null`
  68. if [ -n "${link_status}" ]; then
  69. if [ "$(echo "${link_status}" | grep UP)" != "" ]; then
  70. if [ "$(ip addr show ${1} | grep 'inet ')" == "" ]; then
  71. log_info_msg "Bringing down the ${1} interface..."
  72. ip link set ${1} down
  73. evaluate_retval
  74. fi
  75. fi
  76. fi
  77. # End /sbin/ifdown