#! /bin/sh

test "X${VERBOSE}" = Xtrue && {
  set -x
  PS4="> "
}

current_dir=`pwd`
TMPDIR=${TMPDIR=/tmp}
export TMPDIR
testname=shar-3
testdir=${TMPDIR}/${testname}-$$.d
rm -rf ${testdir}
(umask 077 ; mkdir ${testdir}) || exit 1
opts="-o ${testdir}/${testname}-%04d.shar"
opts="${opts} -L256K -n ${testname}-test -s ${testname}"

shar=`cd ../src ; pwd`/shar
unshar=`cd ../src ; pwd`/unshar
top_builddir=`cd ${top_builddir} ; pwd`

nocompression=false
cd ${top_builddir}
tmpfiles=$(find * -type f -name '*~')
test -n "$tmpfiles" && rm -f $tmpfiles
{
  ctypes='gzip bzip2 xz'
  for f in `ls -1A`
  do
    case "`file $f`" in

    *'directory'* | *text*'long lines'* )
      echo --compact=`set -- $ctypes ; echo $1`
      ctypes=`set -- $ctypes ; echo $2 $3 $1`
      nocompression=false
      ;;

    *' text' )
      $nocompression || {
        echo --compact=none
        nocompression=true
      }
      ;;

    * )
      echo --compact=`set -- $ctypes ; echo $1`
      ctypes=`set -- $ctypes ; echo $2 $3 $1`
      nocompression=false
      ;;
    esac
    echo $f
  done
} > ${testdir}/list
${shar} -pq ${opts} -I${testdir}/list

mkdir ${testdir}/${testname}.d
cd ${testdir}/${testname}.d

for f in ../${testname}-*.shar
do
  ${unshar} ${f} || exit 1
done >/dev/null

cd ..
if diff -r ${top_builddir} ${testname}.d
then :
else
  echo ${top_builddir} and ${testdir}/${testname}.d differ
  exit 1
fi

cd ${current_dir}
rm -rf ${testdir}
exit 0

## Local Variables:
## mode: shell-script
## tab-width: 8
## indent-tabs-mode: nil
## sh-indentation: 2
## sh-basic-offset: 2
## End:

## end of shar-3
