head	1.3;
access;
symbols
	TIGRIS_1_1_0RC2:1.2.2.1
	TIGRIS_1_1_0RC1:1.2.2.1
	TIGRIS_1_1:1.2.2.1.0.2
	TIGRIS_1_0_8:1.2.2.1
	TIGRIS_1_0_8RC3:1.2.2.1
	TIGRIS_1_0_8RC2:1.2.2.1
	TIGRIS_1_0_8RC1:1.2.2.1
	TIGRIS_1_0_7:1.2.2.1
	TIGRIS_1_0_7RC3:1.2.2.1
	TIGRIS_1_0_7RC2:1.2.2.1
	TIGRIS_1_0_7RC1:1.2.2.1
	TIGRIS_1_0_6:1.2.2.1
	TIGRIS_1_0_6RC5:1.2.2.1
	TIGRIS_1_0_6RC4:1.2.2.1
	TIGRIS_1_0_6RC3:1.2.2.1
	TIGRIS_1_0_6RC2:1.2.2.1
	TIGRIS_1_0_6RC1:1.2.2.1
	TIGRIS_1_0_5:1.2.2.1
	TIGRIS_1_0_5RC6:1.2.2.1
	TIGRIS_1_0_5RC5:1.2.2.1
	TIGRIS_1_0_5RC4:1.2.2.1
	TIGRIS_1_0_5RC3:1.2.2.1
	TIGRIS_1_0_5RC2:1.2.2.1
	TIGRIS_1_0_5RC1:1.2.2.1
	TIGRIS_1_0_4:1.2.2.1
	TIGRIS_1_0_3:1.2.2.1
	TIGRIS_1_0_2:1.2.2.1
	TIGRIS_1_0_1:1.2.2.1
	TIGRIS_1_0:1.2.2.1.0.4
	TIGRIS_1_0_0:1.2.2.1
	TIGRIS_1_0_0_RC1:1.2.0.2;
locks; strict;
comment	@# @;


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

1.2
date	2001.03.26.17.05.09;	author edk;	state Exp;
branches
	1.2.2.1;
next	1.1;

1.1
date	2001.03.26.06.00.58;	author edk;	state Exp;
branches;
next	;

1.2.2.1
date	2001.04.05.22.16.31;	author jrobbins;	state Exp;
branches;
next	;


desc
@@


1.3
log
@eyebrowse lists in the www should be renamed to remove the www -- ie.
admin@@{domain} instead of admin@@www.{domain}.  reset the archives after
this is done (which will clear out any bogus information and recreate
things in a valid state) -- which may or may not require starting the
anzu server.
@
text
@#!/usr/bin/perl

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

main();

sub main
{
    $main::options = getOptions();
    $main::dbh = getDatabaseConnection();

    my $domains = readDomainDirs();

    enableDomains($domains);
    removeOldTypes($domains);
    updateProperties();

    updateWWWEyebrowseLists();
    resetArchives();
}

sub updateWWWEyebrowseLists() {
    my $select = getEyebrowseLists($main::dbh);
    while (my $mlRecord = $select->fetchrow_hashref) {
        my $list     = $mlRecord->{listName};
        warn "updating $list\n";
        my $newList = lc($list);
        $newList =~ s/\@@www\./\@@/;
        my $update = $main::dbh->prepare(
            "UPDATE eb_List SET listName = '$newList' WHERE listName = '$list'"
        );
        my $ret = $update->execute();
        warn "failed to update"  if not $ret;
    }
}

sub resetArchives {
    # is the anzu server running?
    system("svok", "$ENV{SANDBOX}/site/scripts/anzu/anzu-server");
    my $exit_value = $? >> 8;
    if ($exit_value) {
        print "starting anzu server to reset the archive; will stop it after\n";
        system("$ENV{SANDBOX}/site/scripts/anzu/start_anzu");
        sleep(2);
    }
    system("$ENV{SANDBOX}/helm/scripts/anzu_admin","--op=reset_archive");
    if ($exit_value) {
        print "stopping anzu server now\n";
        system("$ENV{SANDBOX}/site/scripts/anzu/stop_anzu");
    }
}

sub readDomainDirs
{
    opendir(DIR, "$ENV{SANDBOX}/data/anzu/domains");
    my @@domain_dirs =
        map ("$ENV{SANDBOX}/data/anzu/domains/$_",
            grep (!/^\./, readdir(DIR)));
    closedir(DIR);
    return \@@domain_dirs;
}

sub removeOldTypes
{
    my ($domain_dirs) = @@_;
    foreach my $domain_dir (@@$domain_dirs) {
        opendir(DIR, "$domain_dir/list_types");
        my @@list_types = grep (!/^\./, readdir(DIR));
        closedir(DIR);
        foreach my $list_type (@@list_types) {
            if ($list_type =~ m/-private$/) {
                my $list_type_file = "$domain_dir/list_types/$list_type";
                print "deleting $list_type_file\n" if $main::options->{debug};
                unlink $list_type_file;
            }
        }
    }
}

