Great Circle Associates Majordomo-Workers
(October 1996)
 

Indexed By Date: [Previous] [Next] Indexed By Thread: [Previous] [Next]

Subject: A Script
From: "John D. Hays" <jhays @ Hays . ORG>
Date: Mon, 7 Oct 1996 11:41:01 -0700 (PDT)
To: majordomo-workers @ greatcircle . com

Hi All,

Here is a a script I created that others may find useful.

John
(Just Subscribed to the list)
---------------------------------------------------------
#!/usr/bin/perl
# Copyright 1996 - John D. Hays
# email: jhays@Hays.ORG
#
#
# Configurable Variables
#
$Version = '1.0';
$ThisHost = `/bin/hostname`; chop $ThisHost;
$ThisDomain = `/bin/domainname`; chop $ThisDomain;
$FQDN = $ThisHost.'.'.$ThisDomain;
$RunDate = `/bin/date`; chop $RunDate;
$Aliases="/etc/aliases";
$MajorDomoRoot="/usr/local/majordomo";
$Lists=$MajorDomoRoot.'/Lists';
$Digest=$MajorDomoRoot.'/Digest';
$Archives=$MajorDomoRoot.'/Archives';
$WrapperProg=$MajorDomoRoot.'/wrapper';
#
# Get Basic Information
#
print "\n\n\n";
print "Create List - A Program to Set Up MajorDomo Mail Lists.\n";
print "Copyright 1996 - John D. Hays\n";
print "                 P.O. Box 659\n";
print "                 Snohomish, WA  98291-0659\n";
print "\nEmail: jhays\@Hays.ORG\n";
print "\n\n";
print "This program is not in the Public Domain.\n";
print "It may be freely used for personal and educational lists.\n";
print "If you find it really useful, a small donation would be appreciated.\n";
print "\n";
print "Commercial Users should contact the author.\n";
print "\n";
print "All source must be kept intact (Comment out unneeded sections).\n";
print "Any changes/improvements that you would like to donate back to\n";
print "the author will be gratefully accepted.\n";
print "You may not include this script in another product without the author's consent.\n";
print "\n";
print "Version $Version is executing on: $FQDN\n\n";

do {
	print 'List Name (Single-String): ';
	$ListName = <STDIN>; chop $ListName;
} until ((length($ListName) > 0) && 
	(split(/\s/,$ListName) == 1));

do {
	print 'List Title (Single Line With Plain Text Name): ';
	$Title = <STDIN>; chop $Title;
} until (length($Title) > 0);

print "\nHostname for MajorDomo/List (return for $FQDN): ";
$HostName = <STDIN>; chop $HostName;
if (length($HostName) eq 0) {
	$HostName = $FQDN;
}

