2 # Copyright (C) 2006 OpenWrt.org
3 # Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
5 alias debug
=${DEBUG:-:}
9 ifconfig
"$1" >&- 2>&- ||
10 [ "${1%%[0-9]}" = "br" ] ||
12 [ "${1%%[0-9]*}" = "vlan" ] && (
14 hwname
=$
(nvram get vlan
${i}hwname
)
15 hwaddr
=$
(nvram get
${hwname}macaddr
)
16 [ -z "$hwaddr" ] && return 1
18 vif
=$
(ifconfig
-a |
awk '/^eth.*'$hwaddr'/ {print $1; exit}' IGNORECASE
=1)
19 debug
"# vlan$i => $vif"
20 [ -n "$vif" ] || vif
=$
(ifconfig
-a |
awk '/^eth'${hw##et}'/ {print $1; exit}' IGNORECASE
=1)
22 $DEBUG ifconfig
$vif up
23 $DEBUG vconfig add
$vif $i 2>&-
26 { debug
"# missing interface '$1' ignored"; false
; }
32 if="$(nvram get ${iftype}_ifname)"
33 [ "${if%%[0-9]}" = "ppp" ] && if="$(nvram get ${iftype}_device)"
35 pidfile
=/var
/run
/${if}.pid
36 [ -f $pidfile ] && $DEBUG kill $
(cat $pidfile)
40 ip
=$
(nvram get
${iftype}_ipaddr
)
41 netmask
=$
(nvram get
${iftype}_netmask
)
42 gateway
=$
(nvram get
${iftype}_gateway
)
43 mtu
=$
(nvram get
${iftype}_mtu
)
44 static_route
=$
(nvram get
${iftype}_static_route
)
46 $DEBUG ifconfig
$if $ip ${netmask:+netmask $netmask} ${mtu:+mtu $(($mtu))} broadcast
+ up
47 ${gateway:+$DEBUG route add default gw $gateway}
49 [ -f /tmp
/resolv.conf.auto
] ||
{
50 debug
"# --- creating /tmp/resolv.conf.auto ---"
51 for dns
in $
(nvram get
${iftype}_dns
); do
52 echo "nameserver $dns" >> /tmp
/resolv.conf.auto
56 [ -n "$static_route" ] && {
57 for route
in $static_route; do {
58 eval "set $(echo $route | sed 's/:/ /g')"
59 if [ "$2" = "255.255.255.255" ]; then
62 $DEBUG route add
${opt:-"-net"} $1 netmask
$2 gw
$3 metric
$4
66 env
-i ACTION
="ifup" INTERFACE
="${iftype}" PROTO
=static
/sbin
/hotplug
"iface" &
69 DHCP_IP
=$
(nvram get
${iftype}_ipaddr
)
70 DHCP_NETMASK
=$
(nvram get
${iftype}_netmask
)
71 mtu
=$
(nvram get
${iftype}_mtu
)
72 $DEBUG ifconfig
$if $DHCP_IP ${DHCP_NETMASK:+netmask $DHCP_NETMASK} ${mtu:+mtu $(($mtu))} broadcast
+ up
74 DHCP_ARGS
="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile -t 0"
75 DHCP_HOSTNAME
=$
(nvram get
${iftype}_hostname
)
76 DHCP_HOSTNAME
=${DHCP_HOSTNAME%%.*}
77 [ -z $DHCP_HOSTNAME ] || DHCP_ARGS
="$DHCP_ARGS -H $DHCP_HOSTNAME"
78 [ "$(nvram get ${iftype}_proto)" = "pptp" ] && DHCP_ARGS
="$DHCP_ARGS -n -q" || DHCP_ARGS
="$DHCP_ARGS -R &"
79 [ -r $pidfile ] && oldpid
=$
(cat $pidfile 2>&-)
80 ${DEBUG:-eval} "udhcpc $DHCP_ARGS"
81 [ -n "$oldpid" ] && pidof udhcpc |
grep "$oldpid" >&- 2>&- && {
85 # hotplug events are handled by /usr/share/udhcpc/default.script
90 [ -x "/sbin/ifup.$ifproto" ] && { $DEBUG /sbin
/ifup.
$ifproto ${iftype}; exit; }
91 echo "### ifup ${iftype}: ignored ${iftype}_proto=\"$ifproto\" (not supported)"
103 env
-i ACTION
=$1 INTERFACE
=$2 /sbin
/hotplug net
111 eval "export -n -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
115 config_cb
() { return 0; }
116 option_cb
() { return 0; }
124 CONFIG_NUM_SECTIONS
=$
(($CONFIG_NUM_SECTIONS + 1))
125 name
="${name:-cfg$CONFIG_NUM_SECTIONS}"
126 append CONFIG_SECTIONS
"$name"
127 config_cb
"$cfgtype" "$name"
128 CONFIG_SECTION
="$name"
129 export -n "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
133 local varname
="$1"; shift
136 export -n "CONFIG_${CONFIG_SECTION}_${varname}=$value"
137 option_cb
"$varname" "$*"
146 [ "$OLD" -a "$NEW" ] ||
return
147 for oldvar
in `set | grep ^CONFIG_${OLD}_ | \
148 sed -e 's/\(.*\)=.*$/\1/'` ; do
149 newvar
="CONFIG_${NEW}_${oldvar##CONFIG_${OLD}_}"
150 eval "export -n \"$newvar=\${$oldvar}\""
153 CONFIG_SECTIONS
="$(echo " $CONFIG_SECTIONS " | sed -e "s
, $OLD , $NEW ,")"
155 [ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION
="$NEW"
159 config_set
"$1" "$2" ""
166 CONFIG_SECTIONS
="$(echo " $CONFIG_SECTIONS " | sed -e "s
, $OLD , ,")"
167 CONFIG_SECTIONS
="${SECTION:+$CONFIG_SECTIONS}"
169 for oldvar
in `set | grep ^CONFIG_${SECTION:+$SECTION_} | \
170 sed -e 's/\(.*\)=.*$/\1/'` ; do
176 local file="/etc/config/$1"
179 CONFIG_NUM_SECTIONS
=0
186 ${CONFIG_SECTION:+config_cb}
191 "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
192 *) eval "export -n -- \"$1=\${CONFIG_${2}_${3}}\"";;
200 export -n "CONFIG_${section}_${option}=$value"
207 [ -z "$CONFIG_SECTIONS" ] && return 0
208 for section
in ${CONFIG_SECTIONS}; do
209 eval "$function \"\$section\""
215 sed 's/^[^#]/insmod &/' $
* | ash
2>&- ||
:
221 for file in $
(ls $1/*.sh
2>/dev
/null
); do
227 local PART
="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
230 echo "${PART:+/dev/mtdblock/$PART}"
233 strtok
() { # <string> { <variable> [<separator>] ... }
240 while [ $# -gt 1 ]; do
243 [ "$tmp" = "$val" ] && break
247 export -n "$1=$tmp"; count
=$
((count
+1))
251 if [ $# -gt 0 -a "$val" ]; then
252 export -n "$1=$val"; count
=$
((count
+1))
261 [ -f "/proc/diag/led/$1" ] && echo "$state" > "/proc/diag/led/$1"