diff options
author | DJ Lucas <dj@linuxfromscratch.org> | 2011-05-18 17:18:30 +0000 |
---|---|---|
committer | DJ Lucas <dj@linuxfromscratch.org> | 2011-05-18 17:18:30 +0000 |
commit | c2db0877b0203a21182e5aaba75c98e6291d2ea0 (patch) | |
tree | 4845d841e8c425c558cbfe6336e298328f18eb10 /lsb-bootscripts/sbin/ifdown | |
parent | 499ce32dd46e8fba9c0fc18c398408cc269ad867 (diff) |
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
Diffstat (limited to 'lsb-bootscripts/sbin/ifdown')
-rw-r--r-- | lsb-bootscripts/sbin/ifdown | 230 |
1 files changed, 154 insertions, 76 deletions
diff --git a/lsb-bootscripts/sbin/ifdown b/lsb-bootscripts/sbin/ifdown index f9e2a51ad..e6d49c874 100644 --- a/lsb-bootscripts/sbin/ifdown +++ b/lsb-bootscripts/sbin/ifdown @@ -1,98 +1,176 @@ #!/bin/sh ######################################################################## -# Begin $NETWORK_DEVICES/ifdown +# Begin /sbin/ifdown # # Description : Interface Down # -# Authors : Nathan Coulson - nathan@linuxfromscratch.org -# Kevin P. Fleming - kpfleming@linuxfromscratch.org +# Authors : DJ Lucas - dj@linuxfromscratch.org # -# Version : 00.01 -# -# Notes : the IFCONFIG variable is passed to the scripts found -# in the services directory, to indicate what file the -# service should source to get environmental variables. +# Version : 00.02 # ######################################################################## . /lib/lsb/init-functions -# Collect a list of configuration files for our interface -if [ -n "${2}" ]; then - for file in ${@#$1}; do # All parameters except $1 - FILES="${FILES} /run/network/ifconfig.${1}/${file}" - done -elif [ -d "/run/network/ifconfig.${1}" ]; then - FILES=`echo /run/network/ifconfig.${1}/*` -else - FILES="/run/network/ifconfig.${1}" -fi - -# Reverse the order configuration files are processed in -for file in ${FILES}; do - FILES2="${file} ${FILES2}" -done -FILES=${FILES2} +function get_args() + { + if test -z "${1}" ; then + showhelp + exit 1 + fi -# Process each configuration file -for file in ${FILES}; do - # skip backup files - if [ "${file}" != "${file%""~""}" ]; then - continue - fi + while test -n "${1}" ; do + case "${1}" in + -c | --configfile) + check_arg $1 $2 + CONFIGFILE="${2}" + shift 2 + ;; + -f | --force) + FORCE="1" + shift 1 + ;; + eth* | iw* | wlan*) + INTERFACE="${1}" + shift 1 + ;; + -h | --help) + showhelp + exit 0 + ;; + *) + showhelp + echo "ERROR: '${1}' unknown argument" + echo "" + exit 2 + ;; + esac + done + } - if [ ! -f "${file}" ]; then - message="${file} is not a network configuration file or directory." - log_warning_msg - fi - ( - if [ ! -d "${file}" ]; then - . ${file} +function check_arg() + { + echo "${2}" | grep -v "^-" > /dev/null + if [ -z "${?}" -o ! -n "${2}" ]; then + echo "Error: ${1} requires a valid argument." + exit 2 fi + } - # Will not process this service if started by boot, and ONBOOT - # is not set to yes - if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then - continue - fi +function showhelp() + { + echo "" + echo "`/usr/bin/basename ${0}` brings down a valid network interface." + echo "" + echo "Options:" + echo " -c --configfile The path to an interface configuration file" + echo " If no configuration file is given, all files" + echo " listed in /etc/network/ifconfig.<int> will" + echo " be processed, regarless of the value of ONBOOT" + echo " -f --force Flush all IPs and force the interface down." + echo " -h --help Show this help message and exit." + echo "" + echo "Examples:" + echo " `/usr/bin/basename ${0}` eth0 -c /run/network/ifconfig.eth0/ipv4" + echo " `/usr/bin/basename ${0}` eth0 --force -c /run/network/ifconfig.eth0/ipv4" + echo " `/usr/bin/basename ${0}` eth0 --force" + echo " `/usr/bin/basename ${0}` eth0" + echo "" + echo "" + } + +# Intialize empty variables so that the shell does not polute the script +CONFIGFILE="" +CONFIGDIR="" +INTERFACE="" +FORCE="" +failed=0 + +# Process command line arguments +get_args ${@} + +# Handle common errors - No need to account for bootscripts, this should not +# happen during boot or shutdown. +if [ "${CONFIGFILE}x" != "x" -a ! -f "${CONFIGFILE}" ]; then + echo "ERROR: ${CONFIGFILE} is not a valid network configuration file." + echo "" + exit 2 +fi + +if [ "${INTERFACE}x" == "x" ]; then + echo "ERROR: No interface was given" + echo "" + exit 2 +else + if ! grep "${INTERFACE}" /proc/net/dev 2>&1 > /dev/null; then + echo "ERROR: ${INTERFACE} is not a valid network interface." + echo "" + exit 2 + fi +fi - # Will not process this service if started by hotplug, and - # ONHOTPLUG is not set to yes - if [ "${IN_HOTPLUG}" = "1" -a "${ONHOTPLUG}" != "yes" ]; then - continue +# If a configuration file is present, use it +if [ "${CONFIGFILE}x" != "x" ]; then + . "${CONFIGFILE}" + if [ -x "/lib/network-services/${SERVICE}" ]; then + # do the work + if IFCONFIG=${CONFIGFILE} \ + /lib/network-services/${SERVICE} ${INTERFACE} down; then + rm "${CONFIGFILE}" fi - - # This will run the service script, if SERVICE is set - if [ -n "${SERVICE}" -a -x "/lib/network-services/${SERVICE}" ]; then - if ip link show ${1} > /dev/null 2>&1 - then - IFCONFIG=${file} /lib/network-services/${SERVICE} ${1} down && - if [ -f "${file}" ]; then - rm ${file} + else + echo "ERROR: Service '${SERVICE}' is not a valid service." + echo "" + exit 2 + fi +# No interface configuration file was given +else + # Process all running interface configuration files + CONFIGDIR="/run/network/ifconfig.${INTERFACE}" + if [ -d "${CONFIGDIR}" ]; then + FILES=`ls "${CONFIGDIR}"` + for CONFIGFILE in ${FILES} + do + ( + . "${CONFIGDIR}/${CONFIGFILE}" + # No error checking necessary if they are in /run + if IFCONFIG="${CONFIGDIR}/${CONFIGFILE}" \ + /lib/network-services/${SERVICE} ${INTERFACE} down; then + rm "${CONFIGDIR}/${CONFIGFILE}" fi - else - message="Interface ${1} doesn't exist." - log_warning_msg - fi - else - echo -e "${FAILURE}Unable to process ${file}. Either" - echo -e "${FAILURE}the SERVICE variable was not set," - echo -e "${FAILURE}or the specified service cannot be executed." - message="" - log_failure_msg - fi - ) -done - -if [ -z "${2}" ]; then - link_status=`ip link show $1` - if [ -n "${link_status}" ]; then - if echo "${link_status}" | grep -q UP; then - message="Bringing down the ${1} interface..." - ip link set ${1} down - evaluate_retval standard + ) + done + # all running config files processes, set the link down + message="Setting interface ${INTERFACE} down..." + /sbin/ip link set "${INTERFACE}" down + evaluate_retval standard + else + if [ "${FORCE}" != "1" ]; then + echo "ERROR: No configuration files found for ${INTERFACE}." + echo "" + exit 2 fi fi fi + +if [ "${FORCE}" == "1" ]; then + /sbin/ip addr flush dev "${INTERFACE}" 2>&1 > /dev/null || failed=1 + if [ "${failed}" == "1" ]; then + log_failure_msg "Flushing IP addresses from interface ${INTERFACE}..." + echo "" + exit 1 + else + log_success_msg "Flushing IP addresses from interface ${INTERFACE}..." + fi + /sbin/ip link set dev "${INTERFACE}" down 2>&1 > /dev/null || failed=1 + if [ "${failed}" == "1" ]; then + log_failure_msg "Setting link down for interface ${INTERFACE}..." + echo "" + exit 1 + else + log_success_msg "Setting link down for interface ${INTERFACE}..." + fi +fi + +exit "${failed}" -# End $NETWORK_DEVICES/ifdown |