#! /bin/sh 
#
#   Copyright (c) 1989-1993 Frame Technology Corp. All rights reserved.
#
#   $Id: fmcheckinstall,v 1.4 1992/11/06 05:39:16 adl Exp $
# 
# TODO:
#  . verify directory permissions on groupsettings & annotate.fm?

cd $FMHOME
admdir=$FMHOME/.install

# Determine which flavor of sum to use.
echo "x" > /tmp/fmsum.$$
sum /tmp/fmsum.$$ > /tmp/fmsum2.$$
read xsum blk < /tmp/fmsum2.$$
rm -f /tmp/fmsum.$$ /tmp/fmsum2.$$

sumcmd='sum -r'
[ "$xsum" = '00070' ] && sumcmd='sum'

setlist="`eval echo $admdir/*.x`"
[ $# != 0 ] && {
   # the user wants to specify the filesets
   setlist=""
   for i in $@
   do
      # make sure the setlist is how we like it
      name=$admdir/`basename $i .x`.x
      setlist="$setlist $name"
   done
}

echo "Checking installation of:"
cat $FMHOME/.VERSION
echo ""
for option in $setlist
do
   echo checking `basename $option .x`:

   sumfile=$option
   < $sumfile (
      #file names can contain spaces, but not tabs
      IFS='	'
      while
	 read file sum size perm
      do
	 if [ "$sum" = "<>" ]; then
	    link=$size
	    fileinode=`/bin/ls -id "$file" | sed -e 's/[ 	].*//'
	    linkinode=`/bin/ls -id "$link" | sed -e 's/[ 	].*//'
	    [ "$fileinode" != "$linkinode" ] && \
	       echo "$file is not linked to $link"
	 elif $FMHOME/bin/scripts/isslink "$file"; then
	    if [ "$sum" = "->" ]; then
	       link=$size
	       newlink=`$FMHOME/bin/scripts/isslink -l "$file"`
	       [ "$link" != "$newlink" ] && \
		  echo "$file is a sym link to a new place"
	    else
	       echo "$file was a file, now is a sym link"
	    fi
	 elif [ -f "$file" ]; then
	    saveifs=$IFS
	    eval $sumcmd "$file" > /tmp/fmch.$$
	    IFS=' '
	    read newsum blks < /tmp/fmch.$$
	    rm -f /tmp/fmch.$$
	    IFS=$saveifs
	    [ "$sum" != "$newsum" ] && echo "$file has changed"
	    
	    # Check permissions
	    > /tmp/fmvi.$$
	    chmod $perm /tmp/fmvi.$$
	    stp=`ls -l /tmp/fmvi.$$ | \
	       sed -e 's/[ 	].*//' -e s'/^.//'`
	    ttp=`ls -l "$file" | \
	       sed -e 's/[ 	].*//' -e s'/^.//'`
	    [ $stp != $ttp ] && echo "The permissions on $file have changed."
	    rm -f /tmp/fmvi.$$
	 else
	    echo "$file missing"
	 fi
      done
   )
done

#
# Check generated files (currently there is only one)
# 

$FMHOME/bin/scripts/isslink ./fminit/fontdir/fontlist || \
    echo "There is no fontlist link in fminit/fontdir"


echo "Done."
