#! /bin/bash
#
# autologin
#
# description: logs in as a user docomomo
#
# Copyright (C) 2008 zunda <zunda at freeshell.org>
# 
# Permission is granted for copying, modification, distribution,
# and distribution of modified versions of this work under the
# terms of GPL version 2 or later.
#
# Read the GPL.txt fle or gpl-3.0.txt file for more details.
#

RETVAL=0
USER=docomomo

# check if the console is available
if [ -e /var/run/console/consle.lock ]; then
	cat /var/run/console/console.lock
	echo is already logged in
	exit 1
fi

# chown some device files
echo -n 1 > /var/run/console/$USER && \
echo -n $USER > /var/run/console/console.lock && \
pam_console_apply 
RETVAL=$?
[ $RETVAL -ne 0 ] && exit $RETVAL

# run the application
su - $USER -c /usr/bin/startx

# reset owner of some device files
rm /var/run/console/console.lock
pam_console_apply -r
exit $?
