#!/bin/sh
#
#  checkdir <directory>
#
#  Check a candidate top directory. Exit 1 if okay, exit 0 if trouble found.
#
tman=$1/SystemFiles/Installation/SystemResources/Manifests/installation

if [ -d $1 ]; then
   if [ -f $1/Install/math.install ]; then
      printm V22Found $1
   elif [ -w $tman -o -w $1/.install-manifest ]; then
      exit 1
   elif [ `ls -la $1 2>/dev/null | wc -l` -le 4 ]; then
      if (touch $1/.install-manifest 2> /dev/null); then
         rm -f $1/.install-manifest 2> /dev/null
         exit 1
      else
         printm NoWrite $1
      fi
   else
      printm OtherFound $1
   fi
elif (mkdir $1 2> /dev/null); then
   exit 1
else
   printm NotCreate $1
fi
exit 0
