Run script on user login

Hi, I’ve created symlinks, that redirect all the .config, .cache, .kde4, recent files and so… simply all the trails that KDE leaves behind to the ramdisk (/run/user/1000) and it works fine. But to make symlinks work I have to create folders on the ramdisk first when I start the computer, otherwise login via KDE gui does not work (it hangs and I have to kill it when I forget to login via tty1 first). I cannot figure where to put my script with mkdirs to make it work properly. I need it to run just after ecryptfs mounts my home folder. Currently I have the script in /etc/profile.d and it works, but I have to login via tty first (ctrl+alt+f1), logout, then ctrl+alt+f7 to switch to the GUI tty7 and login via KDE. It is a bin inconvenient. :frowning:
Btw. from what config file is actually the ecryptfs invoked? I looked into /etc/rc.d and /etc/init.d and it is empty, there’s not even skeleton now :\

Apart from your original question (which I thinjk will not be to easy to answer because I assume the designers never had such a thing in mind when designing GUI login, let alone that they provided easy hooks), I can explain why /etc/rc.d and etc/init.d are empty. They are not used anymore because openSUSE already some time ago switched to systemd.

Maybe a user (not system) systemd unit could help you in your problem though.

Hello and thank you for reply, but I’m sure there’s a mechanism that makes this possible, otherwise ecryptfs could not mount the needed files on login and GUI would hang too.

I try to look onto suggested user systemd, but before I try to reinvent the wheel, maybe someone knows how this works?

If this is a single user system and you are using xdm then you can try placing this in /etc/X11/xdm/Xsetup

That’s normally what pam_ecryptfs is for.

Hm, yes, I see why you are looking into that mechanism.

Others tune in now. All together may succeed in solving this:)

Thanks for suggestion, I tried to put mkdirs there, but it does not work. Either there’s no ramdisk (yet) when this is executed, or I’m not using xdm. KDE Plasma uses sddm I think. Btw. you would not believe, why I prefer KDE over gnome: I was unable to move taskbar from top to bottom :shame: Btw2 I like your footer :wink:

Ok, but who is that someone who tells him the user is about to login and to act? :wink:

Thanks, I hope someone knows. And yes, I’m aware what does curiosity do to cats :wink:

Looking at this:

https://jlk.fjfi.cvut.cz/arch/manpages/man/sddm.conf.5

Can you modify: /usr/share/sddm/scripts/Xsetup

Firstly, your “ecryptfs” file system is mounted via pam. So that happens during login.

Secondly: your user shell startup script (probably “.bashrc”) is run during session startup. The trick is to put some cross checks in there so that you only do your special stuff when needed, and skip it for other times that your user shell is started.

The default config shipped in openSUSE’s sddm package explicitly configures it to use /etc/X11/xdm/Xsetup instead.
See /usr/lib/sddm/sddm.conf.d/00-general.conf .

But: /run/user/xxx/ is created dynamically on login (by PAM), so it probably doesn’t exist yet when Xsetup is run.

No idea how to best create subdirectories there though…

But: you can set certain environment variables to override .cache, .config, and .local ($XDG_CACHE_HOME, $XDG_CONFIG_HOME, and $XDG_DATA_HOME respectively), so you don’t necessarily have to symlink those folders (and they do get created as needed).

.kde4 should normally not being used anymore anyway (there are only a few applications still being KDE4 based), although that can be changed via $KDE_HOME IIANM.

User does tell, by performing login. PAM framework handles user logins, so PAM modules run automatically during logging in before any other user process (like shell) is started.

I see, thank you. PAM is probably key to the solution, but no idea at what step create the dirs. Is the “1000” folder in ramdisk created via pam too? Maybe I should place mkdir commands right after it is created.

Thank you, I tried to set variables in /etc/environment, but after boot, before KDE login shows, I get error from sddm: “Configuration file ‘/run/user/1000/.config/sddm-greetrc’ not writable. Please contact your system administrator.” and after OK login does not work either, so I have to login via tty1, create dirs in ramdisk, kill KDE, which restarts and then login via GUI. Either KDE does not create folders specified by variables, or ramdisk is not ready at the time KDE login screen starts.

So where should I place my mkdir commands is still a mystery :frowning: I’m still creating dirs in ramdisk from /etc/profile.d, but I need to login twice, tty1 first, then via tty7 KDE login.

Yes, it is.

How about putting the script in /etc/X11/xinit/xinitrc.d/ ???

That sets it to /run/user/1000/.config/ for all users, and that cannot work because only user 1000 has access to /run/user/1000/.

Maybe try to set the variables (or run mkdir) in ~/.profile or ~/.bashrc .

Or maybe it would work to use $XDG_RUNTIME_DIR (which expands to /run/user/user_id/) instead of hardcoding the path.

Thank you all for helpful hints, I have not solved it with KDE, but I switched to tumbleweed with lxde, which leaves way less trails, so I don’t have to move everything to ramdisk, I just set correct permissions to few files :slight_smile: