#!/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/zenity-llcc.png"
# check if autologin is enabled
if grep -q -x "autologin-user=linux" /etc/lightdm/lightdm.conf; then
  zenity --question --width="280" --height=40 --title="   $APPNAME" --window-icon=$ic \
         --text="\n<b>Auto Login is currently not enabled</b>. \n\nAre you looking to Enable Auto Login instead?" 2>/dev/null
    if [ "$?" -eq "0" ]; then
      bash /usr/scripts/autologin-e; exit 0
    else exit 0
    fi
else
  :
fi
# continue
if [ $EUID -ne 0 ]; then pkexec $0; exit; else :; fi
while (true); do
# 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 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="200" --height=40 --timeout=3 --title="   $APPNAME" --window-icon=$ic --text="\nAuto Login has been disabled." 2>/dev/null
                exit 0
        else
                zenity --error --width="260" --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