do {
	print 'Name of Owner (Required): ';
	$Owner = <STDIN>; chop $Owner;
} until (length($Owner));
do {
	print 'Email Address of Owner (Full foo@bar.com): ';
	$Email = <STDIN>; chop $Email;
	if (index($Email,"@") < 0) {
		@tmpArray = getpwnam($Email);
		if ((@tmpArray[0] cmp $Email) == 0) {
				$Email .= "@".$HostName;
		}
	}
} until (index($Email,"@") > 0); # Want to have name not just host
print "Using Email: $Email\n\n";
print 'Do you want a Digest[YyNn]: ';
while (<STDIN>) {
	$CreateDigest = -1;
	$CreateDigest = 1 if /[Yy]/;
	$CreateDigest = 0 if /[Nn]/;
	if ($CreateDigest > -1) {
		last;
	}
	print 'Do you want a Digest[YyNn]: ';
} 
print 'Digest ';
if ($CreateDigest) {
	print 'Selected.';
}
else {
	print 'Not Selected.';
}
print "\n";	
print 'Do you want an Archive[YyNn]: ';
while (<STDIN>) {
	$CreateArchive = -1;
	$CreateArchive = 1 if /[Yy]/;
	$CreateArchive = 0 if /[Nn]/;
	if ($CreateArchive > -1) {
		last;
	}
	print 'Do you want a Archive[YyNn]: ';
} 
print 'Archive ';
if ($CreateArchive) {
	print 'Selected.';
}
else {
	print 'Not Selected.';
}
print "\n";	
#
# Create Values For Scripts
#
$ListOwner = 'owner-'.$ListName;
$ListUserFile = $Lists."/$ListName";
$ListConfig = $ListUserFile.".config";
$ListInfo = $ListUserFile.".info";
$ListApproval = $ListName.'-approval';
$ListRequest = $ListName.'-request';
$ListRequestOwner = 'owner-'.$ListRequest;
$ListNameOut = $ListName.'-outgoing';
$ListNameOutOwner = 'owner-'.$ListNameOut;
$ListSend = $ListName.'-send';
$ListSendOwner = 'owner-'.$ListSend;
$ArchiveName = $ListName.'-archive';
$ArchiveFile = $Archives."/$ArchiveName";
$ArchiveOwner = 'owner-'.$ArchiveName;
$DigestName = $ListName.'-digest';
$DigestDir = $Digest."/$DigestName";
$DigestArchDir = $Lists."/".$DigestName.'.archive';
$DigestOut = $DigestName.'-outgoing';
$DigestOutOwner = 'owner-'.$DigestOut;
$DigestOwner = 'owner-'.$DigestName;
$DigestApproval = $DigestName.'-approval';
$DigestApprovalOwner = 'owner-'.$DigestApproval;
$DigestIt = $ListName.'-digest-it';
$DigestItOwner = 'owner-'.$DigestIt;
$DigestRequest = $DigestIt.'-request';
$DigestRequestOwner = 'owner-'.$DigestRequest;
$DigestUserFile = $Lists."/$DigestName";
$DigestConfig = $DigestUserFile.'.cf';
$DigestInfo = $DigestUserFile.'.info';
$DigestSend = $DigestName.'-send';
$DigestSendOwner = 'owner-'.$DigestSend;
$DigestHeaderPath = $DigestUserFile.'.header';
$DigestTrailerPath = $DigestUserFile.'.trailer';
$DigestVolPath = $DigestUserFile.'.vol';
$DigestNumPath = $DigestUserFile.'.num';
$MsgMax = 10000;
$MsgPrecedence = 'bulk';
@ListFiles = ($ListUserFile,$ListInfo,$ArchiveFile,
	$DigestUserFile,$DigestConfig,$DigestInfo,
	$DigestVolPath,$DigestNumPath,$DigestHeaderPath,$DigestTrailerPath);
# $ListConfig Intentionally Left Out
@Directories = ($DigestDir,$DigestArchDir);
#
# See If Name is in Use
#
&TestListName;
&PopulateAliases;
&CreateFiles;
&SetPerm;
#
# If we get here then the ListName is not in use
#

