#! /tools/bin/perl

use Procmon;
require '/usr/www/push/php/scripts/auth.pl';

my $source_dir="/usr/www/push/static_files/";
my $image_dir_list="/usr/www/push/php/scripts/logs/dirlist_images";
my $pm = new Procmon;
$pm->group( 'Images' );
$pm->description( 'Copies images from CVS to racecar' );
##################################################
my $cp="/bin/cp";

die "Destination dir unavailable" unless -d '/racecar/images/epi_images';

&make_dir;

open(FILE,$image_dir_list);
my @dirs=<FILE>;
close(FILE);
chomp(@dirs);

foreach $dir (@dirs) {
	my $source=$source_dir.$dir;
	my $dest_dir=$dir;
	$dest_dir =~ s|images|/racecar/images/epi_images|;
	my $cmd="mkdir -p $dest_dir";
	print "$cmd\n";
	if ( system($cmd) ) {
		print "$cmd had an error\n";
	}

	#$cmd="cd $source; $cp * $dest_dir ";
	#print "$cmd\n";
	#if ( system($cmd) ) {
	#	print "$cmd had an error\n";
	#}

        opendir SOURCE, "$source" or die "can't open $source: $!";
        my @files = grep !/^\.\.?$/, readdir SOURCE;
        foreach my $file (@files) {
		if (-f "$file") {
			$cmd = "$cp $file $dest_dir";
			if (system($cmd)) {
				print "$cmd had an error\n";
			}
		}
	}
	closedir SOURCE;
} # End of foreach

$pm->mail_report;
