remove an old note for file
[linux_from_scratch.git] / BOOK / bootscripts / lfs / sbin / ifdown
blobe875be905af8afe7c65d92999e09b3edefebf6b3
1 #!/bin/bash
2 ########################################################################
3 # Begin /sbin/ifdown
5 # Description : Interface Down
7 # Authors : Nathan Coulson - nathan@linuxfromscratch.org
8 # Kevin P. Fleming - kpfleming@linuxfromscratch.org
9 # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
11 # Version : LFS 7.0
13 # Notes : the IFCONFIG variable is passed to the scripts found
14 # in the /lib/services directory, to indicate what file the
15 # service should source to get interface specifications.
17 ########################################################################
19 RELEASE="7.0"
21 USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
22 VERSTR="LFS ifdown, version ${RELEASE}"
24 while [ $# -gt 0 ]; do
25 case "$1" in
26 --help | -h) help="y"; break ;;
28 --version | -V) echo "${VERSTR}"; exit 0 ;;
30 -*) echo "ifup: ${1}: invalid option" >&2
31 echo "${USAGE}" >& 2
32 exit 2 ;;
34 *) break ;;
35 esac
36 done
38 if [ -n "$help" ]; then
39 echo "${VERSTR}"
40 echo "${USAGE}"
41 echo
42 cat << HERE_EOF
43 ifdown is used to bring down a network interface. The interface
44 parameter, e.g. eth0 or eth0:2, must match the trailing part of the
45 interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2.
47 HERE_EOF
48 exit 0
51 file=/etc/sysconfig/ifconfig.${1}
53 # Skip backup files
54 [ "${file}" = "${file%""~""}" ] || exit 0
56 . /lib/lsb/init-functions
58 if [ ! -r "${file}" ]; then
59 log_warning_msg "${file} is missing or cannot be accessed."
60 exit 1
63 . ${file}
65 if [ "$IFACE" = "" ]; then
66 log_failure_msg "${file} does not define an interface [IFACE]."
67 exit 1
70 # We only need to first service to bring down the interface
71 S=`echo ${SERVICE} | cut -f1 -d" "`
73 if ip link show ${IFACE} > /dev/null 2>&1; then
74 if [ -n "${S}" -a -x "/lib/services/${S}" ]; then
75 IFCONFIG=${file} /lib/services/${S} ${IFACE} down
76 else
77 MSG="Unable to process ${file}. Either "
78 MSG="${MSG}the SERVICE variable was not set "
79 MSG="${MSG}or the specified service cannot be executed."
80 log_failure_msg "$MSG"
81 exit 1
83 else
84 log_warning_msg "Interface ${1} doesn't exist."
87 # Leave the interface up if there are additional interfaces in the device
88 link_status=`ip link show ${IFACE} 2>/dev/null`
90 if [ -n "${link_status}" ]; then
91 if [ "$(echo "${link_status}" | grep UP)" != "" ]; then
92 if [ "$(ip addr show ${IFACE} | grep 'inet ')" == "" ]; then
93 log_info_msg "Bringing down the ${IFACE} interface..."
94 ip link set ${IFACE} down
95 evaluate_retval
100 # End /sbin/ifdown