#!/bin/sh
+#
+# $Id: ifdown,v 1.24.2.6 2001/09/30 10:19:42 misiek Exp $
+#
PATH=/sbin:/usr/sbin:/bin:/usr/bin
-cd /etc/sysconfig/network-scripts
-. ./network-functions
+. /etc/sysconfig/network
+. /etc/rc.d/init.d/functions
+. /etc/sysconfig/network-scripts/functions.network
-CONFIG=$1
+DEV=$1
-[ -z "$CONFIG" ] && {
- echo "usage: ifdown <device name>" >&2
+[ -z "$DEV" ] && {
+ nls "usage: %s <device name>" "ifdown" >&2
exit 1
}
-[ -f "$CONFIG" ] || CONFIG=ifcfg-$CONFIG
-[ -f "$CONFIG" ] || {
- echo "usage: ifdown <device name>" >&2
- exit 1
-}
+if [ -f "/etc/sysconfig/interfaces/ifcfg-$DEV" ] ; then
+ CONFIG="/etc/sysconfig/interfaces/ifcfg-$DEV"
+else
+ CONFIG="$DEV"
+fi
-if [ `id -u` != 0 ]; then
- if [ -x /usr/sbin/usernetctl ]; then
- exec /usr/sbin/usernetctl $CONFIG down
+if [ "$(id -u)" != "0" ]; then
+ if [ -x /sbin/usernetctl ]; then
+ exec /sbin/usernetctl $CONFIG down
fi
echo "Users cannot control this device." >&2
exit 1
source_config
-DEVICETYPE=`echo $DEVICE | sed "s/[0-9]*$//"`
+# set all major variables
+setup_ip_param
+
OTHERSCRIPT="/etc/sysconfig/network-scripts/ifdown-${DEVICETYPE}"
+# shutdown tleds software
+if [ "$TLEDS_DEV" = "$DEVICE" -a -x /usr/bin/tleds ]; then
+ /usr/bin/tleds -qk "$DEVICE"
+fi
+
if [ -x $OTHERSCRIPT ]; then
- $OTHERSCRIPT $CONFIG $2
- exit $?
+ if [ "$HANDLING" = "0" ]; then
+ exec $OTHERSCRIPT $CONFIG $2
+ elif [ "$HANDLING" = "1" ]; then
+ $OTHERSCRIPT $CONFIG $2
+ RESULT=$?
+ if [ ${RESULT} -ne 0 ]; then
+ exit 1
+ fi
+ fi
fi
-if echo $DEVICE | grep -q ':' ; then
- ISALIAS=yes
-else
- ISALIAS=no
+# Check to make sure the device is actually up
+check_device_down && exit 0
+
+if [ "$BOOTMETHOD" = "bootp" -o "$BOOTMETHOD" = "pump" ]; then
+ /sbin/pump -r -i ${DEVICE}
+ RESULT=$?
fi
-if [ "$BOOTPROTO" = dhcp -a "$ISALIAS" = no ]; then
- if [ -f /var/run/dhcpcd-${DEVICE}.pid ]; then
- kill `cat /var/run/dhcpcd-${DEVICE}.pid`
- rm -f /var/run/dhcpcd-${DEVICE}.pid
- exit 0
+if [ "$BOOTMETHOD" = "dhcp" ]; then
+ if [ -x /sbin/dhcpcd ];then
+ if [ "foo$2" = "fooboot" -a -e /var/run/dhcpcd-${DEVICE}.pid ]; then
+ PID=$(cat /var/run/dhcpcd-${DEVICE}.pid)
+ if ps ax --no-header | grep -q $PID;then
+ kill -TERM $PID
+ RESULT=$?
+ fi
+ else
+ /sbin/dhcpcd -k ${DEVICE}
+ RESULT=$?
fi
- exit 1
+ elif [ -x /sbin/dhclient ];then
+ if [ -f /var/run/dhclient.pid ];then
+ PID=$(cat /var/run/dhclient.pid)
+ if ps ax --no-header|grep -q $PID;then
+ kill $PID
+ RESULT=$?
+ fi
+ fi
+ elif [ -x /sbin/dhcpxd ];then
+ /sbin/dhcpxd -k ${DEVICE}
+ RESULT=$?
+ elif [ -x /sbin/pump ];then
+ /sbin/pump -r -i ${DEVICE}
+ RESULT=$?
+ fi
+fi
+
+ip link set ${DEVICE} down
+ip addr flush dev ${DEVICE} 2>&1 | grep -v "Nothing to flush"
+
+# wait up to 5 seconds for device to actually come down...
+waited=0
+while ! check_device_down && [ "$waited" -lt 50 ] ; do
+ usleep 10000
+ waited=$(( ${waited} + 1 ))
+done
+
+if [ "$HANDLING" = "4" ]; then
+ exit 0
+fi
+
+if [ "$RESULT" != "0" ]; then
+ return $RESULT
fi
-ifconfig ${DEVICE} down
+# don't leave an outdated key sitting around
+if [ -n "${WIRELESS_ENC_KEY}" -a -x /sbin/iwconfig ]; then
+ /sbin/iwconfig ${DEVICE} enc 0 > /dev/null 2>&1
+fi
+
+exec /etc/sysconfig/network-scripts/ifdown-post ${CONFIG}
-exec /etc/sysconfig/network-scripts/ifdown-post $CONFIG
+# This must be last line !
+# vi:syntax=sh:tw=78:ts=8:sw=4