#!/bin/csh
# sfingerd package support script
# can be run regulary to update users files...
# if you don't trust the users, just comment the 'chown' in make files
# and update yourself with this proc regulary... ($user file will be
# rebuilt when ~$user/.plan is newer)
# (imo letting users do what they want with their finger output is better 
#  but if you are really paranoiac, you can use this solution...)
# May 10 1994 - Laurent Demailly - dl@hplyot.obspm.fr
# from sfingerd's 'make-files' script...

# Configure below :

# if your awk syntax is :
# awk [-F fs] [-v var=value] [prog | -f file ... ] [file ...]
# keep the following :
set AWK1="-v skip=1"
set AWK2=""
# if your awk syntax is :
# awk [ -f program-file ] [ -Fc ] [ program ] [ variable=value ] ...
# (like some SUN OS), uncomment below :
# set AWK1=""
# set AWK2="skip=1"

# check that this is the same one as in sfingerd.c & make-files :
set CHROOT_PATH=/usr/local/etc/fingerdroot

umask 022
unalias ls
if ( ! -d $CHROOT_PATH ) then
echo "$CHROOT_PATH don't exist, never run 'make-files' ??"
exit 1
endif

cd $CHROOT_PATH

# for each user that already have a file :
foreach user ( `\ls | egrep -v '^W|~$'` )
echo -n "working on $user..."
awk -F: -v u=$user '$1==u {exit 1}' /etc/passwd >& /dev/null
if ( $status ) then
  if ( ! -f ~$user/.plan ) then
    echo " nothing changed, no ~$user/.plan..."
  else
    ( ls -l $user | egrep -v "^-......... +1 " ) >& /dev/null 
    if ( $status == 0 ) then
      echo " $user/.plan file is a link or special, no changes..."
      continue
    endif
    @ size=`ls -s ~$user/.plan|awk '{print $1}'`
    if ( $size > 20 ) then
      echo " "
      echo " big ~$user/.plan, no changes..."
      continue
    endif
    find $user -newer ~$user/.plan >& /dev/null
    if ( "X`find $user -newer ~$user/.plan`" == "X" ) then
      # remove sensible informations, get only one copy :
      # ( maybe needs tailoring depending on your 'finger' output and the
      #   amount of data you want to remove/keep )
      finger $user | awk $AWK1 '/^Login name:/ || /^Login:/ {if (skip==1) skip=0; else skip=2;} \
       /^Last login/ || /^Directory:/ || /^Never logged in/ || /^    from / || /^On since/ || /Idle Time$/ || /^No unread mail/ || /^No Mail./ || /^New mail/ || /^Mail last read/ || /unread since/ || /^Bldg:/ {skip++} \
      skip==0 {print $0} skip==1 {skip=0}' $AWK2 >! $user
      #chown $user $user
      echo " successfully changed $CHROOT_PATH/$user."
    else
      echo " .plan didn't changed, no changes..."
    endif
  endif
else
  echo " not a real user... no changes..."
endif
end
echo "*** All done, have a look at the files in $CHROOT_PATH."
