1 | #!/bin/bash
|
---|
2 | ########################################################################
|
---|
3 | # Begin /sbin/ifdown
|
---|
4 | #
|
---|
5 | # Description : Interface Down
|
---|
6 | #
|
---|
7 | # Authors : Nathan Coulson - nathan@linuxfromscratch.org
|
---|
8 | # Kevin P. Fleming - kpfleming@linuxfromscratch.org
|
---|
9 | # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
|
---|
10 | #
|
---|
11 | # Version : LFS 7.0
|
---|
12 | #
|
---|
13 | # Notes : the ${file} 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.
|
---|
16 | #
|
---|
17 | ########################################################################
|
---|
18 |
|
---|
19 | RELEASE="7.0"
|
---|
20 |
|
---|
21 | USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
|
---|
22 | VERSTR="LFS ifdown, version ${RELEASE}"
|
---|
23 |
|
---|
24 | while [ $# -gt 0 ]; do
|
---|
25 | case "$1" in
|
---|
26 | --help | -h) help="y"; break ;;
|
---|
27 |
|
---|
28 | --version | -V) echo "${VERSTR}"; exit 0 ;;
|
---|
29 |
|
---|
30 | -*) echo "ifup: ${1}: invalid option" >&2
|
---|
31 | echo "${USAGE}" >& 2
|
---|
32 | exit 2 ;;
|
---|
33 |
|
---|
34 | *) break ;;
|
---|
35 | esac
|
---|
36 | done
|
---|
37 |
|
---|
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.
|
---|
46 |
|
---|
47 | HERE_EOF
|
---|
48 | exit 0
|
---|
49 | fi
|
---|
50 |
|
---|
51 | file=/etc/sysconfig/ifconfig.${1}
|
---|
52 |
|
---|
53 | # Skip backup files
|
---|
54 | [ "${file}" = "${file%""~""}" ] || exit 0
|
---|
55 |
|
---|
56 | . /lib/lsb/init-functions
|
---|
57 |
|
---|
58 | if [ ! -r "${file}" ]; then
|
---|
59 | log_warning_msg "${file} is missing or cannot be accessed."
|
---|
60 | exit 1
|
---|
61 | fi
|
---|
62 |
|
---|
63 | . ${file}
|
---|
64 |
|
---|
65 | if [ -z "$PHYS" ]; then
|
---|
66 | log_failure_msg "${file} does not define any physical interfaces [PHYS]."
|
---|
67 | exit 1
|
---|
68 | fi
|
---|
69 |
|
---|
70 | # Reverse the order
|
---|
71 | SERVICES=
|
---|
72 | for S in ${SERVICE}; do SERVICES="${SERVICES} ${S}"; done
|
---|
73 |
|
---|
74 | # This will run the service scripts
|
---|
75 | EXISTING_INTERFACES=
|
---|
76 | for PHY in ${PHYS} ; do
|
---|
77 | if ip link show ${PHY} > /dev/null 2>&1 ; then
|
---|
78 | EXISTING_INTERFACES="${EXISTING_INTERFACES} ${PHY}"
|
---|
79 | else
|
---|
80 | log_warning_msg "Interface ${PHY} doesn't exist."
|
---|
81 | fi
|
---|
82 | done
|
---|
83 |
|
---|
84 | if [ -n "${EXISTING_INTERFACES}" ] ; then
|
---|
85 | for S in ${SERVICES}; do
|
---|
86 |
|
---|
87 | if [ -n "${S}" -a -x "/lib/services/${S}" ]; then
|
---|
88 | IFCONFIG=${file} /lib/services/${S} ${file} down
|
---|
89 | else
|
---|
90 | MSG="Unable to process ${file}. Either"
|
---|
91 | MSG="${MSG} the SERVICE variable was not set"
|
---|
92 | MSG="${MSG} or the specified service cannot be executed."
|
---|
93 | log_failure_msg "$MSG"
|
---|
94 | exit 1
|
---|
95 | fi
|
---|
96 | done
|
---|
97 |
|
---|
98 | for PHY in "${EXISTING_INTERFACES}" ; do
|
---|
99 | link_status=`ip link show ${PHY} 2>/dev/null`
|
---|
100 |
|
---|
101 | if [ -n "${link_status}" ]; then
|
---|
102 | if [ "$(echo "${link_status}" | grep UP)" != "" ]; then
|
---|
103 | #QRUX - Why does it matter if ${PHY} has an IP address?
|
---|
104 | #QRUX - Seems like it should be taken it down regardless.
|
---|
105 | if [ "$(ip addr show ${PHY} | grep 'inet ')" != "" ]; then
|
---|
106 | log_info_msg "Bringing down the ${PHY} interface..."
|
---|
107 | ip link set ${PHY} down
|
---|
108 | evaluate_retval
|
---|
109 | fi
|
---|
110 | fi
|
---|
111 | fi
|
---|
112 | done
|
---|
113 | else
|
---|
114 | log_warning_msg "No interfaces among (${PHYS}) exist."
|
---|
115 | fi
|
---|
116 |
|
---|
117 | # End /sbin/ifdown
|
---|