1

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

1 Answers1

1

The file /etc/init/karl-startup.conf should read:

description "karls sexy startup script"

As you say in your related question you want to start the script on login, further use

start on desktop-session-start

if you want to run it on startup, use

start on startup

exec sudo -u $user /home/karl/.scripts/startup/sensei-raw-startup.sh
exec echo sensei-raw-startup.sh script `date` >> /var/log/karl-startup.log start 

Further details on upstart here: http://upstart.ubuntu.com/cookbook/#id300

mcantsin
  • 1,254
  • 1
  • 12
  • 29
  • In this question, I wish for it to start before login. I tried your changes, still no effect :/ – Karl Morrison Dec 02 '15 at 01:41
  • Ok, I see. Well if it's at reboot I suggest you use a cronjob. Check here: http://askubuntu.com/questions/173924/how-to-run-a-cron-job-using-the-sudo-command – mcantsin Dec 02 '15 at 01:43
  • Ok tried cronjob: sudo cronjob -e and wrote @reboot /home/karl/.scripts/startup/sensei-raw-startup.sh, still does not change settings :/ – Karl Morrison Dec 02 '15 at 02:02
  • if you don't explicitly use bash in front of the path to the script, the file would be executed using sh. I suggest, you use @reboot bash /home/karl/.scripts/startup/sensei-raw-startup.sh – mcantsin Dec 02 '15 at 02:08
  • Ok added bash to the command, still not effecting it! – Karl Morrison Dec 02 '15 at 02:11
  • Ok I've done more testing and my script is being run, however it is not finding the ids of the SteelSeries Sensei Raw Gaming Mouse pointers. Which brings me to ask, when are those loaded (connected via usb)? – Karl Morrison Dec 02 '15 at 02:40
  • I'll mark this as correct as it does solve my question. I will start another question on why xinput isn't working. – Karl Morrison Dec 02 '15 at 19:31