sub updateProperties
{
    # for this, we're just going to copy stuff from the anzu source
    # dir.  that's not ideal, but the properties should be in conf/, not in
    # data/ ... hopefully that'll be fixed soon.
    if (! -d "$ENV{SANDBOX}/anzu") {
        die ("missing anzu source directory in the sandbox\n");
    }
    if (! -f "$ENV{SANDBOX}/anzu/conf/anzu.properties") {
        die ("anzu.properties missing from anzu source directory");
    }
    print "overwriting anzu.properties\n" if $main::options->{debug};
    system("cp -f $ENV{SANDBOX}/anzu/conf/anzu.properties* $ENV{SANDBOX}/data/anzu/properties");
}

sub enableDomains
{
    my ($domain_dirs) = @@_;
    foreach my $domain_dir (@@$domain_dirs) {
        touchFile("$domain_dir/enabled");
        enableProjects($domain_dir);
    }
}

sub enableProjects
{
    my ($domain_dir) = @@_;
    opendir(DIR, "$domain_dir/projects");
    my @@project_dirs = map "$domain_dir/projects/$_", grep !/\./, readdir(DIR);
    closedir(DIR);
    foreach my $project_dir (@@project_dirs) {
        touchFile("$project_dir/enabled");
    }
}

sub touchFile
{
    my ($file) = @@_;
    print "touching $file\n" if $main::options->{debug};
    open OUT, ">$file" or die "unable to touch file '$file'";
    close(OUT);
}

sub getEyebrowseLists
{
    my ($dbh) = @@_;
    my $select = $dbh->prepare(
        "SELECT listName from eb_List where listName like '%\@@www.%'"
    );
    my $ret = $select->execute();
    warn "error selecting mailing lists" if not $ret;
    return $select;
}

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,
                "debug",
                "help")
            or $options{help}) {
        showUsage();
    }

    return \%options;
}

sub showUsage
{
    my ($message) = @@_;
    print <<EOM;
Usage: update_anzu [--debug] [--help]
        help            show this message
        debug           include debugging output

This script is designed to adopt a 0.9.2 style anzu data directory
to 1.0.0 anzu.  You must have sourced env.sh before you can use it.

EOM

    print "\n\tERROR MESSAGE\n\t$message\n" if ($message);

    exit;
}

@


1.2
log
@bug fixes & so on : this is now lightly tested
@
text
@d5 2
d13 1
d20 34
d124 25
@


1.2.2.1
log
@buddying edks change from HEAD to branch
@
text
@a4 2
use DBI;  
END { $main::dbh->disconnect if $main::dbh }
a10 1
    $main::dbh = getDatabaseConnection();
a16 34

    updateWWWEyebrowseLists();
    resetArchives();
}

sub updateWWWEyebrowseLists() {
    my $select = getEyebrowseLists($main::dbh);
    while (my $mlRecord = $select->fetchrow_hashref) {
        my $list     = $mlRecord->{listName};
        warn "updating $list\n";
        my $newList = lc($list);
        $newList =~ s/\@@www\./\@@/;
        my $update = $main::dbh->prepare(
            "UPDATE eb_List SET listName = '$newList' WHERE listName = '$list'"
        );
        my $ret = $update->execute();
        warn "failed to update"  if not $ret;
    }
}

sub resetArchives {
    # is the anzu server running?
    system("svok", "$ENV{SANDBOX}/site/scripts/anzu/anzu-server");
    my $exit_value = $? >> 8;
    if ($exit_value) {
        print "starting anzu server to reset the archive; will stop it after\n";
        system("$ENV{SANDBOX}/site/scripts/anzu/start_anzu");
        sleep(2);
    }
    system("$ENV{SANDBOX}/helm/scripts/anzu_admin","--op=reset_archive");
    if ($exit_value) {
        print "stopping anzu server now\n";
        system("$ENV{SANDBOX}/site/scripts/anzu/stop_anzu");
    }
a86 25
}

sub getEyebrowseLists
{
    my ($dbh) = @@_;
    my $select = $dbh->prepare(
        "SELECT listName from eb_List where listName like '%\@@www.%'"
    );
    my $ret = $select->execute();
    warn "error selecting mailing lists" if not $ret;
    return $select;
}

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;
@


1.1
log
@a script to make transformations to the anzu data directory after
upgrading.
@
text
@d3 3
d10 2
d13 1
a13 2
    exit;
    $main::options = getOptions();
d32 1
a32 1
    foreach my $domain_dir (@@domain_dirs) {
d39 1
a39 1
                print "deleting $list_type_file" if $main::options->{debug};
d57 1
d63 1
a63 1
    my ($domains_dirs) = @@_;
d74 1
a74 1
    my @@project_dirs = map "$domain_dir/$_", grep !/\./, readdir(DIR);
d84 1
a84 1
    print "touching $file" if $main::options->{debug};
@

