1

In order to adjust the screenpad backlight on my ASUS Zenbook, I am using a kernel module I found here. Per his instructions, to make keybind shortcuts using a simple screenpad x command to adjust the brightness, I need to add sudo chmod a+w '/sys/class/leds/asus::screenpad/brightness' to 'rc.local', as the command is required with each reboot, and needs a password every time. By running automatically I could immediately use the custom keyboard shortcuts as they'd function normally with the drivers on Windows, without needing to run the command and enter my password each boot.

I'm a new Linux user, on Parrot OS. From what I've gathered, it's not recommend to use rc.local, and I should instead use either systemd, cronjob, or run it as process using the GUI startup applications menu.

I'm completely lost as to go about doing this with systemd or cronjob. I tried making a file called 'screenpad-perms.sh' and put it in /usr/local/bin, with just these lines in it based on what I've read:

#! /bin/bash

sudo chmod a+w '/sys/class/leds/asus::screenpad/brightness'

I then made it executable using chmod +x screenpad-perms.sh. Finally, I opened the GUI Autostart app and added it as a Login Script.

Restarted the PC but it doesn't work, typing screenpad x gets a permissions denied error unless I manually type sudo chmod a+w '/sys/class/leds/asus::screenpad/brightness' and enter my password; so it seems to not be executing.

Again apologies as I'm very new to Linux, just really hoping to get this screen working properly. What am I missing here?

5
  • 3
    rc.local (which is in /etc) is executed as root so you do not need sudo – Romeo Ninov Apr 20 at 9:13
  • I think this answers your question: askubuntu.com/a/919059/967250 – Alexey Ismagilov Apr 20 at 15:04
  • @RomeoNinov I'm not sure this answers my question, for my distro Parrot rc.local doesn't exist, and from what I understand of what I've read, I'm better off using systemd, cron, or the GUI autostart app. I've seen that I can create an rc.local file and enable it, but if possible I'd like to learn the "right" way as intended on this distro. I'm just having issues understanding even how the script itself should be setup. If it worked, if I execute it manually it should run the command in the terminal, right? Again, very new to Linux/not a coder. – PUNJISTICK Apr 21 at 9:35
  • @PUNJISTICK, in UNIX/Linux usually there is more than one way to do the work. So my suggestion is to learn them all. – Romeo Ninov Apr 21 at 9:56
  • @RomeoNinov haha I respect that, however I feel like this entire situation is way above where I want to be learning right now as a BRAND new (no coding background whatsoever) Linux user. Ideally, my screenpad backlight would just work like on Windows, and I could focus on stuff more "my speed". I've been trying to understand this for about 2 weeks now. At this point I'm just looking for the solution so the backlight can stop crushing my battery, and I can start with some beginner stuff that doesn't involve messing with kernel/system stuff right off the bat. – PUNJISTICK Apr 22 at 5:47
1

If your system is using systemd, that is your best option for what you want to do. The systemd unit will already be executed as root, so sudo is not needed, and you can set it up to run during bootup without even needing anyone to be there to log in.

Here's one link with information on systemd: https://www.digitalocean.com/community/tutorials/understanding-systemd-units-and-unit-files

systemd unit files are more or less similar to a Microsoft *.INI file. They have [SectionHeadings] followed by Directive=Value line.

Here are the steps you will need:

  1. Either load a root shell (sudo bash) or prefix most of the commands with sudo to run as root.

  2. Create a shell script for the systemd service unit to execute. Typically, you will put the file in /usr/local/sbin. Let's call it /usr/local/sbin/fix-backlight.sh (as root):

    editor /usr/local/sbin/fix-backlight.sh

