head	1.8;
access;
symbols
	TIGRIS_1_1_0RC2:1.6.6.1
	TIGRIS_1_1_0RC1:1.6.6.1
	TIGRIS_1_1:1.6.6.1.0.2
	TIGRIS_1_0_8:1.6.6.1
	TIGRIS_1_0_8RC3:1.6.6.1
	TIGRIS_1_0_8RC2:1.6.6.1
	TIGRIS_1_0_8RC1:1.6.6.1
	TIGRIS_1_0_7:1.6.6.1
	TIGRIS_1_0_7RC3:1.6.6.1
	TIGRIS_1_0_7RC2:1.6.6.1
	TIGRIS_1_0_7RC1:1.6.6.1
	TIGRIS_1_0_6:1.6.6.1
	TIGRIS_1_0_6RC5:1.6.6.1
	TIGRIS_1_0_6RC4:1.6.6.1
	TIGRIS_1_0_6RC3:1.6.6.1
	TIGRIS_1_0_6RC2:1.6.6.1
	TIGRIS_1_0_6RC1:1.6.6.1
	TIGRIS_1_0_5:1.6.6.1
	TIGRIS_1_0_5RC6:1.6.6.1
	TIGRIS_1_0_5RC5:1.6.6.1
	TIGRIS_1_0_5RC4:1.6.6.1
	TIGRIS_1_0_5RC3:1.6.6.1
	TIGRIS_1_0_5RC2:1.6.6.1
	TIGRIS_1_0_5RC1:1.6.6.1
	TIGRIS_1_0_4:1.6
	TIGRIS_1_0_3:1.6
	TIGRIS_1_0_2:1.6
	TIGRIS_1_0_1:1.6
	TIGRIS_1_0:1.6.0.6
	TIGRIS_1_0_0:1.6
	TIGRIS_1_0_0_RC1:1.6.0.2
	HELM_PEER_PORT_BRANCH:1.1.1.1
	dlr:1.1.1;
locks; strict;
comment	@# @;


1.8
date	2001.06.19.06.21.36;	author edk;	state dead;
branches;
next	1.7;

1.7
date	2001.05.14.12.35.43;	author edk;	state Exp;
branches;
next	1.6;

1.6
date	2001.03.02.21.41.20;	author edk;	state Exp;
branches
	1.6.6.1;
next	1.5;

1.5
date	2001.03.02.13.08.13;	author edk;	state Exp;
branches;
next	1.4;

1.4
date	2001.03.02.12.57.51;	author edk;	state Exp;
branches;
next	1.3;

1.3
date	2001.02.22.16.53.43;	author edk;	state Exp;
branches;
next	1.2;

1.2
date	2001.02.22.04.48.45;	author edk;	state Exp;
branches;
next	1.1;

1.1
date	2001.02.21.00.36.25;	author dlr;	state Exp;
branches
	1.1.1.1;
next	;

1.1.1.1
date	2001.02.21.00.36.25;	author dlr;	state Exp;
branches;
next	;

1.6.6.1
date	2001.05.14.13.13.06;	author edk;	state Exp;
branches;
next	;


desc
@@


1.8
log
@this script has been obsoleted by anzu_admin
@
text
@#!/usr/bin/perl

use Getopt::Long;

main();

sub main {
    setupEnvironment();
    my $options = getOptions();
    $main::dbh = getDatabaseConnection();
    my ($select, $ret);

    # currently, $anzu_command_info is a command, and eyebrowse_command_info
    # is a list of arrays, one for each mailing list to be created.
    my ($anzu_command_info, $eyebrowse_command_info) =
        constructCommandInfo($dbh);

    # we always handle eybrowse items for now, since anzu needs to learn
    # how to delete all the stuff in a domain
    my $result = handleEyebrowseItems($options, $eyebrowse_command_info);
    if ($options->{type} eq 'anzu') {
        $result = handleAnzuItems($options, $anzu_command_info);
    }
    exit $result;
}

#################################
### handle any required actions
#################################

sub handleAnzuItems {
    my ($options, $anzu_command) = @@_;
    sleep 2;
    print STDERR "running anzu Harness; if this hangs, please kill it,\n";
    print STDERR "restart your sandbox, and try again.\n";

    system(@@$anzu_command);
    my $exit_value  = $? >> 8;
    return $exit_value;
}

