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" = "0.0.0.0" ]; then
62 $DEBUG route add
${opt:-"-net"} $1 netmask
$2 gw
$3 metric
$4
67 env
-i ACTION
="ifup" INTERFACE
="${iftype}" PROTO
=static
/sbin
/hotplug
"iface" &
70 DHCP_IP
=$
(nvram get
${iftype}_ipaddr
)
71 DHCP_NETMASK
=$
(nvram get
${iftype}_netmask
)
72 mtu
=$
(nvram get
${iftype}_mtu
)
73 $DEBUG ifconfig
$if $DHCP_IP ${DHCP_NETMASK:+netmask $DHCP_NETMASK} ${mtu:+mtu $(($mtu))} broadcast
+ up
75 DHCP_ARGS
="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile -t 0"
76 DHCP_HOSTNAME
=$
(nvram get
${iftype}_hostname
)
77 DHCP_HOSTNAME
=${DHCP_HOSTNAME%%.*}
78 [ -z $DHCP_HOSTNAME ] || DHCP_ARGS
="$DHCP_ARGS -H $DHCP_HOSTNAME"
79 [ "$(nvram get ${iftype}_proto)" = "pptp" ] && DHCP_ARGS
="$DHCP_ARGS -n -q" || DHCP_ARGS
="$DHCP_ARGS -R &"
80 [ -r $pidfile ] && oldpid
=$
(cat $pidfile 2>&-)
81 ${DEBUG:-eval} "udhcpc $DHCP_ARGS"
82 [ -n "$oldpid" ] && pidof udhcpc |
grep "$oldpid" >&- 2>&- && {
86 # hotplug events are handled by /usr/share/udhcpc/default.script
91 [ -x "/sbin/ifup.$ifproto" ] && { $DEBUG /sbin
/ifup.
$ifproto ${iftype}; exit; }
92 echo "### ifup ${iftype}: ignored ${iftype}_proto=\"$ifproto\" (not supported)"
104 env
-i ACTION
=$1 INTERFACE
=$2 /sbin
/hotplug net
112 eval "export -n -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
116 config_cb
() { return 0; }
117 option_cb
() { return 0; }
125 CONFIG_NUM_SECTIONS
=$
(($CONFIG_NUM_SECTIONS + 1))
126 name
="${name:-cfg$CONFIG_NUM_SECTIONS}"
127 append CONFIG_SECTIONS
"$name"
128 config_cb
"$cfgtype" "$name"
129 CONFIG_SECTION
="$name"
130 export -n "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
134 local varname
="$1"; shift
137 export -n "CONFIG_${CONFIG_SECTION}_${varname}=$value"
138 option_cb
"$varname" "$*"
147 [ "$OLD" -a "$NEW" ] ||
return
148 for oldvar
in `set | grep ^CONFIG_${OLD}_ | \
149 sed -e 's/\(.*\)=.*$/\1/'` ; do
150 newvar
="CONFIG_${NEW}_${oldvar##CONFIG_${OLD}_}"
151 eval "export -n \"$newvar=\${$oldvar}\""
154 CONFIG_SECTIONS
="$(echo " $CONFIG_SECTIONS " | sed -e "s
, $OLD , $NEW ,")"
156 [ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION
="$NEW"
160 config_set
"$1" "$2" ""
167 CONFIG_SECTIONS
="$(echo " $CONFIG_SECTIONS " | sed -e "s
, $OLD , ,")"
168 CONFIG_SECTIONS
="${SECTION:+$CONFIG_SECTIONS}"
170 for oldvar
in `set | grep ^CONFIG_${SECTION:+$SECTION_} | \
171 sed -e 's/\(.*\)=.*$/\1/'` ; do
177 local file="/etc/config/$1"
180 CONFIG_NUM_SECTIONS
=0
187 ${CONFIG_SECTION:+config_cb}
192 "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
193 *) eval "export -n -- \"$1=\${CONFIG_${2}_${3}}\"";;
201 export -n "CONFIG_${section}_${option}=$value"
208 [ -z "$CONFIG_SECTIONS" ] && return 0
209 for section
in ${CONFIG_SECTIONS}; do
210 eval "$function \"\$section\""
216 sed 's/^[^#]/insmod &/' $
* | ash
2>&- ||
:
222 for file in $
(ls $1/*.sh
2>/dev
/null
); do
228 local PART
="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
231 echo "${PART:+/dev/mtdblock/$PART}"
234 strtok
() { # <string> { <variable> [<separator>] ... }
241 while [ $# -gt 1 ]; do
244 [ "$tmp" = "$val" ] && break
248 export -n "$1=$tmp"; count
=$
((count
+1))
252 if [ $# -gt 0 -a "$val" ]; then
253 export -n "$1=$val"; count
=$
((count
+1))
262 [ -f "/proc/diag/led/$1" ] && echo "$state" > "/proc/diag/led/$1"