#!/bin/bash

# User for auto-login (default 'iar')
AUTOLOGIN_USER="iar"

# LightDM configuration file path
LIGHTDM_CONFIG_FILE="/etc/lightdm/lightdm.conf"

# Backup the current configuration file if it hasn't been backed up already
if [ ! -f "${LIGHTDM_CONFIG_FILE}.bak" ]; then
    echo "Backing up the current LightDM configuration..."
    sudo cp "$LIGHTDM_CONFIG_FILE" "${LIGHTDM_CONFIG_FILE}.bak"
fi

# Enable auto-login for the specified user by uncommenting and modifying the relevant lines
echo "Enabling GUI auto-login for user: $AUTOLOGIN_USER"

# Uncomment the relevant lines and modify them to enable auto-login for the user 'iar'
sudo sed -i 's/^#autologin-user=/autologin-user=/' "$LIGHTDM_CONFIG_FILE"
sudo sed -i "s/^autologin-user=.*/autologin-user=$AUTOLOGIN_USER/" "$LIGHTDM_CONFIG_FILE"
sudo sed -i 's/^#autologin-user-timeout=/autologin-user-timeout=/' "$LIGHTDM_CONFIG_FILE"

echo "Auto-login enabled for user: $AUTOLOGIN_USER"
