source: bootscripts/lfs/sbin/ifup@ e9d172b

ml-11.0 multilib
Last change on this file since e9d172b was e9d172b, checked in by Xℹ Ruoyao <xry111@…>, 3 years ago

Merge changes from trunk

git-svn-id: http://svn.linuxfromscratch.org/LFS/branches/multilib@11611 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

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