#!/bin/sh
# DocumentId:	$Id: update-twinspot-users-sshaccess 1051 2001-08-08 13:19:55Z tomfa $
# Author:	$Author: tomfa $
# Date:		$Date: 2001-08-08 15:19:55 +0200 (ons, 08 aug 2001) $
# Summary:
#	Updates the twinspot base user access (via ssh).

# Read the default twinspot config.
. /usr/share/twinspot/defaults.conf

for TEST in / $DHOME ; do
    if mount | grep "on[[:space:]][[:space:]]*$TEST[[:space:]].*type[[:space:]][[:space:]]*nfs[[:space:]]" > /dev/null 2>&1 ; then
	echo "Does not regenerate authorized_keys when $TEST is nfsmounted."
	exit 0
    fi
done

# Users that exist in password file.

IFS=:
cat $PWDF | while read user junk uid gid gecos home shell ; do
    if [ "$user" != "" ] \
	&& [ "$uid" != "" ] \
	&& [ $uid -lt 1000 ] \
	&& sudo -u $user test -w $home \
	&& find "$USERSRC"/*/"$user" -printf "" 2>/dev/null
    then
	ISSH="$home/.ssh"
	IDENT="$ISSH/identity"
	IDENTP="$IDENT.pub"
	AUTHK="$ISSH/authorized_keys"
	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
    fi
done
