#!/bin/sh
# I want to "be myself" on the ITB.  This script writes into /tmp/pickuser
# the sequentially first user in /etc/passwd whose primary group is "users".
# For a multiuser setup you need to do this at S21 1/2 (after the X-server
# and before af-services), showing a menu, getting a password, etc.

# Copyright (c) 2006 by James F. Carter (jimc@math.ucla.edu>
# 2006-08-27, for Maemo-2.0 (Nokia 770)

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You can find the GNU General Public License in your Maemo distribution
# as /usr/share/common-licenses/GPL-2; if it's missing, write to the 
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA 02111-1307, USA.


case "$1" in
    start )
	group=`awk 'BEGIN {FS=":"} $1 == "users" {print $3 ; exit}' /etc/group`
	user=`awk -v grp=${group:=29998} 'BEGIN {FS=":"} $4 == grp {print $1 ; exit}' /etc/passwd`
	echo ${user:=user} > /tmp/pickuser
	if [ $user != "user" ] ; then
	    rm -f /tmp/session_bus_address.user
	    ln -s session_bus_address.$user /tmp/session_bus_address.user
	fi
	;;
    stop )
	:	# Does nothing
	;;
    * )
	echo "Unrecognized action parameter '$1'"
	exit 4
	;;
esac

