-$| = 1; #unbuffer that output.
-
-require RT::Handle;
-my $Handle = RT::Handle->new($RT::DatabaseType);
-$Handle->BuildDSN;
-my $dbh;
-
-if ( $args{'prompt-for-dba-password'} ) {
- $args{'dba-password'} = get_dba_password();
- chomp( $args{'dba-password'} );
-}
-
-if ( $args{'action'} eq 'init' ) {
- $dbh = DBI->connect( get_system_dsn(), $args{'dba'}, $args{'dba-password'} )
- || die "Failed to connect to " . get_system_dsn() . " as $args{'dba'}: $DBI::errstr";
- print "Now creating a database for RT.\n";
- if ( $RT::DatabaseType ne 'Oracle' || $args{'dba'} ne $RT::DatabaseUser ) {
- create_db();
- } else {
- print "...skipped as ".$args{'dba'} ." is not " . $RT::DatabaseUser . " or we're working with Oracle.\n";
- }
-
- if ( $RT::DatabaseType eq "mysql" ) {
- # Check which version we're running
- my ($version) = $dbh->selectrow_hashref("show variables like 'version'")->{Value} =~ /^(\d\.\d+)/;
- print "*** Warning: RT is unsupported on MySQL versions before 4.0.x\n" if $version < 4;
-
- # MySQL must have InnoDB support
- my $innodb = $dbh->selectrow_hashref("show variables like 'have_innodb'")->{Value};
- if ( $innodb eq "NO" ) {
- die "RT requires that MySQL be compiled with InnoDB table support.\n".
- "See http://dev.mysql.com/doc/mysql/en/InnoDB.html\n";
- } elsif ( $innodb eq "DISABLED" ) {
- die "RT requires that MySQL InnoDB table support be enabled.\n".
- ($version < 4
- ? "Add 'innodb_data_file_path=ibdata1:10M:autoextend' to the [mysqld] section of my.cnf\n"
- : "Remove the 'skip-innodb' line from your my.cnf file, restart MySQL, and try again.\n");
- }
- }
-
- # SQLite can't deal with the disconnect/reconnect
- unless ( $RT::DatabaseType eq 'SQLite' ) {
-
- $dbh->disconnect;
-
- if ( $RT::DatabaseType eq "Oracle" ) {
- $RT::DatabasePassword = $RT::DatabasePassword; #Warning avidance
- $dbh = DBI->connect( $Handle->DSN, ${RT::DatabaseUser}, ${RT::DatabasePassword} ) || die $DBI::errstr;
- } else {
- $dbh = DBI->connect( $Handle->DSN, $args{'dba'}, $args{'dba-password'} ) || die $DBI::errstr;
- }
- }
- print "Now populating database schema.\n";
- insert_schema();
- print "Now inserting database ACLs\n";
- insert_acl() unless $RT::DatabaseType eq 'Oracle';
- print "Now inserting RT core system objects\n";
- insert_initial_data();
- print "Now inserting RT data\n";
- insert_data( $RT::EtcPath . "/initialdata" );
-}
-elsif ( $args{'action'} eq 'drop' ) {
- unless ( $dbh =
- DBI->connect( get_system_dsn(), $args{'dba'}, $args{'dba-password'} ) )
- {
- warn $DBI::errstr;
- warn "Database doesn't appear to exist. Aborting database drop.";
- exit;
- }
- drop_db();
-}
-elsif ( $args{'action'} eq 'insert_initial' ) {
- insert_initial_data();
-}
-elsif ( $args{'action'} eq 'insert' ) {
- insert_data( $args{'datafile'} || ($args{'datadir'}."/content") );
-}
-elsif ( $args{'action'} eq 'acl' ) {
- $dbh = DBI->connect( $Handle->DSN, $args{'dba'}, $args{'dba-password'} )
- || die "Failed to connect to " . get_system_dsn() . " as $args{'dba'}: $DBI::errstr";
- insert_acl($args{'datadir'});
-}
-elsif ( $args{'action'} eq 'schema' ) {
- $dbh = DBI->connect( $Handle->DSN, $args{'dba'}, $args{'dba-password'} )
- || die "Failed to connect to " . get_system_dsn() . " as $args{'dba'}: $DBI::errstr";
- insert_schema($args{'datadir'});
-}
-else {
- print STDERR "$0 called with an invalid --action parameter\n";