I was about to make a Slackel package for cbatticon but you were faster than me, Dimitri
This is what I ended up using (please correct me if I am wrong or there is a better way to do what I wanted):
cbatticon should shutdown the computer if battery level is critically low. This means cbatticon should execute
sudo halt. There is a problem, however: sudo normally asks for user's password; I want to prevent this; system must shtdown without user intervention (because user might be away when battery level becomes critically low). My solution to this problem was this:create a new file,
/etc/sudoers.d/20-halt:
(in this case I use vim but any editor can be used). In the new file add the line
Save and exit. Now executing sudo halt will not ask for a user password for all users in group wheel. Then add this in ~/.config/openbox/autostart.sh:
Code: Select all
([ -x /usr/bin/cbatticon ] && dbus-launch cbatticon -n -i symbolic -c "sudo halt" -r 5)
This will run cbatticon when openbox starts. The essential flag is
-c "sudo halt" which will shutdown the system at critical battery level. The rest of the flags are just personal preferences.
I am not quite sure if it's better to run cbatticon via dbus-launch. Since batti was launched that way, I did the same for cbatticon.
The above works very well and it's lightweight.