16
#!/bin/bash
ids=$(xinput list | awk '/SteelSeries Sensei Raw Gaming Mouse .*pointer/ {print $8}' | sed 's/id=\(.*\)/\1/')

if [ -z "$ids" ]; then
  exit 0;
fi

read -a ids_array <<< $ids

echo fixing id ${ids_array[0]}
xinput set-prop ${ids_array[0]} 'Device Accel Profile' -1
xinput set-prop ${ids_array[0]} 'Device Accel Constant Deceleration' 2.5
xinput set-prop ${ids_array[0]} 'Device Accel Adaptive Deceleration' 1
xinput set-prop ${ids_array[0]} 'Device Accel Velocity Scaling' 1

echo fixing id ${ids_array[1]}
xinput set-prop ${ids_array[1]} 'Device Accel Profile' -1
xinput set-prop ${ids_array[1]} 'Device Accel Constant Deceleration' 1.5
xinput set-prop ${ids_array[1]} 'Device Accel Adaptive Deceleration' 1
xinput set-prop ${ids_array[1]} 'Device Accel Velocity Scaling' 1

sudo sensei-raw-ctl --show
sudo sensei-raw-ctl --polling 500
sudo sensei-raw-ctl --cpi-on 450
sudo sensei-raw-ctl --cpi-off 5670

unset ids
unset ids_array

I wish for the following script to run once when I login or when the computer starts up. The above script is located in /home/karl/.scripts/startup/sensei-raw-startup.sh.

I DO NOT wish to use the GUI to add the script. I wish to learn a bit more about how to do it manually.

What files do I need to create, what must be in them and where should they be located to be able to run my script which is located in the said directory.

  • 1
    Here they explain how to run an script at boot as root (in /etc/init) as user (/home/user/.config/upstart) or even with a "@reboot" task in cron: http://askubuntu.com/questions/814/how-to-run-scripts-on-start-up – Julen Larrucea Dec 01 '15 at 22:13
  • Either rclocal or systemd on a newer system as seen in the posted link. – mchid Dec 02 '15 at 00:23
  • 1
    @Julen creating a cronjob is not the right solution, as @reboot starts the script when the system is started, not when the user logs in. https://help.ubuntu.com/community/CronHowto – mcantsin Dec 02 '15 at 01:04

1 Answers1

22

1. Using /etc/profile.d

You can run the script on login by placing the script in /etc/profile.d/

These files are executed upon login.

To create a symbolic link to the file you want to execute, use

sudo ln -s /home/karl/.scripts/startup/sensei-raw-startup.sh /etc/profile.d/myscript.sh

2. Using upstart

Another possibility is to use upstart

start on desktop-session-start

and place your script there.

mcantsin
  • 1,254
  • 1
  • 12
  • 29
  • How does this handle sudo commands? – Karl Morrison Dec 02 '15 at 01:13
  • @KarlMorrison echo "password" | sudo -S command – mcantsin Dec 02 '15 at 01:22
  • Where is that supposed to reside? In the file? You need to be a little more specific (I'm still learning this stuff!). – Karl Morrison Dec 02 '15 at 01:23
  • 1
    @KarlMorrison personally I think you should use the upstart solution, as /etc/profile.d is not really meant to be used like this. My suggestion is more a "hack". I you still want to try, just add the echo "password" in front of the | sudo -S part, whereafter sudo won't ask for the password any more. – mcantsin Dec 02 '15 at 01:25
  • Indeed I've tried: https://askubuntu.com/questions/704815/upstart-not-running-sh-script perhaps you could see whats wrong? :/ – Karl Morrison Dec 02 '15 at 01:27
  • @KarlMorrison I think the error is with the part start on runlevel [2345]. Use the solution I suggest: start on desktop-session-start which I think is what you want: starting when the desktop session starts. - no? (Regarding upstart I will respond in your other ticket) – mcantsin Dec 02 '15 at 01:32
  • Just tried with what you suggested, still no effect :( I need the script to be loaded when the login screen appears (as the mouse can be used there). So basically before logging into the user. – Karl Morrison Dec 02 '15 at 01:35
  • Please check in your related question: https://askubuntu.com/questions/704815/upstart-not-running-sh-script/704820#704820 – mcantsin Dec 02 '15 at 01:40