From b7f9b2e76faee7a417b6c2e59a6e0b23bbe341a7 Mon Sep 17 00:00:00 2001
From: Luiz Reis <luizreis@outlook.com>
Date: Fri, 23 Oct 2015 10:19:33 -0200
Subject: [PATCH] [autologin] Add autologin script, that runs before kdm

Signed-off-by: Luiz Reis <luizreis@outlook.com>
---
 .../etc/systemd/system/autologin.service      | 12 ++++++++
 .../multi-user.target.wants/autologin.service | 12 ++++++++
 .../opt/openslx/scripts/systemd-autologin     | 29 +++++++++++++++++++
 3 files changed, 53 insertions(+)
 create mode 100644 server/modules/autologin/etc/systemd/system/autologin.service
 create mode 100644 server/modules/autologin/etc/systemd/system/multi-user.target.wants/autologin.service
 create mode 100755 server/modules/autologin/opt/openslx/scripts/systemd-autologin

diff --git a/server/modules/autologin/etc/systemd/system/autologin.service b/server/modules/autologin/etc/systemd/system/autologin.service
new file mode 100644
index 00000000..415c4c79
--- /dev/null
+++ b/server/modules/autologin/etc/systemd/system/autologin.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Runs the OpenSLX Autologin Tool
+After=tmp.target
+Before=kdm.service
+Wants=tmp.target
+DefaultDependencies=no
+ConditionPathIsMountPoint=/
+
+[Service]
+Type=oneshot
+ExecStart=/opt/openslx/scripts/systemd-autologin
+RemainAfterExit=yes
diff --git a/server/modules/autologin/etc/systemd/system/multi-user.target.wants/autologin.service b/server/modules/autologin/etc/systemd/system/multi-user.target.wants/autologin.service
new file mode 100644
index 00000000..415c4c79
--- /dev/null
+++ b/server/modules/autologin/etc/systemd/system/multi-user.target.wants/autologin.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Runs the OpenSLX Autologin Tool
+After=tmp.target
+Before=kdm.service
+Wants=tmp.target
+DefaultDependencies=no
+ConditionPathIsMountPoint=/
+
+[Service]
+Type=oneshot
+ExecStart=/opt/openslx/scripts/systemd-autologin
+RemainAfterExit=yes
diff --git a/server/modules/autologin/opt/openslx/scripts/systemd-autologin b/server/modules/autologin/opt/openslx/scripts/systemd-autologin
new file mode 100755
index 00000000..78bf2cf5
--- /dev/null
+++ b/server/modules/autologin/opt/openslx/scripts/systemd-autologin
@@ -0,0 +1,29 @@
+#!/bin/bash
+# simple script for setting autologin on or off on display manager
+# works for kdm
+# SLX_AUTOLOGIN_ACTIVE is the flag which indicates if the computer should autologin or not
+# SLX_AUTOLOGIN_USER is the username to autologin
+# SLX_AUTOLOGIN_PASS is the user's password to autologin
+# SLX_AUTOLOGIN_DELAY is the delay to autologin
+
+# dialog aux functions
+perror () {
+  echo "ERROR: $@" 1>&2
+  dialog --title "ERROR" --stdout --msgbox "$@" 15 60
+  exit 1
+}
+
+. /opt/openslx/config || perror "Could not source config."
+
+kdm_file="/etc/kde4/kdm/kdmrc"
+echo "[autologin] Updating AutoLoginEnable to $SLX_AUTOLOGIN_ACTIVE in $kdm_file"
+sed -e 's/AutoLoginEnable=.*$/AutoLoginEnable='$SLX_AUTOLOGIN_ACTIVE'/g' $kdm_file > $kdm_file".tmp" && mv $kdm_file".tmp" $kdm_file
+echo "[autologin] Updating AutoLoginDelay to $SLX_AUTOLOGIN_DELAY in $kdm_file"
+sed -e 's/AutoLoginDelay=.*$/AutoLoginDelay='$SLX_AUTOLOGIN_DELAY'/g' $kdm_file > $kdm_file".tmp" && mv $kdm_file".tmp" $kdm_file
+if [ $(cat $kdm_file | grep "AutoLoginUser") ]; then
+  echo "[autologin] Updating AutoLoginUser to $SLX_AUTOLOGIN_USER in $kdm_file"
+  sed -e 's/AutoLoginUser=.*$/AutoLoginUser='$SLX_AUTOLOGIN_USER'/g' $kdm_file > $kdm_file".tmp" && mv $kdm_file".tmp" $kdm_file
+else
+  echo "[autologin] Creating AutoLoginUser as $SLX_AUTOLOGIN_USER in $kdm_file"
+  sed -e 's/AutoLoginEnable=.*$/AutoLoginEnable='$SLX_AUTOLOGIN_ACTIVE'\nAutoLoginUser='$SLX_AUTOLOGIN_USER'/g' $kdm_file > $kdm_file".tmp" && mv $kdm_file".tmp" $kdm_file
+fi
-- 
GitLab