ifup 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin $NETWORK_DEVICES/ifup
  4. #
  5. # Description : Interface Up
  6. #
  7. # Authors : Nathan Coulson - nathan@linuxfromscratch.org
  8. # Kevin P. Fleming - kpfleming@linuxfromscratch.org
  9. #
  10. # Version : 00.00
  11. #
  12. # Notes : the IFCONFIG variable is passed to the scripts found
  13. # in the services directory, to indicate what file the
  14. # service should source to get environmental variables.
  15. #
  16. ########################################################################
  17. . /lib/lsb/init-functions
  18. # Collect a list of configuration files for our interface
  19. if [ -n "${2}" ]; then
  20. for file in ${@#$1} # All parameters except $1
  21. do
  22. FILES="${FILES} ${NETWORK_DEVICES}/ifconfig.${1}/${file}"
  23. done
  24. elif [ -d "${NETWORK_DEVICES}/ifconfig.${1}" ]; then
  25. FILES=`echo ${NETWORK_DEVICES}/ifconfig.${1}/*`
  26. else
  27. FILES="${NETWORK_DEVICES}/ifconfig.${1}"
  28. fi
  29. message="Bringing up the ${1} interface..."
  30. # Process each configruation file
  31. for file in ${FILES}; do
  32. # skip backup files
  33. if [ "${file}" != "${file%""~""}" ]; then
  34. continue
  35. fi
  36. if [ ! -f "${file}" ]; then
  37. log_warning_msg
  38. message="${file} is not a network configuration file or directory."
  39. log_warning_msg
  40. fi
  41. (
  42. if [ ! -d "${file}" ]; then
  43. . ${file}
  44. fi
  45. # Will not process this service if started by boot, and ONBOOT
  46. # is not set to yes
  47. if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
  48. continue
  49. fi
  50. # Will not process this service if started by hotplug, and
  51. # ONHOTPLUG is not set to yes
  52. if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" -a "${HOSTNAME}" != "(none)" ]; then
  53. continue
  54. fi
  55. if [ -n "${SERVICE}" -a -x "/lib/network-services/${SERVICE}" ]; then
  56. if [ -z "${CHECK_LINK}" -o "${CHECK_LINK}" = "y" -o "${CHECK_LINK}" = "yes" -o "${CHECK_LINK}" = "1" ]; then
  57. if ip link show ${1} > /dev/null 2>&1; then
  58. link_status=`ip link show ${1}`
  59. if [ -n "${link_status}" ]; then
  60. if ! echo "${link_status}" | grep -q UP; then
  61. ip link set ${1} up
  62. evaluate_retval standard
  63. fi
  64. fi
  65. else
  66. message="${message}Interface ${1} doesn't exist."
  67. log_warning_msg
  68. fi
  69. fi
  70. IFCONFIG=${file} /lib/network-services/${SERVICE} ${1} up
  71. if [ "${?}" -eq "0" ]; then
  72. if [ ! -d "${file}" -a "${file}" != "${NETWORK_DEVICES}/ifconfig.${1}" ]; then
  73. mkdir -p "/run/network/ifconfig.${1}"
  74. cp "${file}" "/run/network/ifconfig.${1}"
  75. elif [ ! -d "${file}" ]; then
  76. cp "${file}" "/run/network/"
  77. fi
  78. fi
  79. else
  80. echo -e "${FAILURE}Unable to process ${file}. Either"
  81. echo -e "${FAILURE}the SERVICE variable was not set,"
  82. echo -e "${FAILURE}or the specified service cannot be executed."
  83. message=""
  84. log_failure_msg
  85. fi
  86. )
  87. done
  88. # End $NETWORK_DEVICES/ifup