#!/bin/bash # ------------------------------------------------------------------------------ # # This Script writes the (hopefully) correct section in your xorg.conf # You must run it as root. # # All buttons work as expected! # This means: thumbbuttons to navigate in browsers and the two wheels scroll horizontal/vertical # ans all the others too. Except of the Mode-Button of course ... # # Created by yokmp on Friday, 13th January 2012 # Yes rly, so use with CARE! # # this is version 0.2 # ------------------------------------------------------------------------------ # lets define some vars 'n' arrays RED='\e[1;31m' GREEN='\e[1;32m' yellow='\e[1;33m' fat='\033[1m' nf='\033[0m' # files to look for files_to_search=( "x11-apps/xinput" "x11-apps/xev" ) files_to_install=( "xinput" "xev" ) function center() { printf "%*s\n" $((( ${#center} + $COLUMNS) / 2 )) "$center" ; } function hr() { echo -en "${yellow}" for (( l = 1 ; l <= $COLUMNS ; l++ )); do echo -n "=" done echo -e "${nf}" } function shr() { echo -en "${yellow}" for (( l = 1 ; l <= $COLUMNS ; l++ )); do echo -n "~" done echo -e "${nf}" } # ------------------------------------------------------------------------------ # lets check for xinput and xev and yes i love loops function chk_stuff() { echo -e "\nSniffin your Packets ..." shr for (( packet = 0 ; packet <= $(((${#files_to_search[*]} - 1 ))) ; packet++ )); do equo query installed ${files_to_install[$packet]}|grep "${files_to_search[$packet]}" 1> /dev/null if [ $? = 0 ]; then echo -e "${fat}${files_to_search[$packet]}\t[ ${GREEN}OK${nf} ]" else echo -e "${fat}${files_to_search[$packet]}\t[${RED}FAIL${nf}]" equo install ${files_to_install[$packet]} --ask fi done } function sed_FTW() # we dont need sed )= { # and we will not check if the user rly has a RAT plugged in ... mouse_name=$(xinput list|grep -o "R.A.T.*Mouse\|R.A.T.*Albino\|R.A.T.*Contagion") mouse_model=$(xinput list|grep -o "R.A.T.*Mouse\|R.A.T.*Albino\|R.A.T.*Contagion"|head -c7|tail -c1) [ -e /etc/X11/xorg.conf ] || echo "" > /etc/X11/xorg.conf mkdir -p /home/$username/Desktop # just to be shure ... cp /etc/X11/xorg.conf /etc/X11/xorg.conf.bakup cp /etc/X11/xorg.conf /home/$username/Desktop chown $username /home/$username/Desktop/xorg.conf button_mapping() { echo " Section \"InputClass\" Identifier \"Mouse Remap\" MatchProduct \"Saitek Cyborg $mouse_name\" MatchDevicePath \"/dev/input/event*\" " >> /home/$username/Desktop/xorg.conf case $mouse_model in 3) echo ' Option "ButtonMapping" "1 2 3 4 5 6 7 8 9 0 0 0 0 0 0" EndSection' >> /home/$username/Desktop/xorg.conf ;; 5) echo ' Option "Buttons" "17" Option "ButtonMapping" "1 2 3 4 5 0 0 8 9 7 6 12 0 0 0 16 17" Option "AutoReleaseButtons" "13 14 15" Option "ZAxisMapping" "4 5 6 7" Option "YAxisMapping" "10 11" EndSection' >> /home/$username/Desktop/xorg.conf ;; 7) echo ' Option "Buttons" "17" Option "ButtonMapping" "1 2 3 4 5 0 0 8 9 7 6 12 0 0 0 16 17" Option "AutoReleaseButtons" "13 14 15" Option "ZAxisMapping" "4 5 6 7" Option "YAxisMapping" "10 11" EndSection' >> /home/$username/Desktop/xorg.conf ;; 9) echo ' Option "Buttons" "17" Option "ButtonMapping" "1 2 3 4 5 0 0 8 9 7 6 12 0 0 0 16 17" Option "AutoReleaseButtons" "13 14 15" Option "ZAxisMapping" "4 5 6 7" Option "YAxisMapping" "10 11" EndSection' >> /home/$username/Desktop/xorg.conf ;; esac } echo -ne "\nIs ${fat}$mouse_name${nf} your mouse? (y/n) " read -n1 ; echo if ( [ "$REPLY" = "y" ] || [ "$REPLY" = "Y" ] ); then echo "Now we will write some stuff in your xorg.conf!" button_mapping else echo -e "Note: In some cases you must use 7 instead of 7 Albion or 9 etc...\nPlay arond and try yourself ;)" read -p "Please enter you model (3, 5, 7, 7 Contagion, 7 Albino, 9): R.A.T." mouse_user mouse_name="R.A.T.$mouse_user" ; button_mapping fi } # ------------------------------------------------------------------------------ clear echo -e "${fat}" ; center="This Script will modify your xorg.conf!" ; center ; echo -e "${nf}" if [ "$(id -u)" != "0" ]; then echo -e "${fat}" ; center="... But you must be root ..." ; center ; echo -e "${nf}" return 1 else read -p "Please enter your username (not root -.-): " username=$REPLY fi hr echo -e "\nThe Script needs ${fat}xinput${nf} and optionally ${fat}xev${nf}" echo "and must also have you ${fat}R.A.T. Mouse plugged in${nf} and of course ${fat}running Sabayon${nf}!" echo -e "\nYou can let the Script handle the installation of both (you will be asked for this)" echo -e "\n\tAnd just in case:\n\tIm not responsible for any wired things that may can happen!" echo -e "\tBut you can leave me a messeage at the discussion page:" echo -e "\thttp://wiki.sabayon.org/index.php?title=User:Yokmp" hr echo -e "\nFirst let me refresh the Repository ..." shr equo update echo -e "\nDone here. Starting search now." hr chk_stuff shr echo -e "Now lets do something useful.\n${fat}If you aborted the installation of xinput," echo -e "then you should press [CTRL]+[C] now and rerun the script!${nf}" echo "Else press enter" read hr sed_FTW hr echo -e "\nDone so far.\nWeird things can happen in scripts so you should check your new xorg.conf!" shr cat /home/$username/Desktop/xorg.conf shr read -p "Replace your xorg.conf now? (y/n) " case $REPLY in y|Y|yes|Yes|YES) cp -vi /home/$username/Desktop/xorg.conf /etc/X11/ # Very Interactive ;; *) echo "You must copy the new file yourself!" ;; esac hr echo -e "${fat}" center="FINISH! Easy thing right?" center center="Don't forget to restart Xorg or nothing will happen!" center echo -e "${nf}" hr