hertg / egpu-switcher

🖥🐧 Setup script for eGPUs in Linux (X.Org)
GNU General Public License v3.0
588 stars 58 forks source link

OpenRC support? #62

Open harakiru opened 3 years ago

harakiru commented 3 years ago

I was wondering if it was possible to make a OpenRC compatible version of this. I think people who use distros without systemd would benefit greatly from this.

harakiru commented 3 years ago

I haven't tested it yet but perhaps something like this could be used:

#!/sbin/openrc-run

name=$RC_SVCNAME
description="EGPU Service"
command="/usr/bin/egpu-switcher"
command_args="switch auto"

depend() {
    after bolt 
    before display-manager 
} 
hertg commented 3 years ago

I'd be open to add OpenRC support sometime, but I am not familiar with it at all. If you could test the example configuration you posted and update it if necessary, I can add this to the backlog.

One hint: I struggled with the SystemD config at the beginning because specifying "before=display-manager" wasn't enough to make sure that the display-manager only starts after egpu-switcher exits (display-manager started after egpu-switcher, but it didn't wait for it to finish). Specifying the systemD service to be of type=oneshot was necessary to make display-manager wait for the epgu-switcher to actually complete, otherwise race conditions can occurr (some background info: #16). It would be great if you could check if something similar is necessary in OpenRC.

Adding OpenRC support would require some code changes in the main script though. My main focus now is how I could rewrite the script to extends its functionality for general thunderbolt devices (not just eGPUs) and I'm working on a prototype in Rust (see discussion #58). Because of that, feature-additions to the bash script aren't my main focus right now, and I can't guarantee any time-frame when this would be implemented. I would welcome a PR though :)

harakiru commented 3 years ago

Understood. I'm afraid i dont know anything about thunderbolt since i use expresscard. However i downloaded and ran the script and it works great as it is. Seems like the only issue is that it cant place and start the systemd service file (since there is no such thing in a openrc system) otherwise it successfully switches my system to the egpu. I'll try to work on a PR when i have some time and hopefully we can add openrc support sometime soon.

hertg commented 3 years ago

I'm afraid i dont know anything about thunderbolt since i use expresscard

Thanks a lot for pointing that out, I wasn't actually aware that people might use the script with non-Thunderbolt external video devices.

I'll try to work on a PR when i have some time and hopefully we can add openrc support sometime soon.

Sounds great! I think the "only" thing to change in the script is the logic where it creates the systemd service. So instead of creating the systemD service directly, it should check whether the init system is systemD or OpenRC, and then apply the according configuration.

Most important lines are probably here: https://github.com/hertg/egpu-switcher/blob/master/egpu-switcher#L335-L338 and here https://github.com/hertg/egpu-switcher/blob/master/egpu-switcher#L501-L510

hertg commented 2 years ago

With the recent rewrite, I took this issue into consideration and tried to abstract away anything systemd related behind an interface. So implementing this might be pretty straightforward. But since I am unfamiliar with OpenRC and since this probably is a niche use-case I don't have any plans on actually implementing this. I'm happy to accept PRs though.