script/ethercat.sh
branchstable-1.2
changeset 1739 5fcbd29151d2
parent 1723 492767ba685a
equal deleted inserted replaced
1738:bc89e3fba1a5 1739:5fcbd29151d2
    47 # Description:
    47 # Description:
    48 ### END INIT INFO
    48 ### END INIT INFO
    49 
    49 
    50 #------------------------------------------------------------------------------
    50 #------------------------------------------------------------------------------
    51 
    51 
       
    52 IFCONFIG=ifconfig
       
    53 BRCTL=brctl
       
    54 ROUTE=route
       
    55 
       
    56 #------------------------------------------------------------------------------
       
    57 
    52 ETHERCAT_CONFIG=/etc/sysconfig/ethercat
    58 ETHERCAT_CONFIG=/etc/sysconfig/ethercat
    53 
    59 
    54 if [ ! -r $ETHERCAT_CONFIG ]; then
    60 if [ ! -r $ETHERCAT_CONFIG ]; then
    55     echo "$ETHERCAT_CONFIG not existing";
    61     echo "$ETHERCAT_CONFIG not existing";
    56     if [ "$1" = "stop" ]; then
    62     if [ "$1" = "stop" ]; then
    69 #
    75 #
    70 build_eoe_bridge()
    76 build_eoe_bridge()
    71 {
    77 {
    72     if [ -z "$EOE_BRIDGE" ]; then return; fi
    78     if [ -z "$EOE_BRIDGE" ]; then return; fi
    73 
    79 
    74     EOEIF=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "`
    80     EOEIF=`$IFCONFIG -a | grep -o -E "^eoe[0-9]+ "`
    75 
    81 
    76     # add bridge, if it does not already exist
    82     # add bridge, if it does not already exist
    77     if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then
    83     if ! $BRCTL show | grep -E -q "^$EOE_BRIDGE"; then
    78 	if ! /sbin/brctl addbr $EOE_BRIDGE; then
    84         if ! $BRCTL addbr $EOE_BRIDGE; then
    79 	    /bin/false
    85 	    /bin/false
    80 	    rc_status -v
    86 	    rc_status -v
    81 	    rc_exit
    87 	    rc_exit
    82 	fi
    88 	fi
    83     fi
    89     fi
    84 
    90 
    85     # check if specified interfaces are bridged
    91     # check if specified interfaces are bridged
    86     for interf in $EOEIF $EOE_EXTRA_INTERFACES; do
    92     for interf in $EOEIF $EOE_EXTRA_INTERFACES; do
    87 	# interface is already part of the bridge
    93 	# interface is already part of the bridge (FIXME->show $EOE_BRIDGE)
    88 	if /sbin/brctl show $EOE_BRIDGE | grep -E -q $interf
    94 	if $BRCTL show | grep -E -q $interf
    89 	    then continue
    95 	    then continue
    90 	fi
    96 	fi
    91 	# clear IP address and open interface
    97 	# clear IP address and open interface
    92 	if ! /sbin/ifconfig $interf 0.0.0.0 up; then
    98 	if ! $IFCONFIG $interf 0.0.0.0 up; then
    93 	    /bin/false
    99 	    /bin/false
    94 	    rc_status -v
   100 	    rc_status -v
    95 	    rc_exit
   101 	    rc_exit
    96 	fi
   102 	fi
    97 	# add interface to the bridge
   103 	# add interface to the bridge
    98 	if ! /sbin/brctl addif $EOE_BRIDGE $interf; then
   104 	if ! $BRCTL addif $EOE_BRIDGE $interf; then
    99 	    /bin/false
   105 	    /bin/false
   100 	    rc_status -v
   106 	    rc_status -v
   101 	    rc_exit
   107 	    rc_exit
   102 	fi
   108 	fi
   103     done
   109     done
   104 
   110 
   105     # configure IP on bridge
   111     # configure IP on bridge
   106     if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then
   112     if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then
   107 	if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \
   113 	if ! $IFCONFIG $EOE_BRIDGE $EOE_IP_ADDRESS \
   108 	    netmask $EOE_IP_NETMASK; then
   114 	    netmask $EOE_IP_NETMASK; then
   109 	    /bin/false
   115 	    /bin/false
   110 	    rc_status -v
   116 	    rc_status -v
   111 	    rc_exit
   117 	    rc_exit
   112 	fi
   118 	fi
   113     fi
   119     fi
   114 
   120 
   115     # open bridge
   121     # open bridge
   116     if ! /sbin/ifconfig $EOE_BRIDGE up; then
   122     if ! $IFCONFIG $EOE_BRIDGE up; then
   117 	/bin/false
   123 	/bin/false
   118 	rc_status -v
   124 	rc_status -v
   119 	rc_exit
   125 	rc_exit
   120     fi
   126     fi
   121 
   127 
   122     # install new default gateway
   128     # install new default gateway
   123     if [ -n "$EOE_GATEWAY" ]; then
   129     if [ -n "$EOE_GATEWAY" ]; then
   124 	while /sbin/route -n | grep -E -q "^0.0.0.0"; do
   130 	while $ROUTE -n | grep -E -q "^0.0.0.0"; do
   125 	    if ! /sbin/route del default; then
   131 	    if ! $ROUTE del default; then
   126 		echo "Failed to remove route!" 1>&2
   132 		echo "Failed to remove route!" 1>&2
   127 		/bin/false
   133 		/bin/false
   128 		rc_status -v
   134 		rc_status -v
   129 		rc_exit
   135 		rc_exit
   130 	    fi
   136 	    fi
   131 	done
   137 	done
   132 	if ! /sbin/route add default gw $EOE_GATEWAY; then
   138 	if ! $ROUTE add default gw $EOE_GATEWAY; then
   133 	    /bin/false
   139 	    /bin/false
   134 	    rc_status -v
   140 	    rc_status -v
   135 	    rc_exit
   141 	    rc_exit
   136 	fi
   142 	fi
   137     fi
   143     fi