blob: 0400e69f9ee19f0547c95a53412bb0f4ccf6b5ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
# This is not a shell script; it provides functions to network scripts
# that source it.
source_config ()
{
DEVNAME=`basename $CONFIG | sed 's/^ifcfg-//g'`
if basename $CONFIG | grep '[^g]-' >/dev/null 2>&1 ; then
PARENTCONFIG=`echo $CONFIG | sed 's/-[^-]*$//g'`
PARENTDEVNAME=`basename $PARENTCONFIG | sed 's/^ifcfg-//g'`
[ -f $PARENTCONFIG ] || {
echo "Missing config file $PARENTCONFIG." >&2
exit 1
}
. $PARENTCONFIG
fi
. $CONFIG
}
toggle_value()
{
if [ -z "$2" ]
then
echo ''
elif [ "$2" = "yes" -o "$2" = "YES" ] ; then
echo "$1 on"
elif [ "$2" = "no" -o "$2" = "NO" ] ; then
echo "$1 off"
else
echo ''
fi
}
do_netreport ()
{
# Notify programs that have requested notification
( cd /var/run/netreport || exit
for i in * ; do
if [ -f $i ]; then
OWNER=`ls -l $i | awk '{ print $3 }'`
su $OWNER -c "kill -SIGIO $i >/dev/null 2>&1 || rm -f $i >/dev/null 2>&1" > /dev/null 2>&1
fi
done
)
}
need_hostname()
{
if [ "`hostname`" = "(none)" -o "`hostname`" = "localhost" -o \
"`hostname`" = "localhost.localdomain" ]; then
NEEDHOSTNAME=yes
else
unset NEEDHOSTNAME
fi
}
set_hostname()
{
hostname $1
if ! grep search /etc/resolv.conf >/dev/null 2>&1; then
domain=`echo $1 | sed 's/^[^\.]*\.//'`
echo "search $domain" >> /etc/resolv.conf
fi
}
check_device_down ()
{
if echo $1 | grep -q ':' ; then
if LANG=C ifconfig -a 2>/dev/null | grep -q $1 ; then
retcode=1
else
retcode=0
fi
else
if LANG=C ip -o link ls dev $1 2>/dev/null | grep ",UP" >/dev/null 2>&1 ; then
retcode=1
else
retcode=0
fi
fi
return $retcode
}
check_link_down ()
{
if [ -x /sbin/mii-tool ]; then
output=`/sbin/mii-tool $1 2>&1`
if echo $output | grep -q "Operation not supported"; then
return 1
elif echo $output | grep -q "link ok"; then
return 1
else
return 0
fi
fi
return 0
}
check_default_route ()
{
ip route | grep -q default
}
find_gateway_dev ()
{
. /etc/sysconfig/network
if [ "${GATEWAY}" != "" -a "${GATEWAY}" != "none" ] ; then
export GATEWAY
networks=`/sbin/route -n|awk '{print $1, ENVIRON["GATEWAY"],$3,$8}'|awk '{system("ipcalc --silent --network "$2" "$3" 2>/dev/null")}'|sed s^NETWORK=^^g`
for net in $networks; do
dev=`/sbin/route -n|grep ^$net|awk '{print $NF}'`
if [ "$dev" != "" ] ; then
GATEWAYDEV=$dev
fi
done
fi
}
add_default_route ()
{
. /etc/sysconfig/network
find_gateway_dev
if [ "${GATEWAY}" != "" -a "${GATEWAY}" != "none" -a "${GATEWAYDEV}" != "" ] ; then
if ! check_device_down $1; then
if [ "$GATEWAY" = "0.0.0.0" ]; then
/sbin/route add default ${GATEWAYDEV}
else
/sbin/route add default gw ${GATEWAY} ${GATEWAYDEV}
fi
fi
fi
}
is_wireless_device ()
{
if [ -x /sbin/iwconfig ]; then
iwconfig $1 2>&1 | grep -q -v "no wireless extensions"
return $?
else
return 1
fi
}
current_profile ()
{
if [ "${CURRENT_PROFILE}" != "" ]; then
echo ${CURRENT_PROFILE}
elif [ "${DEFAULT_PROFILE}" != "" ]; then
echo ${DEFAULT_PROFILE}
else
echo "default"
fi
}
|