#!/bin/sh
#A little script that reports the event# to use for a Logitech G7 mouse and
#optionally replaces the xorg event# with the detected event#.
#I had fun writing this and use it to update xorg.conf since my mouse turns up as
#a different event# every boot!
#May work for other Logitech mice with the some adjustments.
#Usage:
#Please make a backup of your xorg.conf!
#cp /etc/X11/xorg.conf /etc/X11/xorg.conf~
#To find the the correct event number just save as executable script (eg /home/user/sg7).
#Then call the script: $ /home/user/sg7
EVENTLINE=$(cat /proc/bus/input/devices|grep -A 3 "Logitech USB Receiver"|grep "Handlers=mouse0")
echo "proc line: $EVENTLINE"
EVENTSTR=$(echo $EVENTLINE|grep -o event.)
echo "proc string: $EVENTSTR"
echo ""
XORGEVENTLINE=$(cat /etc/X11/xorg.conf|grep event)
echo "xorg.conf line: $XORGEVENTLINE"
XORGEVENTSTR=$(echo $XORGEVENTLINE|grep -o event.)
echo "xorg.conf string: $XORGEVENTSTR"
echo ""
#To overwrite xorg.conf call the script with "edit" as the only argument.
#Save as executable script (eg /root/scripts/sg7).
#Then call the script: $ /root/scripts/sg7 edit
#Needs an already setup xorg.conf where "event#" only occurs ONCE.
#Needs permission to overwrite xorg.conf, I use 'super' for this.
#Since you plan to run this as root understand the commands, since if there is
#a typo or paste error anything could happen...
if [ "$1" = "edit" ]; then
echo "running sed: "
sed -i s/event./$EVENTSTR/ /etc/X11/xorg.conf
XORGEVENTLINE=$(cat /etc/X11/xorg.conf|grep event)
echo "after sed xorg.conf: $XORGEVENTLINE"
fi