#!/bin/sh

################################################################################
# Script name:  dirdupe_v1.0.sh                                                #
# Author:       SoD                                                            #
# Contact:      SoD- @ EFNet                                                   #
# Releasedate:  2001-05-01                                                     #
#                                                                              #
# This script is executed by glftpd before a directory is created and then     #
# checks if a directory with the same name already exists in the dupelog. If   #
# it exists, the name and date of the last match is presented.                 #
#                                                                              #
# Installation: -Put this file in some approperiate place, for example         #
#                /glftpd/bin/dirdupe_v1.0.sh                                   #
#               -Make it executable (chmod 755 /glftpd/bin/dirdupe_v1.0.sh)    #
#               -Edit glftpd.conf and change the line with pre_dir_check to:   #
#                pre_dir_check /bin/dirdupe_v1.0.sh                            #
#               -Edit this script to suit your needs                           #
#                                                                              #
# Requirements: awk, cat, echo, grep, tail                                     #
#                                                                              #
# Limitations:  -Can't handle dirnames with spaces in them.                    #
#                                                                              #
################################################################################

case $PWD/$1 in
    #Dont look for dupes here, ie allow CD1-, CD2-, sampledirs and so on
    /site/mp3/????/*/* ) exit ;;

    /site/mp3/????/*   ) TMP=`cat /ftp-data/logs/dupelog | grep -i "$1" | \
                         tail -n1`
                         if [ `echo $TMP | awk '{print $1}'` ]; then
                             echo -e "`echo $TMP | awk '{print $2}'` was last \
                             uploaded at `echo $TMP | awk '{print $1}'`"
                             exit 2
                         fi
                         exit ;;
esac
exit