sub handleEyebrowseItems {
    my ($options, $eyebrowse_lists) = @@_;

#   this is now (effectively) done in anzu:
#    system("rm -fr $eyebrowse_dir");
    mkdir $eyebrowse_dir, 0755;

    my ($existing_lists) = getEyebrowseLists();

    foreach $item (@@$eyebrowse_lists) {
        my ($list_address, $listID, $desc, $list_file_dir) = @@$item;
        my $list_file = "$list_file_dir/0mbox";
        my @@eyebrowse_command_base = getEyebrowseCommandBase();
        if (grep /^$list_address$/, @@$existing_lists) {
            print STDERR "removing $list_address since it was set up\n";
            system(@@eyebrowse_command_base, '--command','deletelist',
                    '--listname', $list_address);
        }

        # the following stuff is now done in anzu; so we shouldn't need to
        # do it here if we're doing anzu stuff:
        next if ($options->{type} eq 'anzu');

        print STDERR "adding list $list_address to eyebrowse database\n";
        system(@@eyebrowse_command_base, '--command', 'addlist', '--listname',
                $list_address, '--descr', $desc, '--listid', $listID);
        print STDERR "adding list file to eyebrowse database\n";
    
        system('mkdir', '-p', $list_file_dir);
        system('touch', $list_file);
        system(@@eyebrowse_command_base, '--command', 'addlistfile',
                '--listname', $list_address, '--listfile', $list_file);

	print STDERR "adding search-index $list_file_dir/index\n";
	mkdir ("$list_file_dir/index", 0755);
        system(@@eyebrowse_command_base, '--command', 'addindex', '--listname',
		+$list_address, '--indexdir', "$list_file_dir/index");
    }
    my $eyebrowse_dir ="$ENV{SANDBOX}/data/eyebrowse";
    mkdir($eyebrowse_dir, 0755);
    if ($> == 0) {
        print STDERR "Setting ownership of the eyebrowse data directory\n";
        system("chown","-R", "tigrisq.tigris", $eyebrowse_dir);
    }
    return 0;
}

#################################
### process information according to business logic
#################################

sub constructCommandInfo {
    my ($dbh) = @@_;
   
    my @@anzu_command = (
            "$ENV{SANDBOX}/site/scripts/anzu/harness"
    );
    my @@domains = ();
    $select = getDomains($main::dbh);
    while (my $domainRecord = $select->fetchrow_hashref) {
        my $domain = $domainRecord->{DOMAIN};
        next if ($domain =~ m/\*/);
        # if there's stuff there, clean it out
        push(@@anzu_command, 'delete_domain', $domain, "\n");
        push(@@anzu_command, 'add_domain', $domain, "\n");
        push @@domains, $domain;
    }

    $select = getProjects($main::dbh);
    while (my $projectRecord = $select->fetchrow_hashref) {
        my $project = $projectRecord->{project};
        my $domain  = $projectRecord->{DOMAIN};
        next if ($project=~ m/\*/);
        push(@@anzu_command, 'add_project', $domain, $project, "\n");
        my $projectID = $projectRecord->{projectID};
        my $subselect = getProjectOwners($main::dbh, $projectID);
        my $ownerAddress = '';
        while (my $ownerRecord = $subselect->fetchrow_hashref) {
            my $ownerLoginID = $ownerRecord->{LOGIN_NAME};
            $ownerAddress .= "\n" if $ownerAddress;
            $ownerAddress .= "$ownerLoginID\@@$domain";
        }
        push(@@anzu_command, 'alias', $domain, $project, 'create',
                'owner', $ownerAddress, "\n");
    }

    $select = getUsers($main::dbh);
    while(my $userRecord = $select->fetchrow_hashref) {
        my $user = $userRecord->{LOGIN_NAME};
        my $email = $userRecord->{EMAIL};
        my $domain = $userRecord->{DOMAIN};
        next if ($user =~m/\*/); # TODO : better weeding ?
        if ($domain =~ m/\*/) {  # TODO : better handling of wildcards ?
            foreach my $domain (@@domains) {
                push (@@anzu_command, 'alias', $domain, 'www', 'create', $user,
                        $email, "\n");
            }
            next;
        }
        push(@@anzu_command,'alias',$domain,'www','create',$user,$email,"\n");
    }

    $select = getMailingLists($main::dbh);
    while (my $mlRecord = $select->fetchrow_hashref) {
        my $listName = $mlRecord->{LIST_NAME};
        my $type     = $mlRecord->{TYPE};
        my $domain   = $mlRecord->{DOMAIN_NAME};
        my $project  = $mlRecord->{PROJECT_NAME};
        my $listID   = $mlRecord->{MAILINGLIST_ID};
        my $desc     = $mlRecord->{DESCRIPTION};
        push(@@anzu_command,'ml',$domain,$project,'create',$listName,$type,"\n");
        if ("$ENV{MAIL_PREFIX}" ne '') {
            push (@@anzu_command,'ml',$domain,$project,'update_string',
                    $listName, 'mail_prefix', "$ENV{MAIL_PREFIX}","\n");
        }
        my $archiver_address = "$ENV{MAIL_PREFIX}archive=mail-$project=".
            "$listName=$domain\@@$ENV{MAIL_ARCHIVE_HOST}";
        my $list_address     = "$ENV{MAIL_PREFIX}$listName\@@$project.$domain";
        my $list_file_dir    =
            "$ENV{SANDBOX}/data/eyebrowse/$domain/$project/$listName";

        push(@@anzu_command, 'ml', $domain, $project, 'subscribe', $listName, '',
                $archiver_address, "\n");
        push @@eyebrowse_lists, [$list_address,$listID,$desc,$list_file_dir];
    }
    return (\@@anzu_command, \@@eyebrowse_lists);
}

