#!/bin/sh

PREREQ=""
DESCRIPTION="Setting up automatic login..."

. /scripts/casper-functions

prereqs()
{
       echo "$PREREQ"
}

case $1 in
# get pre-requisites
prereqs)
       prereqs
       exit 0
       ;;
esac

log_begin_msg "$DESCRIPTION"

if [ -d /root/etc/gdm ]; then
    # Configure GDM autologin
    cat > /root/etc/gdm/custom.conf <<EOF
[daemon]
AutomaticLoginEnable=true
AutomaticLogin=$USERNAME
TimedLoginEnable=true
TimedLogin=$USERNAME
TimedLoginDelay=10
EOF
fi

if [ -f /root/etc/kde4/kdm/kdmrc ]; then
    # Configure KDM autologin
    sed -i -r \
        -e "s/^#?AutoLoginEnable=.*\$/AutoLoginEnable=true/" \
        -e "s/^#?AutoLoginUser=.*\$/AutoLoginUser=$USERNAME/" \
        -e "s/^#?AutoReLogin=.*\$/AutoReLogin=true/" \
        /root/etc/kde4/kdm/kdmrc
fi

log_end_msg
