#!/bin/sh 

#=======================================================================
# This script checks a directory tree for features which will cause 
# problems on a FAT32 filesystem
#=======================================================================

A=/tmp/tmp.$$.a
B=/tmp/tmp.$$.b
C=/tmp/tmp.$$.c
D=/tmp/tmp.$$.d
E=/tmp/tmp.$$.e
F=/tmp/tmp.$$.f

#-----------------------------------------------------------------------
# check for case folding conflicts
#-----------------------------------------------------------------------

DIRS=`find .. -type d`

cat /dev/null >${A}

for I in ${DIRS}
   do

   FILES=`/bin/ls ${I}`

   for J in ${FILES}
      do

      echo ${I}/${J}  >>${A}

   done

done

cat ${A} | tr '[A-Z]' '[a-z]' | sort | uniq -d >${B}

fgrep -ix -f ${B} ${A} >${C}

if [ -s ${C} ]
   then

   echo ""
   echo "The following case folding conflicts were found:"
   for I in `cat ${C}`
      do
      /bin/ls -ld ${I}
   done

fi

#-----------------------------------------------------------------------
# check for symbolic links
#-----------------------------------------------------------------------

find .. -type l -print >${D}

if [ -s ${D} ]
   then

   echo ""
   echo "The following symbolic links were found."
   cat ${D} | xargs /bin/ls -l

fi

#-----------------------------------------------------------------------
# check for hard links
#-----------------------------------------------------------------------

find .. -type f -exec /bin/ls -i {} \; >${E}

awk '{print $1}' ${E} | sort | uniq -d >${F}

if [ -s ${F} ]
   then

   echo ""
   echo "The following hard links were found."

   HARD=`fgrep -f ${F} ${E} | awk '{print $2}' `

   for I in ${HARD}
      do

      /bin/ls -li ${I}

   done

fi

rm ${A} ${B} ${C} ${D} ${E} ${F}