#################################
###  preparation (getting information, db connections, etc.)
#################################
sub getDomains {
    my ($dbh) = @@_;
    my $select  = $dbh->prepare(
            "SELECT HELM_DOMAIN.NAME as DOMAIN ".
            "FROM HELM_DOMAIN");
    my $ret  = $select->execute();
    warn "error selecting domains" if not $ret;
    return $select;
}

sub getProjects {
    my ($dbh) = @@_;
    my $select  = $dbh->prepare(
            "SELECT HELM_PROJECT.NAME as project, HELM_DOMAIN.NAME as DOMAIN, ".
                "HELM_PROJECT.PROJECT_ID as projectID ".
            "FROM HELM_PROJECT, HELM_DOMAIN ".
            "WHERE HELM_PROJECT.DOMAIN_ID = HELM_DOMAIN.DOMAIN_ID AND " .
                "HELM_PROJECT.TYPE!='host' AND HELM_PROJECT.TYPE != 'domain'");
    my $ret  = $select->execute();
    warn "error selecting projects" if not $ret;
    return $select;
}

sub getProjectOwners {
    my ($dbh, $projectID) = @@_;
    my $select = $dbh->prepare(
            "SELECT u.LOGIN_NAME ".
            "FROM HELM_USER u, HELM_USER_ROLE_PROJECT urp, HELM_ROLE r ".
            "WHERE u.USER_ID = urp.USER_ID and urp.PROJECT_ID = $projectID and ".
                "urp.ROLE_ID = r.ROLE_ID and r.NAME=\"Project Owner\"");
    my $ret    = $select->execute();
    warn "error selecting project owners" if not $ret;
    return $select;
}

sub getUsers {
    my ($dbh) = @@_;
    my $select = $dbh->prepare(
            "SELECT LOGIN_NAME, EMAIL, HELM_DOMAIN.NAME as DOMAIN ".
            "FROM HELM_USER, HELM_DOMAIN ".
            "WHERE HELM_USER.DOMAIN_ID = HELM_DOMAIN.DOMAIN_ID");
    my $ret = $select->execute();
    warn "error selecting users" if not $ret;
    return $select;
}

sub getMailingLists {
    my ($dbh) = @@_;
    my $select = $dbh->prepare(
        "SELECT LIST_NAME, ml.TYPE, Project.NAME as PROJECT_NAME, " .
            "Domain.NAME as DOMAIN_NAME, MAILINGLIST_ID, ml.DESCRIPTION ".
        "FROM HELM_MAILINGLIST ml, HELM_PROJECT Project, HELM_DOMAIN Domain ".
        "WHERE ml.PROJECT_ID = Project.PROJECT_ID AND ".
            "Project.DOMAIN_ID = Domain.DOMAIN_ID");
    my $ret = $select->execute();
    warn "error selecting mailing lists" if not $ret;
    return $select;
}

