my $gpath = $ENV{GPT_LOCATION};

if (!defined($gpath))
{
    $gpath = $ENV{GLOBUS_LOCATION};
}

if (!defined($gpath))
{
    die "GPT_LOCATION or GLOBUS_LOCATION needs to be set before running this script";
}

@INC = (@INC, "$gpath/lib/perl");

require Grid::GPT::Setup;
use Getopt::Long;

my $help		= 0;

GetOptions('help|h' => \$help);

&usage if $help;

my $metadata =
    new Grid::GPT::Setup(package_name => "globus_scheduler_provider_setup_fork");

my $globusdir	= $ENV{GLOBUS_LOCATION};
my $libexecdir	= "$globusdir/libexec";
my $pgm_file	= "$globusdir/libexec/globus-scheduler-provider-fork";

# create dir for program
# mkdir $libexecdir . "/gram_providers", 0777;

# Do script relocation
print `./find-fork-provider-tools --cache-file=/dev/null`;
if($? != 0)
{
    print STDERR "Error locating PBS commands, aborting!\n";
    exit 2;
}

# Set executable permissions for script
chmod(0755, $pgm_file) || die "Can't set permissions on $pgm_file\n";

$metadata->finish();

sub usage
{
    print "Usage: $0 [options]\n".
          "Options: [--help|-h]\n";
    exit 1;
}
