After reading up the .post*
, '.pre*' and .config
scripts of gdm3
and lightdm
I have found a way to run dpkg-reconfigure
interactively to change between the display managers and keep the magic of the mentioned pre
, post
and config
scripts.
All you have to do is to update the /etc/X11/default-display-manager file with the display manager binary you want to change to. Then run dpkg-reconfigure
non-interactively and you are done. Well, gdm3
does not update the debconf
database, whereas lightdm
does, but that is OK to do that manually.
Here we go...
Change from lightdm
to gdm3
.
$ echo "/usr/sbin/gdm3"> /etc/X11/default-display-manager$ DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure gdm3$ echo set shared/default-x-display-manager gdm3 | debconf-communicate
Change from gdm3
to lightdm
.
$ echo "/usr/sbin/lightdm"> /etc/X11/default-display-manager$ DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure lightdm$ echo set shared/default-x-display-manager lightdm | debconf-communicate
As already mentioned the last step echo set shared/default-x-display-manager lightdm | debconf-communicate
is not really necessary here as the scripts of lightdm
will take care of it. But for the sake of a simplified script it does not hurt to set it.
Putting things together into a shell script could be as follows. One could add more control if needed.
$ cat set_dm.sh#!/bin/bashset_dm() { DISPLAY_MANAGER="gdm3" DISPLAY_MANAGER_SERVICE="/etc/systemd/system/display-manager.service" DEFAULT_DISPLAY_MANAGER_FILE="/etc/X11/default-display-manager" if [ -n "${1}" ] then DISPLAY_MANAGER="$1" fi DISPLAY_MANAGER_BIN="/usr/sbin/${DISPLAY_MANAGER}" if [ ! -e "${DISPLAY_MANAGER_BIN}" ] then echo "${DISPLAY_MANAGER} seems not to be a valid display manager or is not installed." exit 1 fi echo "${DISPLAY_MANAGER_BIN}"> "${DEFAULT_DISPLAY_MANAGER_FILE}" DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true dpkg-reconfigure "${DISPLAY_MANAGER}" echo set shared/default-x-display-manager "${DISPLAY_MANAGER}" | debconf-communicate &> /dev/null echo -n "systemd service is set to: " readlink "${DISPLAY_MANAGER_SERVICE}" echo -n "${DEFAULT_DISPLAY_MANAGER_FILE} is set to: " cat "${DEFAULT_DISPLAY_MANAGER_FILE}" echo -n "debconf is set to: " echo get shared/default-x-display-manager | debconf-communicate }set_dm $1
The two variables DEBIAN_FRONTEND=noninteractive
and DEBCONF_NONINTERACTIVE_SEEN=true
are needed to really run interactively.
What also helped was the environment variable DEBCONF_DEBUG
to see what debconf
is doing. It can be set to
user
developer
db
.*
which is all of the above