#!/bin/sh

if [ "$#" -eq 0 ]
then
  echo "Must supply path to archive files"
  exit 1
fi

target="$1"

osname=`uname -s | sed -e 's/_NT-.*$/_NT/; s/^MINGW[0-9]*/CYGWIN/'`
if [ "$osname" = "CYGWIN_NT" -a -x /bin/cygpath ]
then
  target=`cygpath -w "$target"`
fi

target=${target%/}

if [ ! -d "$target" ]
then
  mkdir "$target"
fi

if [ ! -f "$target/CACHEDIR.TAG" ]
then
  cat >$target/CACHEDIR.TAG <<EOF
Signature: 8a477f597d28d172789f06886806bc55
# This file is a cache directory tag created by edirect.
# For information about cache directory tags, see:
#   http://www.brynosaurus.com/cachedir/
EOF
fi

if [ "$osname" = "Darwin" ]
then
  echo ""
  echo "  To prepare the disk for an EDirect archive, please disable:"
  echo ""
  echo "    Antivirus scanning"
  echo "    Spotlight indexing"
  echo "    Time Machine backups"
  echo ""
  echo "  for the '$target' directory."
  echo ""
fi

if [ "$osname" = "Linux" ]
then
  echo ""
  echo "  To prepare the disk for an EDirect archive, please disable:"
  echo ""
  echo "    Antivirus scanning"
  echo ""
  echo "  for the '$target' directory."
  echo ""
  echo "  You may also need to run a command like:"
  echo ""
  echo "    sudo mkfs -t ext4 -b 1024 -I 128 -i 4096 /dev/<device-name>"
  echo ""
  echo "  to configure the file system for a large number of inodes."
  echo ""
fi

if [ "$osname" = "CYGWIN_NT" ]
then
  echo ""
  echo "  To prepare the disk for an EDirect archive, please disable:"
  echo ""
  echo "    Antivirus scanning"
  echo ""
  echo "  for the '$target' directory."
  echo ""

  if reg query 'HKLM\System\CurrentControlSet\Control\FileSystem' \
    /v NtfsDisable8dot3NameCreation | fgrep -q 0x0
  then
    echo "  Also ask your administrator to set:"
    echo ""
    echo "    NtfsDisable8dot3NameCreation"
    echo ""
    echo "  in the Windows Registry."
    echo ""
  fi
fi