(Assuming editor launches your preferred editor and it creates the file if it does not exist.)

  1. In the file, put (the #! MUST be the first line of the file):

    #!/bin/bash
    chmod a+w '/sys/class/leds/asus::screenpad/brightness'

  2. Go ahead and save it and close your editor. Then make the file only read/write/executable by root (for security):

    chmod 0700 /usr/local/sbin/fix-backlight.sh

  3. Create the systemd unit file (usually in /etc/systemd/system, but there are other locations; the link above gives more detail):

    editor /etc/systemd/system/fix-backlight.service

  4. In the editor for that file, put:

    [Unit]
    Description=Fix perms for the 'screenpad x' backlight command
    [Service]
    ExecStart=/usr/local/sbin/fix-backlight.sh
    [Install]
    WantedBy=multi-user.target

  5. Save and exit the editor. Test the unit:

    systemctl start fix-backlight.service

  6. If all went well and from (a non-root) shell the 'screenpad x' cmmand is working, enable the unit to start on boot:

    systemctl enable fix-backlight.service

  7. Go ahead then and reboot, and make sure it's all working now. (And if it does not and blows up the neighbor's cat, blame the dog!)

If needed, you can also systemctl disable fix-backlight.service to make it stop running at boot.

5
  • First off, big thanks for your time typing out such a clear and easy to understand answer (you even pointed out the stuff you were assuming which is a HUGE help on my end as a new user). Greatly appreciate it. I followed your solution and everything worked perfectly steps 1-8. As far as I understand, no errors or issues. Tested it without sudo/root as you said in 7, worked. I then enabled it, but upon restarting I'm still getting "permission denied". The only thing I changed from your instructions was calling it "screenpad-perms.sh/service". Any idea what I could be missing here? – PUNJISTICK Apr 22 at 4:53
  • an update on this, I ran systemctl status screenpad-perms.service and under "Active" it says "failed (result: exit-code)" "(code=exited, status=1/FAILURE)". For the log I see "screenpad-perms.sh[596]: chmod: cannot access '/sys/class/leds/asus::screenpad/brightness' no such file or directory", but when I do systemctl start screenpad-perms.service as before, it works fine. I assume this is where the problem lies, but I'm lost as to why it can't find it on boot? – PUNJISTICK Apr 22 at 5:19
  • ONE MORE UPDATE. I did a little reading as I suspected it must be some issue with the load order (about my only similar experience here is Fallout modding lol). I threw After=multi-user.target under [Unit] and that did the trick! HUGE thank you for your help. I have been circling around exactly what you wrote for weeks now but just couldn't piece it together properly with my limited knowledge. This has been driving me nuts trying to learn! You've saved my laptop battery life, and my eyes as well haha. – PUNJISTICK Apr 22 at 6:17
  • Ahh.. yes. Changing it to run AFTER was not something I had given much thought to, myself. The file it modifies must not exist until something else get's triggered during system startup to create it. You may need to find out what/when/where that happens (i.e.: where it fires off the kernel module driver), and then make this script trigger after that loads, instead of using the multi-user target. That way, it will trigger when the driver loads, even if you start up in single-user mode, not multi-user mode. – C. M. Apr 22 at 8:25
  • I don't even remotely know the first step towards doing that, but it's something I'll definitely keep in mind. For now I'm going to go back to learning the basics of Linux before I do anything else in this realm lol. I bought this laptop 3 weeks ago to learn Linux, and prior to that I didn't know the word kernel even applied to anything beyond popcorn. Thanks again brother. – PUNJISTICK Apr 23 at 9:17
0

Maybe you need to enable this cmd inside the sudoers file, so this particular cmd won't need a password anymore. Sudoers is a config file, in which you can manage sudo related issues:

sudo EDITOR=nano visudo

to edit the file with nano via visudo (recommended) add:

[YOUR_USERNAME] ALL=(ALL) NOPASSWD:/bin/chmod u+w /sys/class/leds/asus::screenpad/brightness

insert your username without the brackets and add the correct location of your chmod with executing:

which chmod

for me it is /bin/chmod

basically you are allowing everyone logged in as you, to execute this command without a password prompt But please be careful, the sudoers file is very important,you can break your system if you save the file with a small typo. This is why you should use visudo to edit it, because it won't save the config file with errors. I'm changing my mac everytime I reboot this way, so it works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.