misc init.d cleanups
[openwrt.git] / target / default / target_skeleton / sbin / ifup
1 #!/bin/ash
2 . /etc/functions.sh
3 type=$1
4 debug "### ifup $type ###"
5
6 if=$(nvram get ${type}_ifname)
7 if [ "${if%%[0-9]}" = "ppp" ]; then
8   if=$(nvram get pppoe_ifname)
9 fi
10
11 if_valid $if || return
12
13 mac=$(nvram get ${type}_hwaddr)
14 $DEBUG ifconfig $if down 2>&-
15 if [ "${if%%[0-9]}" = "br" ]; then
16   stp=$(nvram get ${type}_stp)
17   $DEBUG brctl delbr $if 2>&-
18   $DEBUG brctl addbr $if
19   $DEBUG brctl setfd $if 0
20   $DEBUG brctl stp $if ${stp:-0}
21   for sif in $(nvram get ${type}_ifnames); do {
22     if_valid $sif || continue
23     ${mac:+$DEBUG ifconfig $sif down hw ether $mac}
24     $DEBUG ifconfig $sif 0.0.0.0 up
25     $DEBUG brctl addif $if $sif
26   } done
27 else
28   ${mac:+$DEBUG ifconfig $if down hw ether $mac}
29 fi
30
31
32 if_proto=$(nvram get ${type}_proto)
33 case "$if_proto" in
34   static)
35     ip=$(nvram get ${type}_ipaddr)
36     netmask=$(nvram get ${type}_netmask)
37     gateway=$(nvram get ${type}_gateway)
38
39     $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
40     ${gateway:+$DEBUG route add default gw $gateway}
41
42     [ -f /etc/resolv.conf ] && return
43
44     debug "# --- creating /etc/resolv.conf ---"
45     for dns in $(nvram get ${type}_dns); do {
46         echo "nameserver $dns" >> /etc/resolv.conf
47     } done
48   ;;
49   dhcp)
50     ip=$(nvram get ${type}_ipaddr)
51     pidfile=/tmp/dhcp-${type}.pid
52     if [ -f $pidfile ]; then
53       $DEBUG kill $(cat $pidfile)
54     fi
55     ${DEBUG:-eval} "udhcpc -R -i $if ${ip:+-r $ip} -b -p $pidfile &" 
56   ;;
57   none|"")
58   ;;
59   *)
60     [ -x "/sbin/ifup.${if_proto}" ] && { $DEBUG /sbin/ifup.${if_proto} $*; exit; }
61     echo "### ifup $type: ignored ${type}_proto=\"$if_proto\" (not supported)"
62   ;;
63 esac