While this solution will work for Ubuntu 22.04, since Ubuntu uses Wayland by default, this solution will stop working the moment Ubuntu stops shipping X11. In the worst case, the system will just boot to a tty terminal session and not load a GUI at all. SO I think you should put a disclaimer about this at the end..