#! /bin/bash
# Last edited on 2010-05-14 03:06:50 by stolfilocal

usage="${0##*/} DIRECTORY..."

if [[ $# -lt 1 ]]; then
  echo "usage: ${usage}" 1>&2 
  exit 1
fi

curd="`pwd`"

for dir in "$@" ; do

  cd "${curd}"

  if [[ -L ${dir} ]]; then
    echo "${dir} was just a symbolic link" 1>&2 
    /bin/rm ${dir}
  elif [[ ! -d ${dir} ]]; then
    echo "${dir}: not a directory" 1>&2 
  else 
    head="${dir%/*}"
    tail="${dir##*/}"
    if [[ "/$tail" != "/$dir" ]]; then cd ${head}; fi
    if [[ ! ("/${tail}" =~ ^/([09][0-9]|20[01][0-9])-[0-9][0-9]-[0-9][0-9]-.* ) ]]; then
      echo "${dir}: not a dated directory" 1>&2 
    else
      echo "removing ${dir}" 1>&2 
      ( /bin/chmod -R u+w ${tail} )
      /bin/rm -r ${tail}
    fi
  fi

done
