<commit_before>use Getopt::Long;
use IO::File;

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;

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

my $globusdir	= $ENV{GLOBUS_LOCATION};
my $setupdir	= "$globusdir/setup/globus";
my $sysconfdir	= "$globusdir/etc";
my $libexecdir	= "$globusdir/libexec";
my $bindir	= "$globusdir/bin";
my $sbindir	= "$globusdir/sbin";
my $state_dir   = "$globusdir/tmp/gram_job_state";
my $help	= 0;

GetOptions('state-dir|s=s' => \$state_dir,
           'help|h' => \$help);

&usage if($help);

&setup_state_dir();
&setup_job_manager_conf();
&setup_script_shbang("${setupdir}/globus-job-manager-service.in",
                      "${libexecdir}/globus-job-manager-service");
&setup_script_shbang("${setupdir}/globus-job-manager-mds-provider.in",
                      "${libexecdir}/globus-job-manager-mds-provider");
&setup_script_shbang("$setupdir/globus-job-manager-script.in",
                     "$libexecdir/globus-job-manager-script.pl");
print "Done\n";

$metadata->finish();

sub setup_state_dir
{
    my $last_built_path = '';
    my $built_path = '';
    my @components;

    print "Creating state file directory.\n";

    if( $state_dir !~ m|^/|)
    {
	print STDERR "Invalid directory for state files \"$state_dir\"\n";
	exit(1);
    }

    @components = split(/\//, $state_dir);

    foreach(@components)
    {
	next if $_ eq '';

	$last_built_path = $built_path;
	$built_path .= "/$_";

	if(-e $built_path && ! -d $built_path)
	{
	    print STDERR "Invalid path for state files: " .
	                 "$built_path is not a directory\n";
	    exit(1);
	}
	elsif(! -e $built_path)
	{
	    my $fs_type;

	    chomp($fs_type = (split(/\n/, `df $last_built_path`))[-1]);

	    if($fs_type !~ m%(/dev/|swap)%)
	    {
		print STDERR "WARNING: It looks like $built_path may not be on a local filesystem. WARNING: The test for local file systems is not 100% reliable. Ignore the below if this is a false positive.\n WARNING: The jobmanager requires state dir to be on a local filesystem\n WARNING: Rerun the jobmanager setup script with the -state-dir=<state dir> option.";
	    }
	    mkdir($built_path, 0777) ||
                die "Unable to create directory $built_path\n";
	    chmod(0755, $built_path) ||
	        die "Can't set permissions on $built_path\n";
	}
    }
    
    if(((stat($state_dir))[2] & oct(01777)) != oct(01777))
    {
        chmod(01777, $state_dir) || die "Can't set permissions on $state_dir\n";
    }

    print "Done.\n";
}

sub setup_job_manager_conf
{
    my ($gatekeeper_port, $gatekeeper_subject);
    my ($hostname, $cpu, $manufacturer, $os_name, $os_version);
    my $jm_conf	= "${sysconfdir}/globus-job-manager.conf";
    my $conf_file;

    ($gatekeeper_subject, $gatekeeper_port) =
	&get_gatekeeper_info("${sysconfdir}/globus-gatekeeper.conf");

    ($hostname, $cpu, $manufacturer, $os_name, $os_version) = &get_system_info();

    print "Creating job manager configuration file...\n";
    $conf_file = new IO::File(">$jm_conf") || die "open failed for $jm_conf";

    print $conf_file <<EOF;
	-home \"$globusdir\"
	-globus-gatekeeper-host $hostname
	-globus-gatekeeper-port $gatekeeper_port
	-globus-gatekeeper-subject \"$gatekeeper_subject\"
	-globus-host-cputype $cpu
	-globus-host-manufacturer $manufacturer
	-globus-host-osname $os_name
	-globus-host-osversion $os_version
	-save-logfile on_errors
	-state-file-dir $state_dir
	-machine-type unknown
EOF
    $conf_file->close();
}
<commit_msg>fixed typo in generated job manager conf file (-save-logfile argument)<commit_after>use Getopt::Long;
use IO::File;

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;

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

my $globusdir	= $ENV{GLOBUS_LOCATION};
my $setupdir	= "$globusdir/setup/globus";
my $sysconfdir	= "$globusdir/etc";
my $libexecdir	= "$globusdir/libexec";
my $bindir	= "$globusdir/bin";
my $sbindir	= "$globusdir/sbin";
my $state_dir   = "$globusdir/tmp/gram_job_state";
my $help	= 0;

GetOptions('state-dir|s=s' => \$state_dir,
           'help|h' => \$help);

&usage if($help);

&setup_state_dir();
&setup_job_manager_conf();
&setup_script_shbang("${setupdir}/globus-job-manager-service.in",
                      "${libexecdir}/globus-job-manager-service");
&setup_script_shbang("${setupdir}/globus-job-manager-mds-provider.in",
                      "${libexecdir}/globus-job-manager-mds-provider");
&setup_script_shbang("$setupdir/globus-job-manager-script.in",
                     "$libexecdir/globus-job-manager-script.pl");
print "Done\n";

$metadata->finish();

sub setup_state_dir
{
    my $last_built_path = '';
    my $built_path = '';
    my @components;

    print "Creating state file directory.\n";

    if( $state_dir !~ m|^/|)
    {
	print STDERR "Invalid directory for state files \"$state_dir\"\n";
	exit(1);
    }

    @components = split(/\//, $state_dir);

    foreach(@components)
    {
	next if $_ eq '';

	$last_built_path = $built_path;
	$built_path .= "/$_";

	if(-e $built_path && ! -d $built_path)
	{
	    print STDERR "Invalid path for state files: " .
	                 "$built_path is not a directory\n";
	    exit(1);
	}
	elsif(! -e $built_path)
	{
	    my $fs_type;

	    chomp($fs_type = (split(/\n/, `df $last_built_path`))[-1]);

	    if($fs_type !~ m%(/dev/|swap)%)
	    {
		print STDERR "WARNING: It looks like $built_path may not be on a local filesystem. WARNING: The test for local file systems is not 100% reliable. Ignore the below if this is a false positive.\n WARNING: The jobmanager requires state dir to be on a local filesystem\n WARNING: Rerun the jobmanager setup script with the -state-dir=<state dir> option.";
	    }
	    mkdir($built_path, 0777) ||
                die "Unable to create directory $built_path\n";
	    chmod(0755, $built_path) ||
	        die "Can't set permissions on $built_path\n";
	}
    }
    
    if(((stat($state_dir))[2] & oct(01777)) != oct(01777))
    {
        chmod(01777, $state_dir) || die "Can't set permissions on $state_dir\n";
    }

    print "Done.\n";
}

sub setup_job_manager_conf
{
    my ($gatekeeper_port, $gatekeeper_subject);
    my ($hostname, $cpu, $manufacturer, $os_name, $os_version);
    my $jm_conf	= "${sysconfdir}/globus-job-manager.conf";
    my $conf_file;

    ($gatekeeper_subject, $gatekeeper_port) =
	&get_gatekeeper_info("${sysconfdir}/globus-gatekeeper.conf");

    ($hostname, $cpu, $manufacturer, $os_name, $os_version) = &get_system_info();

    print "Creating job manager configuration file...\n";
    $conf_file = new IO::File(">$jm_conf") || die "open failed for $jm_conf";

    print $conf_file <<EOF;
	-home \"$globusdir\"
	-globus-gatekeeper-host $hostname
	-globus-gatekeeper-port $gatekeeper_port
	-globus-gatekeeper-subject \"$gatekeeper_subject\"
	-globus-host-cputype $cpu
	-globus-host-manufacturer $manufacturer
	-globus-host-osname $os_name
	-globus-host-osversion $os_version
	-save-logfile on_error
	-state-file-dir $state_dir
	-machine-type unknown
EOF
    $conf_file->close();
}

{'fraction_non_alphanumeric': 0.160520031838684, 'fraction_numerical': 0.008224993366940834, 'mean_word_length': 3.5580411124546556, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '531102', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2722, 'n_words': 591}