#!/usr/bin/perl

my $THEMES =	"/WWW/web/DavePics.com/Themes";
my $ALBUM =	"/WWW/web/DavePics.com/Examples";
my $TOP =	"http://MarginalHacks.com/Hacks/album/Themes.html";
my $NICE =	"/usr/bin/nice -20";

my $cnt;
foreach my $t ( @ARGV ) {
  $t =~ s|/+$||;
  next unless (-d $t && -f "$t/album.th");
  die("Run this from the theme directory\n") if $t =~ m|/|;

  unless ($cnt) {
    print "#!/bin/sh\n\n";
    print "$NICE album -known_images -top $TOP $ALBUM\n";
  }
  print "sleep 1m\n" if ($cnt++ % 2);

  print "$NICE album -known_images -theme $THEMES/$t -index $t -captions Captions -top $TOP $ALBUM\n";

# Just get rid of the old files
unlink "${t}.tar.gz";
unlink "${t}.zip";

  system("tar czf ${t}.tar.gz $t") unless -e "${t}.tar.gz";
  if (!-e "${t}.zip" && open(ZIP,"|zip -z ${t}.zip `find $t` > /dev/null")) {
    print ZIP "---------------------------------------------\n";
    print ZIP "| Zipped Album Theme:                       |\n";
    printf ZIP "|   %-40s|\n",$t;
    print ZIP "|                                           |\n";
    print ZIP "| Album:                                    |\n";
    print ZIP "|   http://MarginalHacks.com/Hacks/Album    |\n";
    print ZIP "|                                           |\n";
    print ZIP "|        http://MarginalHacks.com           |\n";
    print ZIP "---------------------------------------------\n";
    print ZIP ".\n";
    close ZIP;
  }
}
system("go+rx");