use DBI;  
END { $main::dbh->disconnect if $main::dbh }

sub getDatabaseConnection {
    my $db_base = 'mysql';
    my $db_name = "$ENV{DATABASE_NAME}";
    my $db_host = "$ENV{DATABASE_HOST}";
    my $db_port = "$ENV{DATABASE_PORT}";
    my $db_user = "$ENV{DATABASE_USER}";
    my $db_pass = "$ENV{DATABASE_PASSWORD}";
    my $connectstring = "dbi:$db_base:$db_name:host=$db_host:port=$db_port";
    my $dbh = DBI->connect($connectstring, $db_user, $db_pass)
        or die "Can't connect to the table '$connectstring'.\n";
    return $dbh;
}

sub getOptions {
    my %options;
    if (!GetOptions(\%options, "type=s", "clean", "help") 
            or $options{help}) {
        showUsage();
    }
    $options{type}    || ($options{type}    = "anzu");
    die "invalid type $options{type}\n" 
        if ($options{type} ne "anzu" and $options{type} ne "eyebrowse");

    return \%options;
}

sub showUsage {
    my ($message) = @@_;
    print <<EOM;
Usage: anzu_initialize [--type={type}] [--clean]
        type       Either 'eyebrowse' or 'anzu'
        clean      A flag which indicates the data should not be deleted
EOM
    exit;
}

sub setupEnvironment {
    my $anzu_jar = "$ENV{SANDBOX}/site/lib/anzu.jar";
    $ENV{CLASSPATH} = "$ENV{CLASSPATH}:$anzu_jar";
}

sub getEyebrowseLists {
    my @@eyebrowse_command_base = getEyebrowseCommandBase();
    open (IN, "-|") or exec @@eyebrowse_command_base, '--command','getlists';
    while (<IN>) {
        chomp;
        push @@existing_lists, $_;
    }
    close(IN);
    return \@@existing_lists;
}
    
sub getEyebrowseCommandBase {
    return  ("$ENV{SANDBOX}/site/scripts/eyebrowse/eyebrowse");
}

@


1.7
log
@update for the new harness api
this should probably be folded in to anzu_admin
@
text
@@


1.6
log
@create eyebrowse data directory
@
text
@d105 2
a106 2
        push(@@anzu_command, 'delete_domain', $domain);
        push(@@anzu_command, 'add_domain', $domain);
d115 1
a115 1
        push(@@anzu_command, 'add_project', $domain, $project);
d125 1
a125 1
                'owner', $ownerAddress);
d137 1
a137 1
                        $email);
d141 1
a141 1
        push(@@anzu_command, 'alias', $domain, 'www', 'create', $user, $email);
d152 1
a152 1
        push(@@anzu_command, 'ml',$domain,$project,'create',$listName,$type);
d154 2
a155 2
            push (@@anzu_command, 'ml', $domain, $project, 'update_string',
                    $listName, 'mail_prefix', "$ENV{MAIL_PREFIX}");
d164 1
a164 1
                $archiver_address, '');
@


1.6.6.1
log
@porting back changes to fix several problems:
* long command line (for sites with lots of users & etc)
* update works without blowing away data managed via the helm UI
Submitted by:	Ed Korthof <edk@@collab.net>
Reviewed by:	Manoj Kasichainula <manoj@@collab.net> (lightly reviewed)
@
text
@d105 2
a106 2
        push(@@anzu_command, 'delete_domain', $domain, "\n");
        push(@@anzu_command, 'add_domain', $domain, "\n");
d115 1
a115 1
        push(@@anzu_command, 'add_project', $domain, $project, "\n");
d125 1
a125 1
                'owner', $ownerAddress, "\n");
d137 1
a137 1
                        $email, "\n");
d141 1
a141 1
        push(@@anzu_command,'alias',$domain,'www','create',$user,$email,"\n");
d152 1
a152 1
        push(@@anzu_command,'ml',$domain,$project,'create',$listName,$type,"\n");
