source: lsb-bootscripts/sbin/ifdown@ c2db087

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 7.0 7.1 7.2 7.3 7.4 7.5 7.5-systemd 7.6 7.6-systemd 7.7 7.7-systemd 7.8 7.8-systemd 7.9 7.9-systemd 8.0 8.1 8.2 8.3 8.4 9.0 9.1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since c2db087 was c2db087, checked in by DJ Lucas <dj@…>, 13 years ago

New ifup/ifdown and modified network script. Changed comments on cleanfs scritp as well.

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@9543 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 5.2 KB
Line 
1#!/bin/sh
2########################################################################
3# Begin /sbin/ifdown
4#
5# Description : Interface Down
6#
7# Authors : DJ Lucas - dj@linuxfromscratch.org
8#
9# Version : 00.02
10#
11########################################################################
12
13. /lib/lsb/init-functions
14
15function get_args()
16 {
17 if test -z "${1}" ; then
18 showhelp
19 exit 1
20 fi
21
22 while test -n "${1}" ; do
23 case "${1}" in
24 -c | --configfile)
25 check_arg $1 $2
26 CONFIGFILE="${2}"
27 shift 2
28 ;;
29 -f | --force)
30 FORCE="1"
31 shift 1
32 ;;
33 eth* | iw* | wlan*)
34 INTERFACE="${1}"
35 shift 1
36 ;;
37 -h | --help)
38 showhelp
39 exit 0
40 ;;
41 *)
42 showhelp
43 echo "ERROR: '${1}' unknown argument"
44 echo ""
45 exit 2
46 ;;
47 esac
48 done
49 }
50
51function check_arg()
52 {
53 echo "${2}" | grep -v "^-" > /dev/null
54 if [ -z "${?}" -o ! -n "${2}" ]; then
55 echo "Error: ${1} requires a valid argument."
56 exit 2
57 fi
58 }
59
60function showhelp()
61 {
62 echo ""
63 echo "`/usr/bin/basename ${0}` brings down a valid network interface."
64 echo ""
65 echo "Options:"
66 echo " -c --configfile The path to an interface configuration file"
67 echo " If no configuration file is given, all files"
68 echo " listed in /etc/network/ifconfig.<int> will"
69 echo " be processed, regarless of the value of ONBOOT"
70 echo " -f --force Flush all IPs and force the interface down."
71 echo " -h --help Show this help message and exit."
72 echo ""
73 echo "Examples:"
74 echo " `/usr/bin/basename ${0}` eth0 -c /run/network/ifconfig.eth0/ipv4"
75 echo " `/usr/bin/basename ${0}` eth0 --force -c /run/network/ifconfig.eth0/ipv4"
76 echo " `/usr/bin/basename ${0}` eth0 --force"
77 echo " `/usr/bin/basename ${0}` eth0"
78 echo ""
79 echo ""
80 }
81
82# Intialize empty variables so that the shell does not polute the script
83CONFIGFILE=""
84CONFIGDIR=""
85INTERFACE=""
86FORCE=""
87failed=0
88
89# Process command line arguments
90get_args ${@}
91
92# Handle common errors - No need to account for bootscripts, this should not
93# happen during boot or shutdown.
94if [ "${CONFIGFILE}x" != "x" -a ! -f "${CONFIGFILE}" ]; then
95 echo "ERROR: ${CONFIGFILE} is not a valid network configuration file."
96 echo ""
97 exit 2
98fi
99
100if [ "${INTERFACE}x" == "x" ]; then
101 echo "ERROR: No interface was given"
102 echo ""
103 exit 2
104else
105 if ! grep "${INTERFACE}" /proc/net/dev 2>&1 > /dev/null; then
106 echo "ERROR: ${INTERFACE} is not a valid network interface."
107 echo ""
108 exit 2
109 fi
110fi
111
112# If a configuration file is present, use it
113if [ "${CONFIGFILE}x" != "x" ]; then
114 . "${CONFIGFILE}"
115 if [ -x "/lib/network-services/${SERVICE}" ]; then
116 # do the work
117 if IFCONFIG=${CONFIGFILE} \
118 /lib/network-services/${SERVICE} ${INTERFACE} down; then
119 rm "${CONFIGFILE}"
120 fi
121 else
122 echo "ERROR: Service '${SERVICE}' is not a valid service."
123 echo ""
124 exit 2
125 fi
126# No interface configuration file was given
127else
128 # Process all running interface configuration files
129 CONFIGDIR="/run/network/ifconfig.${INTERFACE}"
130 if [ -d "${CONFIGDIR}" ]; then
131 FILES=`ls "${CONFIGDIR}"`
132 for CONFIGFILE in ${FILES}
133 do
134 (
135 . "${CONFIGDIR}/${CONFIGFILE}"
136 # No error checking necessary if they are in /run
137 if IFCONFIG="${CONFIGDIR}/${CONFIGFILE}" \
138 /lib/network-services/${SERVICE} ${INTERFACE} down; then
139 rm "${CONFIGDIR}/${CONFIGFILE}"
140 fi
141 )
142 done
143 # all running config files processes, set the link down
144 message="Setting interface ${INTERFACE} down..."
145 /sbin/ip link set "${INTERFACE}" down
146 evaluate_retval standard
147 else
148 if [ "${FORCE}" != "1" ]; then
149 echo "ERROR: No configuration files found for ${INTERFACE}."
150 echo ""
151 exit 2
152 fi
153 fi
154fi
155
156if [ "${FORCE}" == "1" ]; then
157 /sbin/ip addr flush dev "${INTERFACE}" 2>&1 > /dev/null || failed=1
158 if [ "${failed}" == "1" ]; then
159 log_failure_msg "Flushing IP addresses from interface ${INTERFACE}..."
160 echo ""
161 exit 1
162 else
163 log_success_msg "Flushing IP addresses from interface ${INTERFACE}..."
164 fi
165 /sbin/ip link set dev "${INTERFACE}" down 2>&1 > /dev/null || failed=1
166 if [ "${failed}" == "1" ]; then
167 log_failure_msg "Setting link down for interface ${INTERFACE}..."
168 echo ""
169 exit 1
170 else
171 log_success_msg "Setting link down for interface ${INTERFACE}..."
172 fi
173fi
174
175exit "${failed}"
176
Note: See TracBrowser for help on using the repository browser.