[a44ae577] | 1 | #!/bin/bash
|
---|
[f874424] | 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 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.
|
---|
| 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 ;;
|
---|
[a44ae577] | 33 |
|
---|
[f874424] | 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 |
|
---|
[a44ae577] | 56 | . /lib/lsb/init-functions
|
---|
[f874424] | 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 [ "$IFACE" = "" ]; then
|
---|
| 66 | log_failure_msg "${file} does not define an interface [IFACE]."
|
---|
| 67 | exit 1
|
---|
| 68 | fi
|
---|
| 69 |
|
---|
[970a126] | 70 | # We only need to first service to bring down the interface
|
---|
| 71 | S=`echo ${SERVICE} | cut -f1 -d" "`
|
---|
[bd899fb] | 72 |
|
---|
| 73 | if ip link show ${IFACE} > /dev/null 2>&1; then
|
---|
[970a126] | 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
|
---|
| 82 | fi
|
---|
[f874424] | 83 | else
|
---|
[bd899fb] | 84 | log_warning_msg "Interface ${1} doesn't exist."
|
---|
[f874424] | 85 | fi
|
---|
| 86 |
|
---|
[970a126] | 87 | # Leave the interface up if there are additional interfaces in the device
|
---|
[f874424] | 88 | link_status=`ip link show ${IFACE} 2>/dev/null`
|
---|
| 89 |
|
---|
| 90 | if [ -n "${link_status}" ]; then
|
---|
| 91 | if [ "$(echo "${link_status}" | grep UP)" != "" ]; then
|
---|
[3710570] | 92 | if [ "$(ip addr show ${IFACE} | grep 'inet ')" == "" ]; then
|
---|
[f874424] | 93 | log_info_msg "Bringing down the ${IFACE} interface..."
|
---|
| 94 | ip link set ${IFACE} down
|
---|
| 95 | evaluate_retval
|
---|
| 96 | fi
|
---|
| 97 | fi
|
---|
| 98 | fi
|
---|
| 99 |
|
---|
| 100 | # End /sbin/ifdown
|
---|