#!/bin/bash

if test $# -ne 3; then
        echo "usage : $0 prefix start_dir end_dir"
        echo "example $0 li 000/000 099/999"
        exit 1
fi

BASEDIR=/home/script
prefix=$1
start_dir=$2
end_dir=$3
NASTOP=/var/www/html/ghtml

#LOGFILE=$BASEDIR/$prefix\_sync.log

SDIR1=`echo $start_dir | cut -d '/' -f 1`
SDIR2=`echo $start_dir | cut -d '/' -f 2`

EDIR1=`echo $end_dir | cut -d '/' -f 1`
EDIR2=`echo $end_dir | cut -d '/' -f 2`

#echo -n "Batch Start :" >> $LOGFILE 
#date +%Y/%m/%d" "%H:%M:%S >> $LOGFILE

cd $NASTOP
if test $? -ne 0;then 
        echo "===> Check NAS mount"
        exit 1
fi

for i in `seq -w ${SDIR1}${SDIR2} ${EDIR1}${EDIR2}`;do
        DIR1=`echo $i | cut -c 1-3`
        DIR2=`echo $i | cut -c 4-6`
        TARGET=$DIR1/$DIR2
 #       echo -n "Staring $TARGET..." >> $LOGFILE 

        #awscmd="aws s3 sync $NASTOP/$TARGET s3://gd.image-qoo10.com/$TARGET --acl public-read --quiet >> $LOGFILE 2>&1"
        #/usr/bin/aws s3 sync $NASTOP/$TARGET s3://gd.image-qoo10.com/$TARGET --acl public-read --quiet >> $LOGFILE 2>&1
	 

	rm -f `/bin/grep agdetail.image $NASTOP/$TARGET/* | cut -d':' -f1`
	
	#echo 'rm -rf '$path2
	 #/bin/grep agdetail.image $NASTOP/$TARGET/* | cut -d':' -f1 >> /home/script/ghtml.log

#       echo $awscmd            ### comment out this line when real sync
#       $awscmd                ### remove # when real sync

        #echo " Done | "`date +%Y/%m/%d" "%H:%M:%S ` >> $LOGFILE
done
