Replacing startplasma with shell scripts or dinit (Part 1)

Wait 5 sec.

I’m getting old (though, not as old as the image below), and I missthe good old days when using Linux was more difficult, but when everysystem in a Linux desktop session was simple.Excalibur (1981)This was before polkit, systemd, … Even before DBus and PulseAudio.All of these systems are cool and all, but I sometimes miss thesimplicity of “everything can be a shell script”.I’ve been playing around with something that made me investigate howthe Plasma session is started, and if I can replicate it withoutsignificant issues with a simple shell script or something else.It turns out it is not that difficult of a process, just a bitconvoluted.Your chosen display manager starts startplasma. A DBussession is created and startplasmacompositor (andkwin_wayland) is started. Then plasma_sessionstarts. And it starts kded6 and ksmserver.There are a few other things that are started as well (likekactivitymanagerd), but they are startedautomagically by DBus when another component tries to use theirDBus API.Moving to a shell scriptIn the old days, there was just a simple shell script calledstartkde which set the environment variables and startedall the needed processes for a working KDE (and later Plasma) session.It wasn’t pretty, it wasn’t efficient, but it did what it needed to.Se I decided to try to reimplement a rudimentary version of thatscript for the new Plasma.These are the basic environment variables you’d want set beforerunning a Plasma session (or other UI applications):# XDGexport XDG_SESSION_TYPE=waylandexport XDG_CURRENT_DESKTOP=KDEexport XDG_SESSION_DESKTOP=KDE# Qtexport QT_QPA_PLATFORM=waylandexport QT_WAYLAND_SHELL_INTEGRATION=xdg-shellexport QT_WAYLAND_DISABLE_WINDOWDECORATION=1export QT_AUTO_SCREEN_SCALE_FACTOR=0export QT_WAYLAND_RECONNECT=1# KDEexport DESKTOP_SESSION=plasmaexport KDE_FULL_SESSION=trueexport KDE_SESSION_VERSION=6I placed this into a seaprate script called env.sh as itis useful for testing to be able to initialize the same environment in ashell outside of startkde.Apart from these, if you have some custom installation paths for Qtor KDE things, you should also set PATH,XDG_DATA_DIRS, XDG_CONFIG_DIRS,QT_PLUGIN_PATH, QML2_IMPORT_PATH andQT_QUICK_CONTROLS_STYLE_PATH.If you have any custom environment variables defined in~/.config/plasma-workspace/env, you should add them here aswell (or source all the files from that directory).For the main script, just source env.sh, rundbus-update-activation-environment --all and start all thesession components mentioned above:source env.shdbus-update-activation-environment --allkwin_wayland --drm &KWIN_PID=$!sleep 1export WAYLAND_DISPLAY=wayland-0kactivitymanagerd &ksmserver &kded6 &plasmashell &krunner &# other things you want started along with Plasmawait $KWIN_PIDThe sleep 1 is evil and there are better ways to checkif wayland-0 became available, but this is a quick anddirty script after all. And the original startkde scriptalso had some sleeps in it.The only thing remaining is to create a session file that yourdisplay manager can use, and you’re good to go(/usr/share/wayland-session/shellscript-based-startplasma.desktop)):...Exec=dbus-run-session -- /path/to/the/script.sh...This seems to work without important issues, it just skips the splashscreen which I can live without (wow, ksplashqmlis 15 years old…).I didn’t test it for too long, as I quickly replaced this shellscript with a dinit-based setup, but more on that in thenext post.