ifup 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin /sbin/ifup
  4. #
  5. # Description : Interface Up
  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 SERVICE script
  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 ifup, 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. ifup is used to bring up 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. log_info_msg "Bringing up the ${1} interface... "
  47. if [ ! -r "${file}" ]; then
  48. log_warning_msg "\n${file} is missing or cannot be accessed."
  49. exit 1
  50. fi
  51. . $file
  52. if [ "$IFACE" = "" ]; then
  53. log_failure_msg "\n${file} does not define an interface [IFACE]."
  54. exit 1
  55. fi
  56. # Do not process this service if started by boot, and ONBOOT
  57. # is not set to yes
  58. if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
  59. log_info_msg2 "skipped\n"
  60. exit 0
  61. fi
  62. for S in ${SERVICE}; do
  63. if [ ! -x "/lib/services/${S}" ]; then
  64. MSG="\nUnable to process ${file}. Either "
  65. MSG="${MSG}the SERVICE '${S} was not present "
  66. MSG="${MSG}or cannot be executed."
  67. log_failure_msg "$MSG"
  68. exit 1
  69. fi
  70. done
  71. if [ -z "${CHECK_LINK}" -o \
  72. "${CHECK_LINK}" = "y" -o \
  73. "${CHECK_LINK}" = "yes" -o \
  74. "${CHECK_LINK}" = "1" ]; then
  75. # Bring up the interface
  76. if ip link show ${IFACE} > /dev/null 2>&1; then
  77. link_status=`ip link show ${IFACE}`
  78. if [ -n "${link_status}" ]; then
  79. if ! echo "${link_status}" | grep -q UP; then
  80. ip link set ${IFACE} up
  81. fi
  82. fi
  83. else
  84. log_warning_msg "\nInterface ${IFACE} doesn't exist."
  85. exit 0
  86. fi
  87. fi
  88. for S in ${SERVICE}; do
  89. IFCONFIG=${file} /lib/services/${S} ${IFACE} up
  90. done
  91. # End /sbin/ifup