#!/bin/sh

# SynchronizeDelete.sh
# 2008-01-29
# Chieh Cheng
# http://www.CynosureX.com/

# GNU General Public License (GPL), Version 2, June 1991

scriptPath=`dirname $0`
eliminateFile="${scriptPath}/SynchronizeEliminate.txt"

remove ()
{
  path="$1"

  printf "${path} . . . "

  if [ -f "${path}" ]
  then
    rm "${path}"
    printf "file deleted!"
  fi

  if [ -d "${path}" ]
  then
    rm -r "${path}"
    printf "directory deleted!"
  fi

  echo
}

if [ -f "${eliminateFile}" ]
then
  cat "${eliminateFile}" |
  while read line
  do
    if [ "${line}" != "" ]
    then
      mask=`basename "${line}"`
      where.sh "${mask}" |
      while read entry
      do
        match=`echo "${entry}" | grep -c "${line}"`
        if [ ${match} -eq 1 ]
        then
          remove "${entry}"
        fi
      done
    fi
  done
else
  echo "${eliminateFile} does not exist; nothing to delete."
fi

