#!/bin/sh
# DocumentId:	$Id: update-dpsyco-users-sshaccess,v 1.19 2001/12/07 15:45:11 ola Exp $
# Author:	$Author: ola $
# Date:		$Date: 2001/12/07 15:45:11 $
# Summary:
#	Updates the user access (via ssh).

# Read the default dpsyco config.
. /etc/dpsyco/defaults.conf

TESTNFS="/ $DHOME"
. /usr/share/dpsyco/checknfs.test

# Users that exist in password file.

IFS=:
cat $PWDF | while read user junk uid gid gecos home shell ; do
    if [ "$user" != "" ] \
	&& [ "$user" != "+" ] \
	&& [ "$uid" != "" ] \
	&& [ $uid -le $LAST_UID ] \
	&& sudo -u $user test -w $home \
	&& find "$USERSRC"/*/"$user" -printf "" 2>/dev/null
    then
	ISSH="$home/.ssh"
	IDENT="$ISSH/identity"
	IDENTP="$IDENT.pub"
	A1=authorized_keys
	AUTHK="$ISSH/$A1"
	A2=authorized_keys2
	AUTHK2="$ISSH/$A2"
	if [ ! -e $IDENTP ] ; then
	    echo "Gen authorized_keys for $user."
	    sudo -H -u $user ssh-keygen -N "" -f "$IDENT"
	fi
	if [ -e $ISSH ] ; then
	    > "$AUTHK"
	    find "$ISSH" "$USERSRC"/*/"$user" -name "*.pub" -type f \
	    | while read i ; do
		cat "$i" >> "$AUTHK"
	    done
	fi
	if [ ! -e "$AUTHK2" ] ; then
	    ln -s $A1 $AUTHK2
	fi
	chown $uid.$gid $AUTHK
	chown $uid.$gid $AUTHK2
    fi
done
