#!/usr/bin/perl # Stole a lot from mj_key_cache # needs error checking and input validation $cf = $ENV{'MAJORDOMO_CF'} || '/usr/local/majordomo/majordomo.cf'; $editor = $ENV{"EDITOR"} || "vi"; $aliases = 'aliases.majordomo'; $host = 'ugh.net.au'; $newalias = '/usr/local/sbin/postalias'; $user = 'majordom'; $group = 'majordom'; $user = getpwnam($user); $group = getgrnam($group); while ($ARGV[0]) { if ($ARGV[0] eq '-C') { $cf = $ARGV[1]; shift(@ARGV); shift(@ARGV); } elsif ($ARGV[0] eq '-o') { $owner = $ARGV[1]; shift(@ARGV); shift(@ARGV); } elsif ($ARGV[0] eq '-v') { $verbose =1; # say what we are doing shift(@ARGV); } elsif ($ARGV[0] eq '-q') { $quiet = 1; # dont prompt shift(@ARGV); } elsif ($ARGV[0] eq '-l') { $list = $ARGV[1]; shift(@ARGV); shift(@ARGV); } else { warn("Invalid argument ($ARGV[0])\n"); usage(); } } if ($list eq '' || $owner eq '') { usage(); } die("$cf not readable\n") unless -r $cf; die("require of $cf failed: $@\n") unless require $cf; # Go to majordomo home chdir("$homedir"); # Set umask umask(0002); # Create empty list file if ($verbose) { print "Creating $listdir/$list\n"; } if (-e $listdir . '/' . $list) { die("List ($list) already exists!\n"); } open(JUNK, ">$listdir/$list") or die("Creation of $listdir/$list failed: $!\n"); close(JUNK); # Create a .info file if (! $quiet) { print "You must now enter the brief description of the mailing list for the\n$list.info file. Press return to continue.\n"; ; if ($verbose) { print "Creating .info file.\n"; } system($editor, $listdir . '/' . $list . '.info') && die ("system failed: $!\n"); } # Adjust ownership print "Chowning list files\n" if $verbose; chown($user, $group, ($listdir . '/' . $list, $listdir . '/' . $list . '.info')); # Add aliases if ($verbose) { print "Creating aliases.\n"; } open(ALIASES,">>$aliases") || die ("Can't open aliases file ($aliases) for append: $!\n"); print ALIASES "\n# $list added by $0 by " . getpwuid($<) . ' at ' . localtime(time()) . "\n"; print ALIASES "owner-$list: $owner\n"; print ALIASES "owner-$list-outgoing: owner-$list\n"; print ALIASES "$list-approval: owner-$list\n\n"; print ALIASES "$list: \"|$homedir/wrapper resend -l $list -h $host $list-outgoing\"\n"; print ALIASES "$list-outgoing::include:$listdir/$list,\n\t\"\|$homedir/wrapper archive -a -m -f $filedir/$list$filedir_suffix\"\n\n"; print ALIASES "$list-request: \"|$homedir/wrapper majordomo -l $list\"\n"; close(ALIASES); # Rebuild alias database if ($verbose) { print "Rebuilding alias database.\n"; } system($newalias, $homedir . '/' . $aliases) && die("rebuilding alias db failed: $!\n"); print "Done.\n"; sub usage { die("usage: newlist [-C config] -o owner [-q] [-v] -l list\n"); }