#!/usr/bin/perl
# cpanel - cp_util/make_targzd_list.pl            Copyright(c) 2012 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
#
###############################################################################
#
# This script simply finds directories in the targz directory that
# we need to create tarballs from.  Used in conjunction with another
# script that performs the actual duties of tarball creation.
#
# Usage:
#   --help          Print out a usage message
#

use strict;
use warnings;

use File::Find   ();
use Getopt::Long ();

my $opt_help;
my $result = Getopt::Long::GetOptions(
    'help' => \$opt_help,
);

if ($opt_help) {
    print_usage();
    exit;
}

if ( !-d '.git' or !-d 'targz' ) {
    print "This script must be run from the root directory of an EasyApache git repo.\n";
    exit 1;
}

# Find all the unpacked source directories
my @pmd;
my $find_sub = sub {
    if ( $_ =~ /\.d$/ && -d $_ ) {
        my $path = $File::Find::name;
        push @pmd, $path;
        $File::Find::prune = 1;
    }
};
File::Find::find( $find_sub, 'targz' );

@pmd = sort @pmd;

local $, = "\n";
print @pmd;
print "\n";
exit 0;

sub print_usage {
    print <<"USAGE";

Displays a list of application directories that need tarballs
$0 [ --help ]
    --help          Print out a usage message

USAGE
}
