script/ethercat.sh
author Florian Pose <fp@igh-essen.com>
Tue, 07 Nov 2006 13:38:40 +0000
changeset 489 25028ca10fdb
parent 361 29af81543ce1
child 503 e84388b86c38
permissions -rwxr-xr-x
Updated source code documentation.
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     1
#!/bin/sh
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     2
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     3
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     4
#
247
d1f0cff6f57f Minor changes in init script.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
     5
#  Init script for EtherCAT
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     6
#
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     7
#  $Id$
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     8
#
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
     9
#  Copyright (C) 2006  Florian Pose, Ingenieurgemeinschaft IgH
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    10
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    11
#  This file is part of the IgH EtherCAT Master.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    12
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    13
#  The IgH EtherCAT Master is free software; you can redistribute it
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    14
#  and/or modify it under the terms of the GNU General Public License
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    15
#  as published by the Free Software Foundation; either version 2 of the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    16
#  License, or (at your option) any later version.
197
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    17
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    18
#  The IgH EtherCAT Master is distributed in the hope that it will be
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    19
#  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    20
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    21
#  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    22
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    23
#  You should have received a copy of the GNU General Public License
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    24
#  along with the IgH EtherCAT Master; if not, write to the Free Software
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    25
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    26
#
246
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    27
#  The right to use EtherCAT Technology is granted and comes free of
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    28
#  charge under condition of compatibility of product made by
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    29
#  Licensee. People intending to distribute/sell products based on the
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    30
#  code, have to sign an agreement to guarantee that products using
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    31
#  software based on IgH EtherCAT master stay compatible with the actual
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    32
#  EtherCAT specification (which are released themselves as an open
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    33
#  standard) as the (only) precondition to have the right to use EtherCAT
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    34
#  Technology, IP and trade marks.
0bf7c769de06 Changed license headers and added EtherCAT license notice.
Florian Pose <fp@igh-essen.com>
parents: 245
diff changeset
    35
#
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    36
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    37
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    38
### BEGIN INIT INFO
248
f5e94773472d Minor changes in init script 2.
Florian Pose <fp@igh-essen.com>
parents: 247
diff changeset
    39
# Provides:          ethercat
245
100a0c3f5e6e Added dependencies to RC script.
Florian Pose <fp@igh-essen.com>
parents: 244
diff changeset
    40
# Required-Start:    $local_fs $syslog $network
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
    41
# Should-Start:      $time ntp
245
100a0c3f5e6e Added dependencies to RC script.
Florian Pose <fp@igh-essen.com>
parents: 244
diff changeset
    42
# Required-Stop:     $local_fs $syslog $network
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
    43
# Should-Stop:       $time ntp
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    44
# Default-Start:     3 5
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    45
# Default-Stop:      0 1 2 6
247
d1f0cff6f57f Minor changes in init script.
Florian Pose <fp@igh-essen.com>
parents: 246
diff changeset
    46
# Short-Description: IgH EtherCAT master modules
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    47
# Description:
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    48
### END INIT INFO
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
    52
device="ecxml"
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
    53
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
    54
#------------------------------------------------------------------------------
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
    55
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    56
ETHERCAT_CONFIG=/etc/sysconfig/ethercat
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
    58
if [ ! -r $ETHERCAT_CONFIG ]; then
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    59
    echo "$ETHERCAT_CONFIG not existing";
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    60
    if [ "$1" = "stop" ]; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    61
	exit 0
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    62
    else
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    63
	exit 6
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    64
    fi
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
    65
fi
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    66
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
    67
. $ETHERCAT_CONFIG
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
289
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
    71
#
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
    72
#  Function for setting up the EoE bridge
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
    73
#
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
    74
