head	1.2;
access;
symbols
	TIGRIS_1_1_0RC2:1.2
	TIGRIS_1_1_0RC1:1.2
	TIGRIS_1_1:1.2.0.14
	TIGRIS_1_0_8:1.2
	TIGRIS_1_0_8RC3:1.2
	TIGRIS_1_0_8RC2:1.2
	TIGRIS_1_0_8RC1:1.2
	TIGRIS_1_0_7:1.2
	TIGRIS_1_0_7RC3:1.2
	TIGRIS_1_0_7RC2:1.2
	TIGRIS_1_0_7RC1:1.2
	TIGRIS_1_0_6:1.2
	TIGRIS_1_0_6RC5:1.2
	TIGRIS_1_0_6RC4:1.2
	TIGRIS_1_0_6RC3:1.2
	TIGRIS_1_0_6RC2:1.2
	TIGRIS_1_0_6RC1:1.2
	TIGRIS_1_0_5:1.2
	TIGRIS_1_0_5RC6:1.2
	TIGRIS_1_0_5RC5:1.2
	TIGRIS_1_0_5RC4:1.2
	TIGRIS_1_0_5RC3:1.2
	TIGRIS_1_0_5RC2:1.2
	TIGRIS_1_0_5RC1:1.2
	TIGRIS_1_0_4:1.2
	TIGRIS_1_0_3:1.2
	TIGRIS_1_0_2:1.2
	TIGRIS_1_0_1:1.2
	TIGRIS_1_0:1.2.0.16
	TIGRIS_1_0_0:1.2
	TIGRIS_1_0_0_RC1:1.2.0.12
	dlr:1.1.1
	TIGRIS_0_9_2_4:1.2
	TIGRIS_0_9_2_3:1.2
	HELM_PEER_PORT_BRANCH:1.1.1.1
	TURBINE_PEER:1.2
	TIGRIS_0_9_2_1:1.2
	TIGRIS_0_9_2:1.2.0.10
	TIGRIS_0_9_0:1.2.0.8
	TIGRIS_0_8_4:1.2.0.6
	NEWHELM:1.1.1.1
	TIGRIS_NOV_12_2000:1.1.1
	OLDHELM:1.2.0.4
	TIGRIS_NOV_11_2000:1.2
	TIGRIS_SEP_13_2000:1.2.0.2
	TIGRIS_BASELINE:1.2;
locks; strict;
comment	@# @;


1.2
date	2000.07.20.23.35.00;	author ed;	state Exp;
branches;
next	1.1;

1.1
date	2000.07.20.22.36.00;	author ed;	state Exp;
branches
	1.1.1.1;
next	;

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


desc
@@


1.2
log
@insist on being root; use proper options to su and ensure than su
works even if httpd doesn't have a valid shell; die if we fail to
write to the qmail control files.
@
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 = '__SANDBOX__/tigris/helm/perl';
use lib "__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
@script to be run by hand after adding a new project to a domain.  this
covers several more of the items which npm described; it should be easy
to extend it to cover others as well if that is desired.  some editing
on a per-installation basis might be appropriate (eg. for setting the
proper owner for mailing lists -- that is commented out of this version,
so as to avoid setting a bogus value, but that settings is needed) --
otoh, we need a better way to set those defaults.

this adds the domains to virtualdomains / rcpthosts, restarts qmail,
sets some better defaults in the mailing lists, and then execs update.cgi.

lightly tested.
@
text
@d10 2
a11 2
my $perl_dir = '__SANDBOX__/helm/perl';
use lib "__SANDBOX__/helm/perl";
d20 2
d36 6
d69 6
a74 4
    my $update_cgi = "$perl_dir/cgi/update.cgi";
    chdir("$perl_dir/cgi");
    $ENV{QUERY_STRING}="update+$new_project";
    exec("$update_cgi");
d99 1
a99 1
    open(OUT, ">>$virtualdomains");
d106 1
a106 1
    open(OUT, ">>$rcpthosts");
a113 4
    if ($> > 0) { # effectivitely, i'm not root
        print " (adding sudo since i'm not root)";
        unshift @@command, "sudo";
    }
d115 1
@


1.1.1.1
log
@Merging newhelm tree into helm, as per IZ issue #557.  Previous major version of helm is tagged TIGRIS_NOV_11_2000.
@
text
@d10 2
a11 2
my $perl_dir = '__SANDBOX__/tigris/helm/perl';
use lib "__SANDBOX__/tigris/helm/perl";
a19 2
    check_uid();

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

d61 4
a64 6
    $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);
d89 1
a89 1
    open(OUT, ">>$virtualdomains") or die "unable to write to $virtualdomains";
d96 1
a96 1
    open(OUT, ">>$rcpthosts") or die "unable to write to $rcpthosts";
d104 4
a108 1
    sleep(2);
@


