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

# Main window dialogue.
 CONFIGURE_TITLE="Enable Auto Login
-----------------------------------------------------------------------------------------------------
This will Enable Auto Login.
Next time you restart your computer, you will be automatically logged in.

-----------------------------------------------------------------------------------------------------
Click on Yes to continue or No to cancel."

# Call the zenity window icon location.
 INSTALL_ICON="/usr/share/icons/zenity-llcc.png"
 CONFIGURE="Enable Auto Login"
        
        zenity --question --title="$CONFIGURE" --window-icon="${INSTALL_ICON}" --text="${CONFIGURE_TITLE}"

                if [ "$?" -eq "0" ]; then
                        gksudo -g --message 'To proceed with this setting your password is required. Enter your password, or press Cancel.' "sed -i "s/autologin-user=linux/autologin-user=$USER/g" /etc/lightdm/lightdm.conf" | zenity --progress --title="$CONFIGURE" --window-icon="${INSTALL_ICON}" --text="Please wait whilst we enable $CONFIGURE..." --pulsate --width=400 --auto-close --auto-kill


                                if [ "${PIPESTATUS[0]}" -ne "0" ]; then
                        
                                        zenity --error \
                                        --title="Error" --text="$CONFIGURE has not been applied."
                                        exit 0
                                fi

                else

                                        exit 0
                fi


PROCEED=$(zenity --info --title="$CONFIGURE" --window-icon=/usr/share/icons/zenity-llcc.png --text="Auto Login has been Enabled."; echo $?)
if [ ${PROCEED} -eq 1 ]; then
	zenity --info --title="Finished" --window-icon="${INSTALL_ICON}" --text="Auto Login Enabled."
	exit;
else
	exit
fi

exit 0