build_eoe_bridge()
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
    75
{
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    76
    if [ -z "$EOE_BRIDGE" ]; then return; fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    77
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    78
    EOEIF=`/sbin/ifconfig -a | grep -o -E "^eoe[0-9]+ "`
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    79
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    80
    # add bridge, if it does not already exist
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    81
    if ! /sbin/brctl show | grep -E -q "^$EOE_BRIDGE"; then
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
    82
        if ! /sbin/brctl addbr $EOE_BRIDGE; then
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    83
	    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    84
	    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    85
	    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    86
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    87
    fi
289
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
    88
321
64e20e6e9d0b Renamed master parameter ec_eoe_devices to ec_eoeif_count.
Florian Pose <fp@igh-essen.com>
parents: 299
diff changeset
    89
    # check if specified interfaces are bridged
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    90
    for interf in $EOEIF $EOE_EXTRA_INTERFACES; do
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    91
	# interface is already part of the bridge
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    92
	if /sbin/brctl show $EOE_BRIDGE | grep -E -q $interf
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    93
	    then continue
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    94
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    95
	# clear IP address and open interface
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    96
	if ! /sbin/ifconfig $interf 0.0.0.0 up; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    97
	    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    98
	    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
    99
	    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   100
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   101
	# add interface to the bridge
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   102
	if ! /sbin/brctl addif $EOE_BRIDGE $interf; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   103
	    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   104
	    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   105
	    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   106
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   107
    done
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   108
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   109
    # configure IP on bridge
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   110
    if [ -n "$EOE_IP_ADDRESS" -a -n "$EOE_IP_NETMASK" ]; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   111
	if ! /sbin/ifconfig $EOE_BRIDGE $EOE_IP_ADDRESS \
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   112
	    netmask $EOE_IP_NETMASK; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   113
	    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   114
	    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   115
	    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   116
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   117
    fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   118
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   119
    # open bridge
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   120
    if ! /sbin/ifconfig $EOE_BRIDGE up; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   121
	/bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   122
	rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   123
	rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   124
    fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   125
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   126
    # install new default gateway
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   127
    if [ -n "$EOE_GATEWAY" ]; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   128
	while /sbin/route -n | grep -E -q "^0.0.0.0"; do
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   129
	    if ! /sbin/route del default; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   130
		echo "Failed to remove route!" 1>&2
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
   131
		/bin/false
289
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   132
		rc_status -v
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   133
		rc_exit
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   134
	    fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   135
	done
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   136
	if ! /sbin/route add default gw $EOE_GATEWAY; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   137
	    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   138
	    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   139
	    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   140
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   141
    fi
289
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   142
}
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   143
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   144
#------------------------------------------------------------------------------
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   145
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   146
. /etc/rc.status
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   147
rc_reset
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   148
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   149
case "$1" in
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
   150
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   151
    start)
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   152
	echo -n "Starting EtherCAT master "
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   153
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   154
	if [ -z "$DEVICE_INDEX" ]; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   155
	    echo "ERROR: DEVICE_INDEX not set!"
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   156
	    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   157
	    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   158
	    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   159
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   160
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   161
	if [ -z "$EOE_INTERFACES" ]; then
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   162
            # support legacy sysconfig files
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   163
	    if [ -n "$EOE_DEVICES" ]; then
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   164
		EOE_INTERFACES=$EOE_DEVICES
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   165
	    else
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   166
		EOE_INTERFACES=0
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   167
	    fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   168
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   169
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   170
        # unload conflicting modules at first
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   171
	for mod in 8139too; do
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   172
	    if lsmod | grep "^$mod " > /dev/null; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   173
		if ! rmmod $mod; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   174
		    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   175
		    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   176
		    rc_exit
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
   177
		fi
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   178
	    fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   179
	done
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   180
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   181
        # load master module
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   182
	if ! modprobe ec_master ec_eoeif_count=$EOE_INTERFACES; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   183
	    modprobe 8139too
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   184
	    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   185
	    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   186
	    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   187
	fi
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
   188
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   189
	# remove stale device node
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   190
	rm -f /dev/${device}0
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   191
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   192
	# get dynamic major number
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   193
	major=$(awk "\$2==\"EtherCAT\" {print \$1}" /proc/devices)
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   194
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   195
	# create character device
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   196
	mknod /dev/${device}0 c $major 0
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   197
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   198
	# load device module
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   199
	if ! modprobe ec_8139too ec_device_index=$DEVICE_INDEX; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   200
	    rmmod ec_master
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   201
	    modprobe 8139too
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   202
	    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   203
	    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   204
	    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   205
	fi
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
   206
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   207
	# build EoE bridge
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   208
	build_eoe_bridge
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   209
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   210
	rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   211
	;;
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
   212
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   213
    stop)
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   214
	echo -n "Shutting down EtherCAT master "
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   215
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   216
	# unload modules
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   217
	for mod in ec_8139too ec_master; do
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   218
	    if lsmod | grep "^$mod " > /dev/null; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   219
		if ! rmmod $mod; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   220
		    /bin/false
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   221
		    rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   222
		    rc_exit
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   223
		fi;
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   224
	    fi;
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   225
	done
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   226
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   227
	# remove device node
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   228
	rm -f /dev/${device}0
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   229
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   230
	sleep 1
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   231
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   232
	# reload previous modules
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   233
	if ! modprobe 8139too; then
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   234
	    echo "Warning: Failed to restore 8139too module."
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   235
	fi
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   236
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   237
	rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   238
	;;
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
   239
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   240
    restart)
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   241
	$0 stop || exit 1
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   242
	sleep 1
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   243
	$0 start
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   244
	rc_status
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   245
	;;
244
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   246
c302a846ab12 Added status function to RC script.
Florian Pose <fp@igh-essen.com>
parents: 243
diff changeset
   247
    status)
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   248
	echo -n "Checking for EtherCAT "
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   249
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   250
	lsmod | grep "^ec_master " > /dev/null
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   251
	master_running=$?
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   252
	lsmod | grep "^ec_8139too " > /dev/null
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   253
	device_running=$?
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   254
361
29af81543ce1 Introduced per-master character devices for XML descriptions.
Florian Pose <fp@igh-essen.com>
parents: 360
diff changeset
   255
	# master module and device module loaded?
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   256
	test $master_running -eq 0 -a $device_running -eq 0
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   257
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   258
	rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   259
	;;
289
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   260
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   261
    bridge)
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   262
	echo -n "Building EoE bridge "
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   263
	build_eoe_bridge
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   264
	rc_status -v
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   265
	;;
289
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   266
3c121228ebe9 Enhancements and bugfixes on bridging script.
Florian Pose <fp@igh-essen.com>
parents: 285
diff changeset
   267
    *)
360
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   268
	echo "USAGE: $0 {start|stop|restart|status|bridge}"
a7a8ed41b50a Changed identation in init script.
Florian Pose <fp@igh-essen.com>
parents: 325
diff changeset
   269
	;;
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
   270
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   271
esac
324
9aa51cbdbfae Indentication in init script.
Florian Pose <fp@igh-essen.com>
parents: 323
diff changeset
   272
243
f288d557854c Better RC script.
Florian Pose <fp@igh-essen.com>
parents: 197
diff changeset
   273
rc_exit
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   274
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
   275
#------------------------------------------------------------------------------