From 3e4841959f4d31c7ca9461a10874783671bf9448 Mon Sep 17 00:00:00 2001
From: Florian Pose <fp@igh-essen.com>
Date: Fri, 19 May 2006 09:56:55 +0000
Subject: [PATCH] Created scripts directory and improved install and init
 scripts.

---
 Makefile                          | 20 ++++-----
 ethercat.conf.tmpl                |  5 +--
 {tools => script}/ec_list.pl      |  0
 ethercat.sh => script/ethercat.sh | 19 ++++++---
 install.sh => script/install.sh   | 71 +++++++++++++++++--------------
 script/sysconfig                  | 21 +++++++++
 6 files changed, 85 insertions(+), 51 deletions(-)
 rename {tools => script}/ec_list.pl (100%)
 rename ethercat.sh => script/ethercat.sh (91%)
 rename install.sh => script/install.sh (68%)
 create mode 100644 script/sysconfig

diff --git a/Makefile b/Makefile
index adefd365..f1745771 100644
--- a/Makefile
+++ b/Makefile
@@ -33,34 +33,32 @@
 #
 #------------------------------------------------------------------------------
 
-ifneq ($(KERNELRELEASE),)
-
 #------------------------------------------------------------------------------
 #  kbuild section
 
+ifneq ($(KERNELRELEASE),)
+
 obj-m := master/ devices/
 
 #------------------------------------------------------------------------------
+#  default section
 
 else
 
-#------------------------------------------------------------------------------
-#  default section
-
 ifneq ($(wildcard ethercat.conf),)
 include ethercat.conf
 else
-KERNEL := `uname -r`
-DEVICEINDEX := 99
+KERNEL := $(shell uname -r)
 endif
 
-KERNELDIR := /lib/modules/$(KERNEL)/build
+KERNEL_DIR := /lib/modules/$(KERNEL)/build
+CURRENT_DIR := $(shell pwd)
 
 modules:
-	$(MAKE) -C $(KERNELDIR) M=`pwd`
+	$(MAKE) -C $(KERNEL_DIR) M=$(CURRENT_DIR)
 
 clean: cleandoc
-	$(MAKE) -C $(KERNELDIR) M=`pwd` clean
+	$(MAKE) -C $(KERNEL_DIR) M=$(CURRENT_DIR) clean
 
 doc:
 	doxygen Doxyfile
@@ -69,7 +67,7 @@ cleandoc:
 	@rm -rf doc
 
 install:
-	@./install.sh $(KERNEL) $(DEVICEINDEX)
+	@script/install.sh $(KERNEL)
 
 #------------------------------------------------------------------------------
 
diff --git a/ethercat.conf.tmpl b/ethercat.conf.tmpl
index 4cc01214..6f6aa214 100644
--- a/ethercat.conf.tmpl
+++ b/ethercat.conf.tmpl
@@ -9,10 +9,9 @@
 #
 #------------------------------------------------------------------------------
 
+#
 # The kernel to compile the EtherCAT sources against
+#
 KERNEL := `uname -r`
 
-# PCI index of the EtherCAT device
-DEVICEINDEX := 99
-
 #------------------------------------------------------------------------------
diff --git a/tools/ec_list.pl b/script/ec_list.pl
similarity index 100%
rename from tools/ec_list.pl
rename to script/ec_list.pl
diff --git a/ethercat.sh b/script/ethercat.sh
similarity index 91%
rename from ethercat.sh
rename to script/ethercat.sh
index 38e0130c..96a9eb32 100755
--- a/ethercat.sh
+++ b/script/ethercat.sh
@@ -64,7 +64,14 @@ rc_reset
 
 case "$1" in
     start)
-	echo -n "Starting EtherCAT master... "
+	echo -n "Starting EtherCAT master "
+
+	if [ ! $DEVICE_INDEX ]; then
+	    echo "ERROR: DEVICE_INDEX not set!"
+	    /bin/false
+	    rc_status -v
+	    rc_exit
+	fi
 
 	for mod in 8139too 8139cp; do
 		if lsmod | grep "^$mod " > /dev/null; then
@@ -72,17 +79,17 @@ case "$1" in
 				/bin/false
 				rc_status -v
 				rc_exit
-			fi;
-		fi;
+			fi
+		fi
 	done
 
-	modprobe ec_8139too ec_device_index=$DEVICEINDEX
+	modprobe ec_8139too ec_device_index=$DEVICE_INDEX
 
 	rc_status -v
 	;;
 
     stop)
-	echo -n "Shutting down EtherCAT master... "
+	echo -n "Shutting down EtherCAT master "
 
 	for mod in ec_8139too ec_master; do
 		if lsmod | grep "^$mod " > /dev/null; then
