1 | #! /bin/sh |
---|
2 | ### BEGIN INIT INFO |
---|
3 | # Provides: robocfg |
---|
4 | # Required-Start: ifupdown-clean |
---|
5 | # Required-Stop: |
---|
6 | # Default-Start: S |
---|
7 | # Default-Stop: |
---|
8 | # Short-Description: Initialize vlan tagging on b44 ethernet switch with robocfg |
---|
9 | # Description: Initialize vlan tagging on b44 ethernet switch with robocfg |
---|
10 | # |
---|
11 | ### END INIT INFO |
---|
12 | |
---|
13 | # Author: Amain (DebWRT) <amain@debwrt.net> |
---|
14 | # |
---|
15 | |
---|
16 | PATH=/sbin:/usr/sbin:/bin:/usr/bin |
---|
17 | DESC="vlan tagging on b44 ethernet switch" |
---|
18 | NAME=robocfg |
---|
19 | SCRIPTNAME=/etc/init.d/$NAME |
---|
20 | |
---|
21 | # Load the VERBOSE setting and other rcS variables |
---|
22 | . /lib/init/vars.sh |
---|
23 | |
---|
24 | # Define LSB log_* functions. |
---|
25 | # Depend on lsb-base (>= 3.0-6) to ensure that this file is present. |
---|
26 | . /lib/lsb/init-functions |
---|
27 | |
---|
28 | . /etc/default/robocfg |
---|
29 | if [ ! $ENABLED -eq 1 ]; then exit 0; fi |
---|
30 | |
---|
31 | do_start() |
---|
32 | { |
---|
33 | if ( ls -l /etc/network/interfaces | grep firstboot >/dev/null ); then |
---|
34 | log_action_end_msg 1 |
---|
35 | echo "FIRSTBOOT - Please configure network in /etc/network first - robocfg did not configure switch" |
---|
36 | return |
---|
37 | fi |
---|
38 | |
---|
39 | # First set iface eth0 up, otherwist robocfg can't find the hardware |
---|
40 | /sbin/ifconfig eth0 up |
---|
41 | |
---|
42 | # Configure switch |
---|
43 | /usr/sbin/robocfg switch disable 2>/dev/null |
---|
44 | /usr/sbin/robocfg vlans enable reset 2>/dev/null |
---|
45 | /usr/sbin/robocfg vlan 100 ports "0 5t" 2>/dev/null |
---|
46 | /usr/sbin/robocfg vlan 101 ports "1 2 3 4 5t" 2>/dev/null |
---|
47 | /usr/sbin/robocfg port 0 state enabled stp none 2>/dev/null # on some routers it seems that this iface is not up by default |
---|
48 | /usr/sbin/robocfg switch enable 2>/dev/null |
---|
49 | |
---|
50 | # Configure vlans |
---|
51 | /sbin/vconfig add eth0 100 1>/dev/null |
---|
52 | /sbin/vconfig add eth0 101 1>/dev/null |
---|
53 | |
---|
54 | # Configure nice names |
---|
55 | /sbin/ip link set dev eth0.100 name eth0_wan |
---|
56 | /sbin/ip link set dev eth0.101 name eth0_lan |
---|
57 | |
---|
58 | log_action_end_msg 0 |
---|
59 | } |
---|
60 | |
---|
61 | do_stop() |
---|
62 | { |
---|
63 | if ( ls -l /etc/network/interfaces | grep firstboot >/dev/null ); then |
---|
64 | log_action_end_msg 1 |
---|
65 | echo "FIRSTBOOT - Please configure network in /etc/network first - robocfg did not configure switch" |
---|
66 | return |
---|
67 | fi |
---|
68 | |
---|
69 | /sbin/vconfig rem eth0_wan 1>/dev/null |
---|
70 | /sbin/vconfig rem eth0_lan 1>/dev/null |
---|
71 | /usr/sbin/robocfg switch disable vlans enable reset vlan 1 ports "0 5u" vlan 0 ports "1 2 3 4 5u" port 0 state enabled stp none switch enable 2>/dev/null |
---|
72 | } |
---|
73 | |
---|
74 | VERBOSE=yes |
---|
75 | case "$1" in |
---|
76 | start) |
---|
77 | log_action_begin_msg "Initializing $DESC: $NAME" |
---|
78 | do_start |
---|
79 | ;; |
---|
80 | stop) |
---|
81 | log_action_begin_msg "Stopping $DESC: $NAME" |
---|
82 | do_stop |
---|
83 | ;; |
---|
84 | *) |
---|
85 | echo "Usage: $SCRIPTNAME {start}" >&2 |
---|
86 | exit 3 |
---|
87 | ;; |
---|
88 | esac |
---|