sub PopulateAliases {
	
	open(ALIASES,">>$Aliases") || die "Can't open $Aliases: $!\n";
	print ALIASES "\n#\n# MajorDomo List: $ListName\n#\n";
	print ALIASES "# Owner: $Owner ($Email)\n#\n";
	print ALIASES "$ListOwner: $Email\n";
	print ALIASES "$ListRequestOwner: $ListOwner\n";
	print ALIASES "$ListNameOutOwner: $ListOwner\n";
	print ALIASES "owner-$ListName-test: $ListOwner\n";
	print ALIASES "$ListName: \"|$WrapperProg resend -p $MsgPrecedence ",
		"-M $MsgMax -l $ListName -f $ListOwner -h $HostName ",
		"-s $ListNameOut\"\n";
	print ALIASES "$ListApproval: $ListOwner\n";
# Keep lines together
	print ALIASES "$ListNameOut: :include:$ListUserFile";
	if ($CreateArchive) {
		print ALIASES ", $ArchiveName";
	}
	if ($CreateDigest) {
		print ALIASES ", $DigestIt";
	}
	print ALIASES "\n";
# End Keep lines Together
	print ALIASES "$ListRequest: \"|$WrapperProg request-recording $ListName\"\n";
	print ALIASES "$ListName-test: $Email\n";
#
	if ($CreateArchive) {
		print ALIASES "#\n# $ListName has an Archive\n#\n";
		print ALIASES "$ArchiveOwner: $ListOwner\n";
		print ALIASES "$ArchiveName: $ArchiveFile\n";
	}
	if ($CreateDigest) {
		print ALIASES "#\n# $ListName has a Digest\n#\n";
		print ALIASES "$DigestOwner: $ListOwner\n";
		print ALIASES "$DigestOutOwner: $ListOwner\n";
		print ALIASES "$DigestItOwner: $ListOwner\n";
		print ALIASES "$DigestApproval: $ListOwner\n";
		print ALIASES "$DigestSendOwner: $ListOwner\n";
		print ALIASES "$DigestRequestOwner: $ListOwner\n";
		print ALIASES "$DigestName: $ListName\n";
		print ALIASES "$DigestIt: \"|$WrapperProg digest -r -c $DigestConfig\"\n";
		print ALIASES "$DigestOut: :include:$DigestUserFile\n";
		print ALIASES "$DigestRequest: \"|$WrapperProg request-recording $DigestName\"\n";
		print ALIASES "$DigestSend: \"|$WrapperProg resend ",
		"-p $MsgPrecedence ",
		"-l $DigestName -f $DigestOwner -h $HostName ",
		"-s $DigestOut\"\n";
	}	
	print ALIASES "\n#\n# End of $ListName\n#\n\n";
	close(ALIASES);
	print "******* Be sure to run newaliases...\n\007\n";
}

sub CreateFiles {
	open(TMPFILE,">$ListInfo") || die "Unable to open $ListInfo: $!\n";
	print TMPFILE <<"EOF";
List:		$ListName
Title:		$Title
Owner:		$Owner ($Email)
Created:	$RunDate on $FQDN
Hosted at:	$HostName
Purpose:	
EOF
	if ($CreateDigest) {
	print TMPFILE <<"EOF";
Has Digest:	$DigestName\@$HostName
EOF
	close TMPFILE;
	}
	open(TMPFILE,">$ListUserFile") || die "Unable to open $ListUserFile: $!\n";
	print TMPFILE "$Email\n";
	close(TMPFILE);
	if ($CreateDigest) {
		open(TMPFILE,">$DigestUserFile") || die "Unable to open $DigestUserFile: $!\n";
		print TMPFILE "$Email\n";
		close(TMPFILE);
		mkdir ($DigestDir,0744) || die "Unable to create $DigestDir: $!\n"; 
		mkdir ($DigestArchDir,0744) || die "Unable to create $DigestArchDir: $!\n"; 
		open(TMPFILE,">$DigestInfo") || die "Unable to open $DigestInfo: $!\n";
		print TMPFILE <<"EOF";
Digest:		$DigestName
Title:		$Title Digest
Owner:		$Owner ($Email)
Created:	$RunDate on $FQDN
Hosted at:	$HostName
Purpose:	
EOF
		close TMPFILE;
		open(DIGCONF,">$DigestConfig") || die "Unable to open $DigestConfig: $!\n";
		print DIGCONF <<"EOF";
#
# $DigestName configuration file.
#
# Owner: $Owner ($Email)
#
NAME=$Title Digest
REPLY-TO=$ListName\@$HostName
ERRORS-TO=$DigestOwner\@$HostName
TO=$DigestName
REALLY-TO=$DigestSend\@$HostName
FROM=$DigestOwner\@$HostName
HEADER=$DigestHeaderPath
TRAILER=$DigestTrailerPath
INCOMING=$DigestDir
VOL_FILE=$DigestVolPath
NUM_FILE=$DigestNumPath
ARCHIVE=$DigestArchDir
HOME=$MajorDomoRoot
DIGEST_SIZE=40000
#
# Generated: $RunDate on $FQDN
#
EOF

		close DIGCONF;
		open(TMPFILE,">$DigestHeaderPath") || die "Unable to open $DigestHeaderPath $!\n";
		print TMPFILE <<"EOH";
In this issue:

	_SUBJECTS_ 

See the end of the digest for information on subscribing to the $ListName
or $DigestName mailing lists.
EOH
		close TMPFILE;
		open(TMPFILE,">$DigestTrailerPath") || die "Unable to open $DigestTrailerPath $!\n";
		print TMPFILE <<"EOT";
To subscribe to $DigestName, send the command:

    subscribe $DigestName

in the body of a message to \"Majordomo\@$HostName\".  If you want
to subscribe something other than the account the mail is coming from,
such as a local redistribution list, then append that address to the
\"subscribe\" command; for example, to subscribe \"local-foo\":

    subscribe $DigestName local-foo\@your.domain.net

A non-digest (direct mail) version of this list is also available; to
subscribe to that instead, replace all instances of \"$DigestName\"
in the commands above with \"$ListName\".
EOT
		close TMPFILE;
		open(TMPFILE,">$DigestNumPath") || die "Unable to open $DigestNumPath $!\n";
		print TMPFILE "1\n";
		close TMPFILE ;
		open(TMPFILE,">$DigestVolPath") || die "Unable to open $DigestVolPath $!\n";
		print TMPFILE "1\n";
		close TMPFILE ;
	}
	if ($CreateArchive) {
		open(TMPFILE,">$ArchiveFile") || die "Unable to open $ArchiveFile: $!\n";
		print TMPFILE "From $Email\n";
		print TMPFILE "From: $Email ($Owner)\n";
		print TMPFILE "Date: $RunDate\n";
		print TMPFILE "Subject: Created Archive\n";
		print TMPFILE "\n\n";
		close(TMPFILE);
	}
}