@@ -109,7 +116,7 @@ case "$1" in
 	;;
 
     status)
-	echo -n "Checking for EtherCAT... "
+	echo -n "Checking for EtherCAT "
 
 	lsmod | grep "^ec_master " > /dev/null
 	master_running=$?
diff --git a/install.sh b/script/install.sh
similarity index 68%
rename from install.sh
rename to script/install.sh
index d4390704..0390c743 100755
--- a/install.sh
+++ b/script/install.sh
@@ -35,71 +35,80 @@
 #
 #------------------------------------------------------------------------------
 
-CONFIGFILE=/etc/sysconfig/ethercat
-
-#------------------------------------------------------------------------------
-
-# install function
-
-install()
-{
-    echo "    $1"
-    if ! cp $1 $INSTALLDIR; then exit 1; fi
-}
-
-#------------------------------------------------------------------------------
+# Fetch parameters
 
-# Fetch parameter
-
-if [ $# -ne 2 ]; then
+if [ $# -ne 1 ]; then
     echo "This script is called by \"make\". Run \"make install\" instead."
     exit 1
 fi
 
 KERNEL=$1
-DEVICEINDEX=$2
+
+if [ ! -d /lib/modules/$KERNEL ]; then
+    echo "Kernel \"$KERNEL\" does not exist in /lib/modules!"
+    exit 1
+fi
+
+#------------------------------------------------------------------------------
+
+# Copy files
 
 INSTALLDIR=/lib/modules/$KERNEL/kernel/drivers/net
+MODULES=(master/ec_master.ko devices/ec_8139too.ko)
+
 echo "EtherCAT installer - Kernel: $KERNEL"
+echo "  Installing modules"
 
-# Copy files
+for mod in ${MODULES[*]}; do
+    echo "    $mod"
+    cp $mod $INSTALLDIR || exit 1
+done
 
-echo "  installing modules..."
-install master/ec_master.ko
-install devices/ec_8139too.ko
+#------------------------------------------------------------------------------
 
 # Update dependencies
 
-echo "  building module dependencies..."
+echo "  Building module dependencies"
 depmod
 
+#------------------------------------------------------------------------------
+
 # Create configuration file
 
-if [ -f $CONFIGFILE ]; then
-    echo "  notice: using existing configuration file."
+CONFIGFILE=/etc/sysconfig/ethercat
+
+if [ -s $CONFIGFILE ]; then
+    echo "  Note: Using existing configuration file."
 else
-    echo "  creating $CONFIGFILE..."
-    echo "DEVICEINDEX=$DEVICEINDEX" > $CONFIGFILE || exit 1
+    echo "  Creating $CONFIGFILE"
+    cp script/sysconfig $CONFIGFILE || exit 1
+    echo "  Note: Please edit DEVICE_INDEX in $CONFIGFILE!"
 fi
 
+#------------------------------------------------------------------------------
+
 # Install rc script
 
-echo "  installing startup script..."
-cp ethercat.sh /etc/init.d/ethercat || exit 1
+echo "  Installing startup script"
+cp script/ethercat.sh /etc/init.d/ethercat || exit 1
 chmod +x /etc/init.d/ethercat || exit 1
 if [ ! -L /usr/sbin/rcethercat ]; then
     ln -s /etc/init.d/ethercat /usr/sbin/rcethercat || exit 1
 fi
 
+#------------------------------------------------------------------------------
+
 # Install tools
 
-echo "  installing tools..."
-cp tools/ec_list.pl /usr/local/bin/ec_list || exit 1
+echo "  Installing tools"
+cp script/ec_list.pl /usr/local/bin/ec_list || exit 1
 chmod +x /usr/local/bin/ec_list || exit 1
 
+#------------------------------------------------------------------------------
+
 # Finish
 
-echo "EtherCAT installer done."
+echo "Done"
 exit 0
 
 #------------------------------------------------------------------------------
diff --git a/script/sysconfig b/script/sysconfig
new file mode 100644
index 00000000..6c59a8c5
--- /dev/null
+++ b/script/sysconfig
@@ -0,0 +1,21 @@
+#------------------------------------------------------------------------------
+#
+#  EtherCAT sysconfig file
+#
+#  $Id$
+#
+#------------------------------------------------------------------------------
+
+#
+#  PCI index of the (RTL8139-)EtherCAT device
+#  Setting this is mandatory for the EtherCAT init script!
+#
+#DEVICE_INDEX=99
+
+#
+#  Number of Ethernet-over-EtherCAT devices the master shall create
+#  on startup. Default is 0.
+#
+#EOE_DEVICES=0
+
+#------------------------------------------------------------------------------
-- 
GitLab