d154 2
a155 2
            push (@@anzu_command,'ml',$domain,$project,'update_string',
                    $listName, 'mail_prefix', "$ENV{MAIL_PREFIX}","\n");
d164 1
a164 1
                $archiver_address, "\n");
@


1.5
log
@return meaningful result code if it's available.
@
text
@d81 1
@


1.4
log
@hopefully soon anzu's code for deleting projects and domains will take
care of deleting eyebrowse db entries as well.  until then, they
need to be deleted by anzu_initialize explicitly ... but since
anzu handles telling eb about new lists, that code doesn't need to run
if anzu is being initialized.
@
text
@d20 1
a20 1
    handleEyebrowseItems($options, $eyebrowse_command_info);
d22 1
a22 1
        handleAnzuItems($options, $anzu_command_info);
d24 1
d38 2
d85 1
@


1.3
log
@switch to using the harness script to wrap calls to the anzu Harness
class, since that script is still generated from a .in file, so it has
access to RMI_PORT (one of the generated tokens which is not generally
in the environment).
@
text
@d18 4
a21 4
    if ($options->{type} eq 'all' or $options->{type} eq 'eyebrowse') {
        handleEyebrowseItems($options, $eyebrowse_command_info);
    }
    if ($options->{type} eq 'all' or $options->{type} eq 'anzu') {
d57 5
d249 1
a249 1
    $options{type}    || ($options{type}    = "all");
d251 1
a251 2
        if ($options{type} ne "anzu" and $options{type} ne "eyebrowse"
                and $options{type} ne "all");
d260 1
a260 1
        type       One of 'all', 'eyebrowse', 'anzu'
@


1.2
log
@switch from using a generated file to using the environment
@
text
@a84 1
    my $java = findJava();
d87 1
a87 5
            $java,
            "-Dorg.tigris.anzu.secret=$ENV{SANDBOX}/data/anzu/secret",
            "-Dorg.tigris.anzu.RMIURL=rmi://localhost:$ENV{RMI_PORT}/".
                "org.tigris.anzu.mail",
            "org.tigris.anzu.client.Harness"
a162 20
sub findJava {
    if (-d "/usr/java/jdk1.3" && -x "/usr/java/jdk1.3/bin/java") {
        $ENV{JAVA_HOME}='/usr/java/jdk1.3';
        return '/usr/java/jdk1.3/bin/java';
    }
    my $java = `which java 2> /dev/null`;
    if ( ! -x "$java" ) {
        if ($ENV{JAVA_HOME}) {
           $java = "$ENV{JAVA_HOME}/bin/java";
        }
    }

    if ( ! -x $java )  {
        print STDERR "Please add the bin dir from your JDK to your path or ",
                "set JAVA_HOME\n";
        exit 1;
    }
    return $java;
}

@


1.1
log
@Initial revision
@
text
@d66 5
d72 1
a72 1
    my $eyebrowse_dir ="/home/dlr/sandbox/data/eyebrowse";
d89 2
a90 2
            "-Dorg.tigris.anzu.secret=/home/dlr/sandbox/data/anzu/secret",
            "-Dorg.tigris.anzu.RMIURL=rmi://localhost:15025/".
d148 1
a148 1
        if ('' ne '') {
d150 1
a150 1
                    $listName, 'mail_prefix', '');
d152 3
a154 3
        my $archiver_address = "archive=mail-$project=".
            "$listName=$domain\@@sc-dev2.sp.collab.net";
        my $list_address     = "$listName\@@$project.$domain";
d156 1
a156 1
            "/home/dlr/sandbox/data/eyebrowse/$domain/$project/$listName";
d252 5
a256 5
    my $db_name = 'tigris_1025';
    my $db_host = 'localhost';
    my $db_port = '3306';
    my $db_user = 'tigris';
    my $db_pass = 'euphrates';
d288 1
a288 1
    my $anzu_jar = "/home/dlr/sandbox/site/lib/anzu.jar";
d304 1
a304 1
    return  ('/home/dlr/sandbox/site/scripts/eyebrowse/eyebrowse');
@


1.1.1.1
log
@Replacing the HEAD with the HELM_PEER_PORT_BRANCH.
@
text
@@
