[f874424] | 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 | #
|
---|
[b7804ae] | 11 | # Version : LFS 7.7
|
---|
[f874424] | 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 |
|
---|
[970a126] | 19 | up()
|
---|
| 20 | {
|
---|
| 21 | if ip link show $1 > /dev/null 2>&1; then
|
---|
| 22 | link_status=`ip link show $1`
|
---|
| 23 |
|
---|
| 24 | if [ -n "${link_status}" ]; then
|
---|
| 25 | if ! echo "${link_status}" | grep -q UP; then
|
---|
| 26 | ip link set $1 up
|
---|
| 27 | fi
|
---|
| 28 | fi
|
---|
| 29 |
|
---|
| 30 | else
|
---|
| 31 | log_failure_msg "\nInterface ${IFACE} doesn't exist."
|
---|
| 32 | exit 1
|
---|
| 33 | fi
|
---|
| 34 | }
|
---|
| 35 |
|
---|
[b7804ae] | 36 | RELEASE="7.7"
|
---|
[f874424] | 37 |
|
---|
| 38 | USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
|
---|
| 39 | VERSTR="LFS ifup, version ${RELEASE}"
|
---|
| 40 |
|
---|
| 41 | while [ $# -gt 0 ]; do
|
---|
| 42 | case "$1" in
|
---|
| 43 | --help | -h) help="y"; break ;;
|
---|
| 44 |
|
---|
| 45 | --version | -V) echo "${VERSTR}"; exit 0 ;;
|
---|
| 46 |
|
---|
| 47 | -*) echo "ifup: ${1}: invalid option" >&2
|
---|
| 48 | echo "${USAGE}" >& 2
|
---|
| 49 | exit 2 ;;
|
---|
| 50 |
|
---|
| 51 | *) break ;;
|
---|
| 52 | esac
|
---|
| 53 | done
|
---|
| 54 |
|
---|
| 55 | if [ -n "$help" ]; then
|
---|
| 56 | echo "${VERSTR}"
|
---|
| 57 | echo "${USAGE}"
|
---|
| 58 | echo
|
---|
| 59 | cat << HERE_EOF
|
---|
| 60 | ifup is used to bring up a network interface. The interface
|
---|
| 61 | parameter, e.g. eth0 or eth0:2, must match the trailing part of the
|
---|
| 62 | interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2.
|
---|
| 63 |
|
---|
| 64 | HERE_EOF
|
---|
| 65 | exit 0
|
---|
| 66 | fi
|
---|
| 67 |
|
---|
| 68 | file=/etc/sysconfig/ifconfig.${1}
|
---|
| 69 |
|
---|
| 70 | # Skip backup files
|
---|
| 71 | [ "${file}" = "${file%""~""}" ] || exit 0
|
---|
| 72 |
|
---|
| 73 | . /lib/lsb/init-functions
|
---|
| 74 |
|
---|
[bd899fb] | 75 | log_info_msg "Bringing up the ${1} interface... "
|
---|
[f874424] | 76 |
|
---|
| 77 | if [ ! -r "${file}" ]; then
|
---|
[aa14485] | 78 | log_failure_msg2 "${file} is missing or cannot be accessed."
|
---|
[f874424] | 79 | exit 1
|
---|
| 80 | fi
|
---|
| 81 |
|
---|
| 82 | . $file
|
---|
| 83 |
|
---|
| 84 | if [ "$IFACE" = "" ]; then
|
---|
[aa14485] | 85 | log_failure_msg2 "${file} does not define an interface [IFACE]."
|
---|
[f874424] | 86 | exit 1
|
---|
| 87 | fi
|
---|
| 88 |
|
---|
| 89 | # Do not process this service if started by boot, and ONBOOT
|
---|
| 90 | # is not set to yes
|
---|
| 91 | if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then
|
---|
[b7804ae] | 92 | log_skip_msg
|
---|
[f874424] | 93 | exit 0
|
---|
| 94 | fi
|
---|
| 95 |
|
---|
[6553bff] | 96 | for S in ${SERVICE}; do
|
---|
| 97 | if [ ! -x "/lib/services/${S}" ]; then
|
---|
[970a126] | 98 | MSG="\nUnable to process ${file}. Either "
|
---|
[6553bff] | 99 | MSG="${MSG}the SERVICE '${S} was not present "
|
---|
| 100 | MSG="${MSG}or cannot be executed."
|
---|
[bd899fb] | 101 | log_failure_msg "$MSG"
|
---|
| 102 | exit 1
|
---|
| 103 | fi
|
---|
| 104 | done
|
---|
[f874424] | 105 |
|
---|
[b7804ae] | 106 | if [ "${SERVICE}" = "wpa" ]; then log_success_msg; fi
|
---|
| 107 |
|
---|
[970a126] | 108 | # Create/configure the interface
|
---|
| 109 | for S in ${SERVICE}; do
|
---|
| 110 | IFCONFIG=${file} /lib/services/${S} ${IFACE} up
|
---|
| 111 | done
|
---|
[f874424] | 112 |
|
---|
[970a126] | 113 | # Bring up the interface and any components
|
---|
| 114 | for I in $IFACE $INTERFACE_COMPONENTS; do up $I; done
|
---|
[f874424] | 115 |
|
---|
[aa14485] | 116 | # Set MTU if requested. Check if MTU has a "good" value.
|
---|
| 117 | if test -n "${MTU}"; then
|
---|
| 118 | if [[ ${MTU} =~ ^[0-9]+$ ]] && [[ $MTU -ge 68 ]] ; then
|
---|
[970a126] | 119 | for I in $IFACE $INTERFACE_COMPONENTS; do
|
---|
| 120 | ip link set dev $I mtu $MTU;
|
---|
| 121 | done
|
---|
[aa14485] | 122 | else
|
---|
| 123 | log_info_msg2 "Invalid MTU $MTU"
|
---|
| 124 | fi
|
---|
| 125 | fi
|
---|
| 126 |
|
---|
[970a126] | 127 | # Set the route default gateway if requested
|
---|
| 128 | if [ -n "${GATEWAY}" ]; then
|
---|
| 129 | if ip route | grep -q default; then
|
---|
[b7804ae] | 130 | log_skip_msg "\n Gateway already setup; skipping."
|
---|
[970a126] | 131 | else
|
---|
| 132 | log_info_msg "Setting up default gateway..."
|
---|
| 133 | ip route add default via ${GATEWAY} dev ${IFACE}
|
---|
| 134 | evaluate_retval
|
---|
| 135 | fi
|
---|
| 136 | fi
|
---|
[bd899fb] | 137 |
|
---|
[f874424] | 138 | # End /sbin/ifup
|
---|