sub TestListName {
	local($TmpFileName);
	local($TmpMailListName);
	local($TmpRest);
	$failure = 0;
	print "\n";
	open(ALIASES,$Aliases) || die "Can't open $Aliases: $!\n";
	while (<ALIASES>) {
		($TmpMailListName,$TmpRest) = split(/:/,$_,2);
		if (($TmpMailListName cmp $ListName) == 0) {
			print "$ListName is in $Aliases\n";
			close(ALIASES);
			$failure = 1;
			last;
		}
	}
	close(ALIASES);
	foreach $TmpFileName (@ListFiles,@Directories) {
		if (-e $TmpFileName) {
			print 'File ',$TmpFileName," exists.\n";
			$failure = 1;
		}
	}
	if ($failure) {
		print "\n**************\n";
		print "Unable to create $ListName, it appears to be in use.\n";
		print "\nExiting...\007\n";
		exit();
	}
}

sub SetPerm {
	
	local(@MajorDomoRecord,$uid,$gid);
	@MajorDomoRecord = getpwnam('majordomo');
	$uid = $MajorDomoRecord[2];
	$gid = $MajorDomoRecord[3];
	@OPerm = grep (!
		(chown($uid,$gid, $_)),
		@ListFiles,@Directories);
	print "***Couldn't change ownership on: @OPerm\n" if @OPerm;
	@OFPerm = grep (!(chmod 0744,$_), @ListFiles );
	print "***Couldn't change ownership on: @OFPerm\n" if @OFPerm;
	@ODPerm = grep (!(chmod 0755,$_), @Directories );
	print "Couldn't change ownership on: @ODPerm\n" if @ODPerm;
	
# Because sendmail must write directly to the Archive we have to give
# Special Permissions to this file. (gid 1 is bin, yours may vary)
	chown $uid,1,$ArchiveFile;
	chmod 0664,$ArchiveFile;
# Also some writeable Directories
	chown $uid,1,$DigestDir;
	chmod 0755,$DigestDir;
	chown $uid,1,$DigestArchDir;
	chmod 0755,$DigestArchDir;
	print "\n";
	exec '/bin/ls','-ld',@Directories,@ListFiles;
}


Indexed By Date Previous: Re: moderation and majordomo
From: "Alan Millar" <amillar@bolis.com>
Next: 1.94 approving messages -- documentation
From: Brock Rozen <brozen@webdreams.com>
Indexed By Thread Previous: Re: moderation and majordomo
From: "Alan Millar" <amillar@bolis.com>
Next: 1.94 approving messages -- documentation
From: Brock Rozen <brozen@webdreams.com>

Google
 
Search Internet Search www.greatcircle.com