The information on the web regarding upstart, init and .conf files is rubbish. A lot of different places show completely different ways of doing things.
Anyways, I have a script file /home/karl/.scripts/startup/sensei-raw-startup.sh (file permission 775):
#!/bin/bash
# run as root
xinput list >> /var/log/trololol.log
echo trololol start >> /var/log/trololol.log
ids=$(xinput list | awk '/SteelSeries Sensei Raw Gaming Mouse .*pointer/ {print $8}' | sed 's/id=\(.*\)/\1/')
echo trololol before ids >> /var/log/trololol.log
echo $ids >> /var/log/trololol.log
echo trololol after ids >> /var/log/trololol.log
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
sensei-raw-ctl --show
sensei-raw-ctl --polling 500
sensei-raw-ctl --cpi-on 450
sensei-raw-ctl --cpi-off 5670
unset ids
unset ids_array
echo sensei-raw-startup.sh script `date` >> /var/log/sensei-raw-startup.log
echo trololol end >> /var/log/trololol.log
When logged in running the script as sudo it runs perfectly (log is also created):
karl@karl-laptop:~/.scripts/startup$ sudo bash sensei-raw-startup.sh
fixing id 12
fixing id 14
Backlight intensity: low
Backlight pulsation: slow
Speed in CPI (LED is off): 5670
Speed in CPI (LED is on): 450
Polling frequency: 500Hz
karl@karl-laptop:~/.scripts/startup$
Now I wish for this to automatically run whenever I login or the computer starts up (it should affect every user logging in).
I created the file /etc/init/karl-startup.conf:
description "karls sexy startup script"
author "Karl Morrison"
start on started lightdm
pre-start script
exec xinput 1> /var/log/karls.log 2>&1
end script
script
exec bash /home/karl/.scripts/startup/sensei-raw-startup.sh
end script
Now I check the file with:
karl@karl-laptop:~$ init-checkconf /etc/init/karl-startup.conf
File /etc/init/karl-startup.conf: syntax ok
I restart my laptop, login and my mouse settings have not been altered, I check the logs:
karl@karl-laptop:~$ sudo cat /var/log/trololol.log
[sudo] password for karl:
trololol start
trololol before ids
trololol after ids
As you can see where the ids are supposed to be displayed 12 14 it's blank.
Got me the following error:
karl@karl-laptop:~$ sudo cat /var/log/karls.log
Unable to connect to X server