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