From f196b0147ffbf380d2b88b87f9a0168fa1c567b0 Mon Sep 17 00:00:00 2001
From: Alberto LIVIO BECCARIA <alberto.liviobeccaria@uniupo.it>
Date: Thu, 24 Jun 2021 15:03:25 +0200
Subject: [PATCH] Autologin per LightDM

---
 bin-ubuntu/lightdm-autologin                | 49 +++++++++++++++++++++
 bin-ubuntu/{dm-autologin => sddm-autologin} |  0
 systemd-ubuntu/esame-dm-autologin.service   |  6 +--
 3 files changed, 52 insertions(+), 3 deletions(-)
 create mode 100755 bin-ubuntu/lightdm-autologin
 rename bin-ubuntu/{dm-autologin => sddm-autologin} (100%)

diff --git a/bin-ubuntu/lightdm-autologin b/bin-ubuntu/lightdm-autologin
new file mode 100755
index 0000000..c7f6955
--- /dev/null
+++ b/bin-ubuntu/lightdm-autologin
@@ -0,0 +1,49 @@
+#!/bin/bash
+
+clear() {
+    sed -i '/autologin-user=/s/^#*/#/' /etc/lightdm/lightdm.conf
+    sed -i '/session-cleanup-script=/s/^#*/#/' /etc/lightdm/lightdm.conf
+}
+
+dm_restart() {
+    systemctl restart display-manager.service
+}
+
+stop() {
+    clear
+    #dm_restart
+}
+
+start() {
+    echo "LightDM AUTOLOGIN FOR ${ESAME_USER}"
+
+    # 1) .* get expanded by the shell if in double quotes...
+    # 2) $ESAME_USER does not get expanded if in single quotes...
+    # 3) We want the former as is, and the latter expanded.
+    # So, one solution is the following:
+    SEDCMD="/#*autologin-user=.*/s/"'.*'"/autologin-user=$ESAME_USER/"
+    sed -i "$SEDCMD" /etc/lightdm/lightdm.conf
+    # enable auto-relogin (remove the comment in the file)
+    sed -i '/session-cleanup-script=/s/^#*//' /etc/lightdm/lightdm.conf
+
+    #sleep 5
+    dm_restart
+}
+
+case "$1" in
+'start')
+    start
+    ;;
+'stop')
+    stop
+    ;;
+'restart')
+    stop
+    start
+    ;;
+*)
+    echo "Usage: $0 { start | stop | restart }";
+    exit 1;
+    ;;
+esac
+exit 0
diff --git a/bin-ubuntu/dm-autologin b/bin-ubuntu/sddm-autologin
similarity index 100%
rename from bin-ubuntu/dm-autologin
rename to bin-ubuntu/sddm-autologin
diff --git a/systemd-ubuntu/esame-dm-autologin.service b/systemd-ubuntu/esame-dm-autologin.service
index 908c74d..7d70332 100644
--- a/systemd-ubuntu/esame-dm-autologin.service
+++ b/systemd-ubuntu/esame-dm-autologin.service
@@ -1,13 +1,13 @@
 [Unit]
-Description=KDM Autologin
+Description=DM Autologin
 After=esame-mk-homedir.service esame-desktop-wallpaper.service esame-firefox-home.service esame-virtualbox.service
 
 [Service]
 Type=oneshot
 RemainAfterExit=yes
 EnvironmentFile=-/local/esame-machine.conf
-ExecStart=/usr/libexec/labmanager/dm-autologin start
-ExecStop=/usr/libexec/labmanager/dm-autologin stop
+ExecStart=/usr/libexec/labmanager/lightdm-autologin start
+ExecStop=/usr/libexec/labmanager/lightdm-autologin stop
 
 [Install]
 WantedBy=esame.target esamekiosk.target esameshow.target
-- 
GitLab