#!/bin/sh

if test $(id -u) != 0; then
	echo Error: You must be root to run this script!
	exit 1
fi

X_CONF=xorg.conf

perl -pi -e 's|(\s*Option\s+"Protocol"\s+)"IMPS/2"|\1"ExplorerPS/2"|' "/etc/X11/$X_CONF"
perl -pi -e 's|(\s*Option\s+"Buttons"\s+)"\w+"|\1"7"|' "/etc/X11/$X_CONF"
perl -pi -e 's|[\s]*InputDevice    "PS/2 Mouse" "CorePointer"|# PS/2 Mouse not detected|' "/etc/X11/$X_CONF"
perl -pi -e 's|# USB Mouse not detected|\tInputDevice    "USB Mouse" "CorePointer"|' "/etc/X11/$X_CONF"

apt-get update
apt-get -y install imwheel
if ! [ -x /usr/bin/imwheel ]; then
	echo Error: Could not install imwheel correctly.
	exit 2
fi

cat >/etc/X11/imwheel/imwheelrc <<EOF
".*"
None,   Thumb1,   Alt_L|Left
None,   Thumb2,   Alt_L|Right
EOF

rm -f /etc/X11/Xsession.d/999imwheel_start
rm -f /etc/X11/imwheel/startup.conf
cat > /etc/X11/imwheel/startup.conf <<EOF
# Configuration file for setting imwheel startup parameters.

# Set this to "1" to make imwheel start with X.
IMWHEEL_START=1

# Specify the command line parameters to pass to imwheel.
# Simply uncomment the bottom line, and replace the default
# options with your own if necessary.
IMWHEEL_PARAMS="-b 0 0 0 0 8 9"

# Be sure imwheel is killed.
/usr/bin/killall imwheel 2>/dev/null
EOF

echo "Please restart X! (Ctrl+Alt+Backspace)"

