diff --git a/50-rtmouse.rules b/etc/50-rtmouse.rules similarity index 100% rename from 50-rtmouse.rules rename to etc/50-rtmouse.rules diff --git a/etc/rtmouse.service b/etc/rtmouse.service new file mode 100644 index 0000000..37bbb55 --- /dev/null +++ b/etc/rtmouse.service @@ -0,0 +1,17 @@ +[Unit] +Description=rtmouse driver +After=network.target + +[Service] +Type=oneshot +RemainAfterExit=yes +Restart=no +ExecStart=/etc/init.d/rtmouse.sh start +ExecReload=/etc/init.d/rtmouse.sh restart +ExecStopt=/etc/init.d/rtmouse.sh stop +StandardOutput=syslog +StandardError=syslog +SyslogIdentifier=rtmouse + +[Install] +WantedBy=multi-user.target diff --git a/etc/rtmouse.sh b/etc/rtmouse.sh new file mode 100755 index 0000000..07af1a7 --- /dev/null +++ b/etc/rtmouse.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# +### BEGIN INIT INFO +# Provides: rtmouse +# Required-Start: $all +# Required-Stop: +# Default-Start: 2 3 4 5 +# Default-Stop: +# Short-Description: RasPiMouse_Driver +# Description: Rasoberry Pi Mouse Driver by RT Corporation +### END INIT INFO + +SCRIPTNAME=rtmouse.sh +PROC_FILE=/proc/modules +GREP=/bin/grep +MODPROBE=/sbin/modprobe +MODULE_NAME=rtmouse +DEP_MODULE_NAME=mcp320x + +[ -f $PROC_FILE ] || exit 0 +[ -x $GREP ] || exit 0 +[ -x $MODPROBE ] || exit 0 + +RES=`$GREP $MODULE_NAME $PROC_FILE` + +# installing rtmouse.ko +install_rtmouse() +{ + if [ "$RES" = "" ]; then + $MODPROBE $MODULE_NAME + echo "Module Install $MODULE_NAME" + else + echo "Module '$MODULE_NAME' is already installed" + fi +} + +# uninstalling rtmouse.ko +remove_rtmouse() +{ + if [ "$RES" = "" ]; then + echo "Module '$MODULE_NAME' isn't installed yet." + else + $MODPROBE -r $MODULE_NAME + $MODPROBE -r $DEP_MODULE_NAME + echo "Module '$MODULE_NAME' is rmoved." + fi +} + +case "$1" in + start) + install_rtmouse + sleep 1 + /bin/chmod a+rw /dev/rt* + ;; + stop) + remove_rtmouse + ;; + status) + if [ "$RES" = "" ]; then + echo "Module '$MODULE_NAME' isn't installed yet." + exit 0 + else + echo "Module '$MODULE_NAME' is already installed" + exit 0 + fi + ;; + *) + echo "Usage: $SCRIPTNAME {start|stop|status}" >&2 + exit 3 +esac + +exit 0 diff --git a/src/drivers/Makefile.header_from_apt b/src/drivers/Makefile.header_from_apt index 7844404..0dd6513 100644 --- a/src/drivers/Makefile.header_from_apt +++ b/src/drivers/Makefile.header_from_apt @@ -12,9 +12,19 @@ clean: make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean install: rtmouse.ko - cp ../../50-rtmouse.rules /etc/udev/rules.d/ + cp rtmouse.ko /lib/modules/$(shell uname -r)/kernel/drivers/ + cp ../../etc/50-rtmouse.rules /etc/udev/rules.d/ + cp ../../etc/rtmouse.sh /etc/init.d/ + chmod 755 /etc/init.d/rtmouse.sh + cp ../../etc/rtmouse.service /etc/systemd/system/ + systemctl daemon-reload + systemctl enable rtmouse.service uninstall: rm /etc/udev/rules.d/50-rtmouse.rules + -systemctl stop rtmouse.service + systemctl disable rtmouse.service + rm /etc/init.d/rtmouse.sh + rm /etc/systemd/system/rtmouse.sh -#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm \ No newline at end of file +#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm diff --git a/src/drivers/Makefile.header_from_source b/src/drivers/Makefile.header_from_source index 2222e8d..f31506a 100644 --- a/src/drivers/Makefile.header_from_source +++ b/src/drivers/Makefile.header_from_source @@ -9,4 +9,22 @@ rtmouse.ko: rtmouse.c make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) modules clean: - make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean \ No newline at end of file + make -C $(LINUX_SRC_DIR) M=$(shell pwd) V=$(VERBOSE) clean + +install: rtmouse.ko + cp rtmouse.ko /lib/modules/$(shell uname -r)/kernel/drivers/ + cp ../../etc/50-rtmouse.rules /etc/udev/rules.d/ + cp ../../etc/rtmouse.sh /etc/init.d/ + chmod 755 /etc/init.d/rtmouse.sh + cp ../../etc/rtmouse.service /etc/systemd/system/ + systemctl daemon-reload + systemctl enable rtmouse.service + +uninstall: + rm /etc/udev/rules.d/50-rtmouse.rules + -systemctl stop rtmouse.service + systemctl disable rtmouse.service + rm /etc/init.d/rtmouse.sh + rm /etc/systemd/system/rtmouse.sh + +#Reference: http://www.devdrv.co.jp/linux/kernel26-makefile.htm