ethercat.sh
author Florian Pose <fp@igh-essen.com>
Wed, 10 May 2006 07:53:50 +0000
changeset 222 321eba07fafb
parent 197 b9a6e2c22745
child 243 f288d557854c
permissions -rwxr-xr-x
Changed RTAI sample naming.
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
#
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
     5
#  EtherCAT rc script
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
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    15
#  as published by the Free Software Foundation; version 2 of the License.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    16
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    17
#  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
    18
#  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
    19
#  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
    20
#  GNU General Public License for more details.
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    21
#
b9a6e2c22745 GPLv2 License and enhanced Doxygen output.
Florian Pose <fp@igh-essen.com>
parents: 174
diff changeset
    22
#  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
    23
#  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
    24
#  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
    25
#
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    26
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    27
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    28
CONFIGFILE=/etc/sysconfig/ethercat
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    29
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    30
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    31
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    32
print_usage()
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    33
{
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
    34
    echo "Usage: $0 { start | stop | restart }"
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    35
}
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
unload_module()
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    38
{
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    39
    if lsmod | grep ^$1 > /dev/null; then
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    40
	echo "  unloading module \"$1\"..."
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    41
	rmmod $1 || exit 1
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    42
    fi
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    43
}
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    44
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    45
#------------------------------------------------------------------------------
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    46
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    47
# Get parameters
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    48
if [ $# -eq 0 ]; then
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    49
    print_usage
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    50
    exit 1
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    51
fi
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    52
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    53
ACTION=$1
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    54
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    55
# Load configuration from sysconfig
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    56
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    57
if [ -f $CONFIGFILE ]; then
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    58
    . $CONFIGFILE
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    59
else
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    60
    echo "ERROR: Configuration file \"$CONFIGFILE\" not found!"
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    61
    exit 1
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    62
fi
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    63
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    64
case $ACTION in
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
    65
    start | restart)
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    66
	echo "Starting EtherCAT master..."
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
    67
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    68
	# remove modules
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    69
	unload_module 8139too
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    70
	unload_module 8139cp
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    71
	unload_module ec_8139too
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    72
	unload_module ec_master
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
    73
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    74
	echo "  loading master modules..."
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    75
	if ! modprobe ec_8139too ec_device_index=$DEVICEINDEX; then
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    76
	    echo "ERROR: Failed to load module!"
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    77
	    exit 1
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    78
	fi
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    79
	;;
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
    80
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    81
    stop)
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    82
	echo "Stopping EtherCAT master..."
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    83
	unload_module ec_8139too
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    84
	unload_module ec_master
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    85
	if ! modprobe 8139too; then
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    86
	    echo "Warning: Failed to restore 8139too module."
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    87
	fi
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    88
	;;
174
99907332ff1e Restart action in RC script
Florian Pose <fp@igh-essen.com>
parents: 169
diff changeset
    89
169
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    90
    *)
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    91
	print_usage
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    92
	exit 1
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    93
esac
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    94
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    95
echo "done."
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    96
exit 0
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    97
b3ecbec2c487 Better installer and startup scripts.
Florian Pose <fp@igh-essen.com>
parents:
diff changeset
    98
#------------------------------------------------------------------------------