head	1.2;
access;
symbols
	HELM_PEER_PORT_BRANCH:1.1.1.1 dlr:1.1.1;
locks; strict;
comment	@# @;


1.2
date	2001.02.22.08.19.54;	author edk;	state dead;
branches;
next	1.1;

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

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


desc
@@


1.2
log
@remove generated files which were added by accident
@
text
@#!/usr/bin/perl

# Turn off buffering
#$| = 1;

# Fix up some commonly-tainted variables
$ENV{'PATH'} = "/bin:/usr/bin";
delete $ENV{'BASH_ENV'};

my $perl_dir = '/home/dlr/sandbox/tigris/helm/perl';
use lib "/home/dlr/sandbox/tigris/helm/perl";
use Helm::Database;

my $virtualdomains = '/var/qmail/control/virtualdomains';
my $rcpthosts      = '/var/qmail/control/rcpthosts';

main();

sub main {
    check_uid();

    my $new_project = read_project();
    my $domain = read_domain();
    die "no project" unless $new_project ne "";
    die "no domain" unless $domain;

    check_qmail_control_files($new_project, $domain);
    warn_user($new_project, $domain);

    add_qmail_control_files($new_project, $domain);
    restart_qmail();
    
    update_mailing_lists($new_project, $domain);
}

sub check_uid {
    if ($> > 0) { # i'm not root
        die "you must be root to run this script\n";
    }
}

sub update_mailing_lists {
    my ($new_project, $domain) = @@_;
    print "updating some mailing lists to more reasonable defaults.\n";

    my $db = new Helm::Database;
    my $dbh = $db->dbh();

#    my $sql = "UPDATE project_mlists SET owner='jesse.glick\@@netbeans.com' ".
#        "WHERE project='$new_project'";
#    print "running: $sql\n";
#    my $sth = $dbh->prepare($sql);
#    $sth->execute();
   
    $sql = "UPDATE project_mlists SET digest='Y', prefix='Y', ".
       "guard_archive='Y', new_text_file='N', request_address='Y', ".
       "remote_admin='N' WHERE project='$new_project'";
    print "running: $sql\n";
    $sth = $dbh->prepare($sql);
    $sth->execute();

    $sql= "UPDATE project_mlists SET user_posts_only='Y', trailer='Y' ".
        "WHERE project='$new_project' AND list IN ".
        "('announce', 'users', 'dev')";
    print "running: $sql\n";
    $sth = $dbh->prepare($sql);
    $sth->execute();

    $ENV{QUERY_STRING} = "update+$new_project";
    my $cdir = `pwd`;
    chmod $cdir;
    chdir("$perl_dir/cgi") or die "unable to chdir to $perl_dir: $!";
    system("su httpd -s /bin/bash -c ./update.cgi");
    chdir($cdir);
}

sub warn_user {
    my ($new_project, $domain) = @@_;
    print "new project: $new_project ; domain: $domain (sleeping 5s)\n";
    sleep 5;
}

sub read_project {
    my $new_project = shift @@ARGV;

    $new_project =~ m/([a-z0-9A-Z\.\-_]+)/;
    return $1;
}

sub read_domain {
    my $domain = shift @@ARGV;

    $domain =~ m/([a-z0-9A-Z\.\-_]+)/;
    return $1;
}

sub add_qmail_control_files {
    my ($project, $domain) = @@_;
    open(OUT, ">>$virtualdomains") or die "unable to write to $virtualdomains";
    print OUT "$project.$domain:tigrisq";
    if ($project ne "www") {
        print OUT "-$project";
    }
    print OUT "\n";
    close OUT;
    open(OUT, ">>$rcpthosts") or die "unable to write to $rcpthosts";
    print OUT "$project.$domain\n";
    close OUT;
}

sub restart_qmail {
    print "restarting qmail";
    my @@command = ("$perl_dir/scripts/restart-qmail.pl");
    print ":\n\t", join(" ", @@command),"\n";
    sleep(2);
    system(@@command);
}

sub check_qmail_control_files {
    my ($project, $domain) = @@_;
    # we cleaned $project and $domain above, so this should be safe
    open(IN, "-|") || exec '/bin/grep', "^$domain:", "$virtualdomains";
    my $line = <IN>;
    chomp($line);
    if (!$line) {
        die "domain $domain does not appear to be valid";
    }
    close(IN);
    open(IN, "-|") || exec '/bin/grep', "^$project.$domain:", "$virtualdomains";
    $line = <IN>;
    chomp ($line);
    if ($line) {
        die "project $project in domain $domain already appears to be set up";
    }
}
@


1.1
log
@Initial revision
@
text
@@


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