#!/bin/sh
# DocumentId:	$Id: update-twinspot-users-sudoers 1009 2001-07-29 11:42:23Z olalu $
# Author:	$Author: olalu $
# Date:		$Date: 2001-07-29 13:42:23 +0200 (sön, 29 jul 2001) $
# Summary:
#	Updates the twinspot base administrators (sudoers).

SUDOERSF=/etc/sudoers
SUDOSRC=/usr/share/twinspot-base/sudoers

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

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

cd $USERSRC

if [ -f $SUDOSRC ] ; then
    cp -f $SUDOSRC $SUDOERSF
else
    echo "root ALL=(ALL) ALL" > $SUDOSRC
fi
chmod 0440  $SUDOERSF

for P in * ; do
    if [ -d $P -a "$P" != "." -a "$P" != ".." -a "$P" != "CVS" ] ; then
	cd $P
	for U in * ; do
	    if [ -d $U -a "$U" != "." -a "$U" != ".." -a "$P" != "CVS" ] ; then
		if [ -f $U/sudo ] ; then
		    cat $U/sudo | sed -e "s/#.*//" | grep -v "^$" | {
			while read -e SL ; do
			    if ! grep "$U $SL" $SUDOERSF > /dev/null 2>&1 ; then
				echo "$U $SL" >> $SUDOERSF
			    fi
			done
		    }
		fi
	    fi
	done
	cd ..
    fi
done
