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"
21 $DEBUG ifconfig
$vif up
22 $DEBUG vconfig add
$vif $i 2>&-
25 { debug
"# missing interface '$1' ignored"; false
; }
29 if_proto
=$
(nvram get
${2}_proto
)
30 if=$
(nvram get
${2}_ifname
)
31 [ "${if%%[0-9]}" = "ppp" ] && if=$
(nvram get
${2}_device
)
33 pidfile
=/var
/run
/${if}.pid
34 [ -f $pidfile ] && $DEBUG kill $
(cat $pidfile)
38 ip
=$
(nvram get
${2}_ipaddr
)
39 netmask
=$
(nvram get
${2}_netmask
)
40 gateway
=$
(nvram get
${2}_gateway
)
41 mtu
=$
(nvram get
${2}_mtu
)
42 static_route
=$
(nvram get
${2}_static_route
)
44 $DEBUG ifconfig
$if $ip ${netmask:+netmask $netmask} ${mtu:+mtu $(($mtu))} broadcast
+ up
45 ${gateway:+$DEBUG route add default gw $gateway}
47 [ -n "$static_route" ] && {
48 for route
in $static_route; do {
49 eval "set $(echo $route | sed 's/:/ /g')"
50 if [ "$2" = "255.255.255.255" ]; then
53 $DEBUG route add
${opt:-"-net"} $1 netmask
$2 gw
$3 metric
$4
57 [ -f /tmp
/resolv.conf.auto
] ||
{
58 debug
"# --- creating /tmp/resolv.conf.auto ---"
59 for dns
in $
(nvram get
${2}_dns
); do
60 echo "nameserver $dns" >> /tmp
/resolv.conf.auto
64 env
-i ACTION
="ifup" INTERFACE
="${2}" PROTO
=static
/sbin
/hotplug
"iface" &
67 DHCP_IP
=$
(nvram get
${2}_ipaddr
)
68 DHCP_NETMASK
=$
(nvram get
${2}_netmask
)
69 mtu
=$
(nvram get
${2}_mtu
)
70 $DEBUG ifconfig
$if $DHCP_IP ${DHCP_NETMASK:+netmask $DHCP_NETMASK} ${mtu:+mtu $(($mtu))} broadcast
+ up
72 DHCP_ARGS
="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile -t 0"
73 DHCP_HOSTNAME
=$
(nvram get
${2}_hostname
)
74 DHCP_HOSTNAME
=${DHCP_HOSTNAME%%.*}
75 [ -z $DHCP_HOSTNAME ] || DHCP_ARGS
="$DHCP_ARGS -H $DHCP_HOSTNAME"
76 [ "$if_proto" = "pptp" ] && DHCP_ARGS
="$DHCP_ARGS -n -q" || DHCP_ARGS
="$DHCP_ARGS -R &"
77 [ -r $pidfile ] && oldpid
=$
(cat $pidfile 2>&-)
78 ${DEBUG:-eval} "udhcpc $DHCP_ARGS"
79 [ -n "$oldpid" ] && pidof udhcpc |
grep "$oldpid" >&- 2>&- && {
83 # hotplug events are handled by /usr/share/udhcpc/default.script
88 [ -x "/sbin/ifup.$1" ] && { $DEBUG /sbin
/ifup.
$1 ${2}; exit; }
89 echo "### ifup ${2}: ignored ${2}_proto=\"$1\" (not supported)"
101 env
-i ACTION
=$1 INTERFACE
=$2 /sbin
/hotplug net
109 eval "export -n -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
113 config_cb
() { return 0; }
114 option_cb
() { return 0; }
122 CONFIG_NUM_SECTIONS
=$
(($CONFIG_NUM_SECTIONS + 1))
123 name
="${name:-cfg$CONFIG_NUM_SECTIONS}"
124 append CONFIG_SECTIONS
"$name"
125 config_cb
"$cfgtype" "$name"
126 CONFIG_SECTION
="$name"
127 export -n "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
131 local varname
="$1"; shift
134 export -n "CONFIG_${CONFIG_SECTION}_${varname}=$value"
135 option_cb
"$varname" "$*"
144 [ "$OLD" -a "$NEW" ] ||
return
145 for oldvar
in `set | grep ^CONFIG_${OLD}_ | \
146 sed -e 's/\(.*\)=.*$/\1/'` ; do
147 newvar
="CONFIG_${NEW}_${oldvar##CONFIG_${OLD}_}"
148 eval "export -n \"$newvar=\${$oldvar}\""
151 CONFIG_SECTIONS
="$(echo " $CONFIG_SECTIONS " | sed -e "s
, $OLD , $NEW ,")"
153 [ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION
="$NEW"
157 config_set
"$1" "$2" ""
164 CONFIG_SECTIONS
="$(echo " $CONFIG_SECTIONS " | sed -e "s
, $OLD , ,")"
165 CONFIG_SECTIONS
="${SECTION:+$CONFIG_SECTIONS}"
167 for oldvar
in `set | grep ^CONFIG_${SECTION:+$SECTION_} | \
168 sed -e 's/\(.*\)=.*$/\1/'` ; do
174 local file="/etc/config/$1"
177 CONFIG_NUM_SECTIONS
=0
184 ${CONFIG_SECTION:+config_cb}
189 "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
190 *) eval "export -n -- \"$1=\${CONFIG_${2}_${3}}\"";;
198 export -n "CONFIG_${section}_${option}=$value"
205 [ -z "$CONFIG_SECTIONS" ] && return 0
206 for section
in ${CONFIG_SECTIONS}; do
207 eval "$function \"\$section\""
213 sed 's/^[^#]/insmod &/' $
* | ash
2>&- ||
:
219 for file in $
(ls $1/*.sh
2>/dev
/null
); do
225 local PART
="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
228 echo "${PART:+/dev/mtdblock/$PART}"
231 strtok
() { # <string> { <variable> [<separator>] ... }
238 while [ $# -gt 1 ]; do
241 [ "$tmp" = "$val" ] && break
245 export -n "$1=$tmp"; count
=$
((count
+1))
249 if [ $# -gt 0 -a "$val" ]; then
250 export -n "$1=$val"; count
=$
((count
+1))
259 [ -f "/proc/diag/led/$1" ] && echo "$state" > "/proc/diag/led/$1"