From 3ecd031d9d466a2f026192083c532f78d27dc287 Mon Sep 17 00:00:00 2001 From: The feren OS Dev Date: Mon, 15 Apr 2019 15:01:08 +0100 Subject: [PATCH 1/4] Better LightDM Autologin Support This change fixes a few issues and adds a few improvements to the LightDM Autologin configuration process: Fixes: - Fixes malforming of configuration file out of the box, as without `[SeatDefaults]`, `[Seat:*]` or similar in the configuration file LightDM will break on a lot of distributions using LightDM - Preserves the intended lightdm.conf file settings outside of `autologin-user` if the distribution has an /etc/lightdm/lightdm.conf file of its own Misc. changes: - Small spelling fix --- src/modules/displaymanager/main.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/modules/displaymanager/main.py b/src/modules/displaymanager/main.py index 4413aefbb..3b2394b52 100644 --- a/src/modules/displaymanager/main.py +++ b/src/modules/displaymanager/main.py @@ -487,31 +487,45 @@ class DMlightdm(DisplayManager): self.root_mount_point, "etc/lightdm/lightdm.conf" ) text = [] + addseat = False + loopcount = 0 if os.path.exists(lightdm_conf_path): with open(lightdm_conf_path, 'r') as lightdm_conf: text = lightdm_conf.readlines() + # Check to make sure [SeatDefaults] or [Seat:*] is in the config, + # otherwise we'll risk malforming the config + if not '[SeatDefaults]' in text and not '[Seat:*]' in text: + addseat = True with open(lightdm_conf_path, 'w') as lightdm_conf: + if addseat: + # Append Seat line to start of file rather than leaving it without one + # This keeps the config from being malformed for LightDM + text = ["[Seat:*]\n"] + text + loopcount = 0 for line in text: if 'autologin-user=' in line: if do_autologin: line = "autologin-user={!s}\n".format(username) else: line = "#autologin-user=\n" + text[loopcount] = line + loopcount += 1 - lightdm_conf.write(line) + lightdm_conf.write("".join(text)) + loopcount = 0 else: try: # Create a new lightdm.conf file; this is documented to be - # read last, after aeverything in lightdm.conf.d/ + # read last, after everything in lightdm.conf.d/ with open(lightdm_conf_path, 'w') as lightdm_conf: if do_autologin: lightdm_conf.write( - "autologin-user={!s}\n".format(username)) + "[Seat:*]\nautologin-user={!s}\n".format(username)) else: lightdm_conf.write( - "#autologin-user=\n") + "[Seat:*]\n#autologin-user=\n") except FileNotFoundError: return ( _("Cannot write LightDM configuration file"), From c0d61b666dd8e6254c21e922ce2344a729e1e179 Mon Sep 17 00:00:00 2001 From: The feren OS Dev Date: Tue, 16 Apr 2019 16:52:02 +0100 Subject: [PATCH 2/4] Made amendments based on review Fixed 'prepend' terminology in comments, restored old loop as it seems to work for me now in overwriting the file as one overall multiline instead of overwriting the file with each line at a time, code simplification based on review comments... credits-adding will come in the next commit. --- src/modules/displaymanager/main.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/modules/displaymanager/main.py b/src/modules/displaymanager/main.py index 3b2394b52..11b4c0b41 100644 --- a/src/modules/displaymanager/main.py +++ b/src/modules/displaymanager/main.py @@ -495,26 +495,21 @@ class DMlightdm(DisplayManager): text = lightdm_conf.readlines() # Check to make sure [SeatDefaults] or [Seat:*] is in the config, # otherwise we'll risk malforming the config - if not '[SeatDefaults]' in text and not '[Seat:*]' in text: - addseat = True + addseat = '[SeatDefaults]' not in text and '[Seat:*]' not in text with open(lightdm_conf_path, 'w') as lightdm_conf: if addseat: - # Append Seat line to start of file rather than leaving it without one + # Prepend Seat line to start of file rather than leaving it without one # This keeps the config from being malformed for LightDM text = ["[Seat:*]\n"] + text - loopcount = 0 for line in text: if 'autologin-user=' in line: if do_autologin: line = "autologin-user={!s}\n".format(username) else: line = "#autologin-user=\n" - text[loopcount] = line - loopcount += 1 - lightdm_conf.write("".join(text)) - loopcount = 0 + lightdm_conf.write(line) else: try: # Create a new lightdm.conf file; this is documented to be From a79dfa413526c9ae1f18b73a420e766f58c8b046 Mon Sep 17 00:00:00 2001 From: The feren OS Dev Date: Tue, 16 Apr 2019 16:58:19 +0100 Subject: [PATCH 3/4] Added myself to the copyright header --- src/modules/displaymanager/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/displaymanager/main.py b/src/modules/displaymanager/main.py index 11b4c0b41..639edbea7 100644 --- a/src/modules/displaymanager/main.py +++ b/src/modules/displaymanager/main.py @@ -3,6 +3,7 @@ # # === This file is part of Calamares - === # +# Copyright 2019 Dominic Hayes # Copyright 2014-2018, Philip Müller # Copyright 2014-2015, Teo Mrnjavac # Copyright 2014, Kevin Kofler From 3a8a8d3f17aec561e849c822b1c934bac4346988 Mon Sep 17 00:00:00 2001 From: The feren OS Dev Date: Tue, 16 Apr 2019 17:00:05 +0100 Subject: [PATCH 4/4] Update CHANGES --- CHANGES | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGES b/CHANGES index 3573f2098..9fcfc7b00 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,7 @@ website will have to do for older versions. # 3.2.6 (unreleased) # This release contains contributions from (alphabetically by first name): + - Dominic Hayes (feren) ## Core ##