Changeset c2db087 for lsb-bootscripts/sbin/ifup
- Timestamp:
- 05/18/2011 05:18:30 PM (13 years ago)
- Branches:
- 10.0, 10.0-rc1, 10.1, 10.1-rc1, 11.0, 11.0-rc1, 11.0-rc2, 11.0-rc3, 11.1, 11.1-rc1, 11.2, 11.2-rc1, 11.3, 11.3-rc1, 12.0, 12.0-rc1, 12.1, 12.1-rc1, 7.0, 7.1, 7.2, 7.3, 7.4, 7.5, 7.5-systemd, 7.6, 7.6-systemd, 7.7, 7.7-systemd, 7.8, 7.8-systemd, 7.9, 7.9-systemd, 8.0, 8.1, 8.2, 8.3, 8.4, 9.0, 9.1, arm, bdubbs/gcc13, ml-11.0, multilib, renodr/libudev-from-systemd, s6-init, trunk, xry111/arm64, xry111/arm64-12.0, xry111/clfs-ng, xry111/lfs-next, xry111/loongarch, xry111/loongarch-12.0, xry111/loongarch-12.1, xry111/mips64el, xry111/pip3, xry111/rust-wip-20221008, xry111/update-glibc
- Children:
- d93bdd1e
- Parents:
- 499ce32
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lsb-bootscripts/sbin/ifup
r499ce32 rc2db087 1 1 #!/bin/sh 2 2 ######################################################################## 3 # Begin $NETWORK_DEVICES/ifup3 # Begin /sbin/ifdown 4 4 # 5 5 # Description : Interface Up 6 6 # 7 # Authors : Nathan Coulson - nathan@linuxfromscratch.org 8 # Kevin P. Fleming - kpfleming@linuxfromscratch.org 7 # Authors : DJ Lucas - dj@linuxfromscratch.org 9 8 # 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. 9 # Version : 00.02 15 10 # 16 11 ######################################################################## 17 12 18 . /lib/lsb/init-functions 13 . /lib/lsb/init-functions 19 14 20 # Collect a list of configuration files for our interface 21 if [ -n "${2}" ]; then 22 for file in ${@#$1} # All parameters except $1 23 do 24 FILES="${FILES} ${NETWORK_DEVICES}/ifconfig.${1}/${file}" 25 done 26 elif [ -d "${NETWORK_DEVICES}/ifconfig.${1}" ]; then 27 FILES=`echo ${NETWORK_DEVICES}/ifconfig.${1}/*` 28 else 29 FILES="${NETWORK_DEVICES}/ifconfig.${1}" 15 function get_args() 16 { 17 if test -z "${1}" ; then 18 showhelp 19 exit 1 20 fi 21 22 while test -n "${1}" ; do 23 case "${1}" in 24 -c | --configfile) 25 check_arg $1 $2 26 CONFIGFILE="${2}" 27 shift 2 28 ;; 29 eth* | iw* | wlan*) 30 INTERFACE="${1}" 31 shift 1 32 ;; 33 -h | --help) 34 showhelp 35 exit 0 36 ;; 37 *) 38 showhelp 39 echo "ERROR: '${1}' unknown argument" 40 echo "" 41 exit 2 42 ;; 43 esac 44 done 45 } 46 47 function check_arg() 48 { 49 echo "${2}" | grep -v "^-" > /dev/null 50 if [ -z "${?}" -o ! -n "${2}" ]; then 51 echo "Error: ${1} requires a valid argument." 52 exit 2 53 fi 54 } 55 56 function showhelp() 57 { 58 echo "`/usr/bin/basename ${0}` brings up a valid network interface." 59 echo "" 60 echo "Options:" 61 echo " -c --configfile The path to an interface configuration file" 62 echo " If no configuration file is given, all files" 63 echo " listed in ${NETWORK_DEVICES}/ifconfig.<int> will" 64 echo " be processed, regarless of the value of ONBOOT" 65 echo " -h --help Show this help message and exit." 66 echo "" 67 echo "Examples:" 68 echo " `/usr/bin/basename ${0}` eth0 -c ${NETWORK_DEVICES}/ifconfig.eth0/ipv4" 69 echo " `/usr/bin/basename ${0}` eth0" 70 echo "" 71 echo "" 72 } 73 74 # Intialize empty variables so that the shell does not polute the script 75 CONFIGFILE="" 76 CONFIGDIR="" 77 INTERFACE="" 78 79 # Process command line arguments 80 get_args ${@} 81 82 # Handle common errors - No need to account for bootscripts, this should not 83 # happen during boot or shutdown. 84 if [ "${CONFIGFILE}x" != "x" -a ! -f "${CONFIGFILE}" ]; then 85 echo "ERROR: ${CONFIGFILE} is not a valid network configuration file." 86 echo "" 87 exit 2 30 88 fi 31 89 32 message="Bringing up the ${1} interface..." 90 if [ "${INTERFACE}x" == "x" ]; then 91 echo "ERROR: No interface was given" 92 echo "" 93 exit 2 94 else 95 if ! grep "${INTERFACE}" /proc/net/dev 2>&1 > /dev/null; then 96 echo "ERROR: ${INTERFACE} is not a valid network interface." 97 echo "" 98 exit 2 99 fi 100 fi 33 101 34 # Process each configruation file 35 for file in ${FILES}; do 36 # skip backup files 37 if [ "${file}" != "${file%""~""}" ]; then 38 continue 102 # If a configuration file is present, use it 103 if [ "${CONFIGFILE}x" != "x" ]; then 104 . "${CONFIGFILE}" 105 if [ -x "/lib/network-services/${SERVICE}" ]; then 106 # do the work 107 # Check to make sure the interface is up 108 link_status=`/sbin/ip link show "${INTERFACE}" | \ 109 grep -o "state UP"` 110 if [ "${link_status}" != "state UP" ]; then 111 message="Bringing up the ${INTERFACE} interface..." 112 /sbin/ip link set ${INTERFACE} up 113 evaluate_retval standard 114 fi 115 if IFCONFIG=${CONFIGFILE} \ 116 /lib/network-services/${SERVICE} ${INTERFACE} up; then 117 mkdir -p "/run/network/ifconfig.${INTERFACE}" 118 cp "${CONFIGFILE}" "/run/network/ifconfig.${INTERFACE}/" 119 fi 120 else 121 echo "ERROR: Service '${SERVICE}' is not a valid service." 122 echo "" 123 exit 2 39 124 fi 40 41 if [ ! -f "${file}" ]; then 42 log_warning_msg 43 message="${file} is not a network configuration file or directory." 44 log_warning_msg 45 fi 46 47 ( 48 if [ ! -d "${file}" ]; then 49 . ${file} 50 fi 51 52 # Will not process this service if started by boot, and ONBOOT 53 # is not set to yes 54 if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then 55 continue 56 fi 57 # Will not process this service if started by hotplug, and 58 # ONHOTPLUG is not set to yes 59 if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" -a "${HOSTNAME}" != "(none)" ]; then 60 continue 61 fi 62 63 if [ -n "${SERVICE}" -a -x "/lib/network-services/${SERVICE}" ]; then 64 if [ -z "${CHECK_LINK}" -o "${CHECK_LINK}" = "y" -o "${CHECK_LINK}" = "yes" -o "${CHECK_LINK}" = "1" ]; then 65 if ip link show ${1} > /dev/null 2>&1; then 66 link_status=`ip link show ${1}` 67 if [ -n "${link_status}" ]; then 68 if ! echo "${link_status}" | grep -q UP; then 69 ip link set ${1} up 70 evaluate_retval standard 71 fi 125 # No interface configuration file was given 126 else 127 # Process all available interface configuration files 128 CONFIGDIR="/etc/network/ifconfig.${INTERFACE}" 129 if [ -d "${CONFIGDIR}" ]; then 130 FILES=`ls "${CONFIGDIR}"` 131 for CONFIGFILE in ${FILES} 132 do 133 ( 134 . "${CONFIGDIR}/${CONFIGFILE}" 135 if [ -x "/lib/network-services/${SERVICE}" ]; then 136 # Check to make sure the interface is up 137 link_status=`/sbin/ip link show "${INTERFACE}" | \ 138 grep -o "state UP"` 139 if [ "${link_status}" != "state UP" ]; then 140 message="Bringing up the ${INTERFACE} interface..." 141 /sbin/ip link set ${INTERFACE} up 142 evaluate_retval standard 143 fi 144 if IFCONFIG="${CONFIGDIR}/${CONFIGFILE}" \ 145 /lib/network-services/${SERVICE} ${INTERFACE} up; then 146 mkdir -p "/run/network/ifconfig.${INTERFACE}" 147 cp "${CONFIGDIR}/${CONFIGFILE}" \ 148 "/run/network/ifconfig.${INTERFACE}/" 72 149 fi 73 150 else 74 message="${message}Interface ${1} doesn't exist." 75 log_warning_msg 151 echo "ERROR: Service '${SERVICE}' is not a valid service." 152 echo "" 153 exit 2 76 154 fi 77 fi78 IFCONFIG=${file} /lib/network-services/${SERVICE} ${1} up79 if [ "${?}" -eq "0" ]; then80 if [ ! -d "${file}" -a "${file}" != "${NETWORK_DEVICES}/ifconfig.${1}" ]; then81 mkdir -p "/run/network/ifconfig.${1}"82 cp "${file}" "/run/network/ifconfig.${1}"83 elif [ ! -d "${file}" ]; then84 cp "${file}" "/run/network/"85 fi86 fi87 else88 echo -e "${FAILURE}Unable to process ${file}. Either"89 echo -e "${FAILURE}the SERVICE variable was not set,"90 echo -e "${FAILURE}or the specified service cannot be executed."91 message=""92 log_failure_msg93 fi94 )95 done96 155 97 # End $NETWORK_DEVICES/ifup 156 ) 157 done 158 fi 159 fi 160
Note:
See TracChangeset
for help on using the changeset viewer.