#!/bin/bash
#--------------------------------------------
# Description: Linux Lite Auto Login Dialogue
# Authors: Jerry Bezencon, Ralphy
# Website: https://www.linuxliteos.com
#--------------------------------------------

# variables
APPNAME="Disable Auto Login"
ic="/usr/share/icons/Papirus/24x24/apps/liteautologin.png"		# dialog icon 24x24 PNG
EALUSER=$(whoami)
TMPF="/tmp/autologin"
if [ ! -f "$TMPF" ]; then echo "$EALUSER" > "$TMPF"; chmod 600 "$TMPF"; else :; fi
if [ $EUID -ne 0 ]; then pkexec $0; if [ "${PIPESTATUS[@]}" -eq "126" ]; then rm -f "$TMPF"; fi; exit; else :; fi


# Main window dialogue.
zenity --question --icon-name="info" --window-icon="$ic" --ok-label="$APPNAME" --cancel-label="Cancel" --width="360" --height="60" --title="$APPNAME" \
       --text='<span font="12">You are about to Disable Auto Login</span>\n\nFrom the next session onwards, you will be prompted for your password to login.\n \
Make sure you remember your account password before restarting the computer.' 2>/dev/null

if [ "$?" -eq "0" ]; then
    sed -i "s/autologin-user=.*/autologin-user=linux/g" /etc/lightdm/lightdm.conf
        if [ "${PIPESTATUS[0]}" -eq "0" ]; then
                zenity --info --width="240" --height=40 --timeout=3 --title="   $APPNAME" --window-icon=$ic --text="\nAuto Login has been disabled." 2>/dev/null
                exit 0
        else
                zenity --error --width="320" --height="40" --title="$APPNAME - Error" --text="\nAn error occurred while disabling Auto Login." 2>/dev/null
                continue
        fi
else
    exit 0
fi
done
exit 0
