#!/bin/sh
# DocumentId:	$Id: update-dpsyco-users-sudoers,v 1.5 2001/12/07 15:17:13 ola Exp $
# Author:	$Author: ola $
# Date:		$Date: 2001/12/07 15:17:13 $
# Summary:
#	Updates the dpsyco base administrators (sudoers).

SUDOERSF=/etc/sudoers
SUDOSRC=/etc/dpsyco/sudoers

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

TESTNFS="/ /etc"
. /usr/share/dpsyco/checknfs.test

cd $USERSRC

if [ ! -e $SUDOSRC ] ; then
    echo "root ALL=(ALL) ALL" >> $SUDOSRC
fi

echo "# This file is generated by dpsyco-sudo. Source is taken from $SUDOSRC" > $SUDOERSF
echo "# and from files in /usr/share/dpsyco/users." >> $SUDOERSF
echo "# Do not edit $SUDOERSF directly because that file will be" >> $SUDOERSF
echo "# overwritten each time update-dpsyco or update-dpsyco-users-sudoders" >> $SUDOERSF
echo "# is runned. This will happen when you install or update a package using apt." >> $SUDOERSF
cat $SUDOSRC >> $SUDOERSF
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
