#!/usr/bin/perl

# requires tar (haha)
# looks for a tar archive that has a directory entry that ends in
# openbox-3/ or gtk-2.0/

# make sure we got a file arg
exit 1 if scalar(@ARGV) != 1;

# get a file listing from tar
@list = `tar -tf $ARGV[0]`;

# see if we have an openbox-3 theme or a gtk-2.0 theme
$oblist = grep /\/openbox-3\/$/, @list;
$gtklist = grep /\/gtk-2.0\/$/, @list;

# if we got a hit, extract it and exit
if ($oblist > 0 || $gtklist > 0)
{
    # figure out the extraction option (bz2 versus gz)
    $exopt = "j" if $ARGV[0] =~ /\.bz2$/;
    $exopt = "z" if $exopt ne "j";

    # extract, move the archive, and exit
    `tar xf$exopt $ARGV[0] -C ~/.themes/`;
    `mv $ARGV[0] ~/downloads/`;
    exit 0;
}

# made it here means its not a theme archive
exit 1;
