]> git.pld-linux.org Git - projects/rc-scripts.git/blob - sysconfig/network-scripts/ifdown
- use $() for command substitution
[projects/rc-scripts.git] / sysconfig / network-scripts / ifdown
1 #!/bin/sh
2 #
3 #       $Id$
4 #
5 PATH=/sbin:/usr/sbin:/bin:/usr/bin
6
7 . /etc/sysconfig/network
8 . /etc/rc.d/init.d/functions
9 . /etc/sysconfig/network-scripts/functions.network
10
11 # Will be removed in the future
12 if is_yes "$NETWORKING" ; then
13         if [ -z "$IPV4_NETWORKING" ] ; then
14                 echo "NETWORKING is set to YES, but IPV4_NETWORKING is empty!"
15                 echo "Please upgrade your config"
16                 echo "Assuming you want IPv4 networking"
17                 IPV4_NETWORKING=yes
18         fi
19 fi
20
21 DEV=$1
22
23 [ -z "$DEV" ] && {
24         nls "Usage: %s <device name>" "ifdown" >&2
25         exit 1
26 }
27
28 if [ -f "/etc/sysconfig/interfaces/ifcfg-$DEV" ] ; then
29         CONFIG="/etc/sysconfig/interfaces/ifcfg-$DEV"
30 else
31         CONFIG="$DEV"
32 fi
33
34 if [ "$(id -u)" != "0" ]; then
35         if [ -x /sbin/usernetctl ]; then
36                 exec /sbin/usernetctl $CONFIG down
37         fi
38         echo "Users cannot control this device." >&2
39         exit 1
40 fi
41
42 source_config
43
44 # set all major variables
45 setup_ip_param
46
47 OTHERSCRIPT="/etc/sysconfig/network-scripts/ifdown-${DEVICETYPE}"
48
49 # shutdown tleds software
50 if [ "$TLEDS_DEV" = "$DEVICE" -a -x /usr/bin/tleds ]; then
51         /usr/bin/tleds -qk "$DEVICE"
52 fi
53
54 if [ -x $OTHERSCRIPT ]; then
55         if [ "$HANDLING" = "0" ]; then
56                 exec $OTHERSCRIPT $CONFIG $2
57         elif [ "$HANDLING" = "1" ]; then
58                 $OTHERSCRIPT $CONFIG $2
59         fi
60 fi
61
62 if [ -n "$BOOTPROTO" -a "$BOOTPROTO" != "none" -a "$BOOTPROTO" != "static" ]; then
63         if is_yes "$IPV4_NETWORKING"; then
64                 set_dhcpclient
65
66                 case ${DHCP_CLIENT##*/} in
67                   pump)
68                         $DHCP_CLIENT -r -i ${DEVICE}
69                         RESULT=$?
70                         ;;
71                   dhcpcd)
72                         $DHCP_CLIENT -k ${DEVICE}
73                         RESULT=$?
74                         sleep 1
75                         ;;
76                   dhcpxd)
77                         $DHCP_CLIENT -k ${DEVICE}
78                         RESULT=$?
79                         ;;
80                   dhclient)
81                         if [ -f /var/run/dhclient.pid ];then
82                                 PID=$(cat /var/run/dhclient.pid)
83                                 if ps ax --no-header | grep -q $PID; then
84                                         kill $PID
85                                         RESULT=$?
86                                 fi
87                         fi
88                         ;;
89                 esac
90         fi
91 fi
92
93 if is_wireless_device "${DEVICE}"; then
94         if is_yes "${WLAN_WPA}"; then
95                 killproc --pidfile "wpa_supplicant-${DEVICE}.pid" wpa_supplicant > /dev/null 2>&1
96                 rm -f "/var/run/wpa_supplicant-${DEVICE}.pid"
97         fi
98 fi
99
100 # Check to make sure the device is actually up
101 check_device_down && exit 0
102
103 vlan_setup
104 if is_yes $ETH_VLANS && $(echo $DEVICE | grep -q ^eth) ; then
105         if echo "${DEVICE}" | grep -q '\.' ; then
106                 # vlan down
107                 ip addr flush dev ${DEVICE} 2>&1 | grep -v "Nothing to flush"
108                 ip link set ${DEVICE} down
109                 /sbin/vconfig rem ${DEVICE} 2>&1 > /dev/null
110         else
111                 # downujemy interfejs nadrzedny do vlanow
112                 for VLANDEVICE in $(ls /proc/net/vlan 2> /dev/null | grep ^${DEVICE}) ; do
113                         # najpierw wszystkie vlany po kolei
114                         ip addr flush dev ${VLANDEVICE} 2>&1 | grep -v "Nothing to flush"
115                         ip link set ${VLANDEVICE} down
116                         /sbin/vconfig rem ${VLANDEVICE} 2>&1 > /dev/null
117                 done
118                 # a potem dopiero interfejs nadrzedny
119                 ip addr flush dev ${DEVICE} 2>&1 | grep -v "Nothing to flush"
120                 ip link set ${DEVICE} down
121         fi
122 else
123         ip addr flush dev ${DEVICE} 2>&1 | grep -v "Nothing to flush"
124         ip link set ${DEVICE} down
125 fi
126
127 if [ "$HANDLING" = "4" ]; then
128         exit 0
129 fi
130
131 if [ -n "$RESULT" ] ; then
132         if [ "$RESULT" -ne "0" ]; then
133                 return $RESULT
134         fi
135 fi
136
137 exec /etc/sysconfig/network-scripts/ifdown-post $CONFIG
138
139 # This must be last line !
140 # vi:syntax=sh
This page took 0.059273 seconds and 3 git commands to generate.