#!/usr/bin/perl

use strict;
use warnings;

our $VERSION = 3.1;

=head1 NAME

psCreateTopologyDB

=head1 DESCRIPTION

Initializes a Topology Database. Currently, it does so by creating the
DB_CONFIG file for Oracle XML databases.

=cut

use Getopt::Long;

=head2 usage

Prints out a help message.

=cut

sub usage {
    print "$0: Initialize a Topology Service database\n";
    print "  --directory: The directory to hold the database\n";
    return;
}

my $db_config = <<EOC
set_lock_timeout 5000
set_txn_timeout 5000
set_lk_max_lockers 500000
set_lk_max_locks 500000
set_lk_max_objects 500000
set_lk_detect DB_LOCK_MINLOCKS
set_cachesize 0 67108864 0
set_flags DB_LOG_AUTOREMOVE
set_lg_regionmax 2097152
EOC
    ;

my $DB_DIRECTORY;
my $HELP;
my $status = GetOptions(
    'directory|d=s' => \$DB_DIRECTORY,
    'help|h'        => \$HELP,
);

if ( not $status or $HELP ) {
    usage();
    exit( 0 );
}

unless ( $DB_DIRECTORY ) {
    print "Error: No database directory specified\n";
    usage();
    exit( -1 );
}

unless ( -d $DB_DIRECTORY ) {
    my $n = system( "mkdir -p $DB_DIRECTORY" );
    if ( $n != 0 ) {
        print "Error: could not create directory $DB_DIRECTORY\n";
        exit( -2 );
    }
}

open( DB_CONFIG, ">", $DB_DIRECTORY . "/DB_CONFIG" );
print DB_CONFIG $db_config;
close( DB_CONFIG );

__END__

=head1 SEE ALSO

L<Getopt::Long>

To join the 'perfSONAR Users' mailing list, please visit:

  https://mail.internet2.edu/wws/info/perfsonar-user

The perfSONAR-PS subversion repository is located at:

  http://anonsvn.internet2.edu/svn/perfSONAR-PS/trunk

Questions and comments can be directed to the author, or the mailing list.
Bugs, feature requests, and improvements can be directed here:

  http://code.google.com/p/perfsonar-ps/issues/list

=head1 VERSION

$Id$

=head1 AUTHOR

Aaron Brown, aaron@internet2.edu
Jason Zurawski, zurawski@internet2.edu

=head1 LICENSE

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

=head1 COPYRIGHT

Copyright (c) 2004-2009, University of Delaware and Internet2

All rights reserved.

=cut
