home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume28 / bmw-5 / part01 / mkarchive < prev    next >
Text File  |  1994-07-09  |  5KB  |  202 lines

  1. #! /usr/bin/perl
  2.  
  3. # mkarchive -- move the currently monthly file to the archive.
  4.  
  5. $USAGE = "$0 <listname>\n";
  6.  
  7. if ($#ARGV != 0) { die ("$USAGE"); }
  8.  
  9. $LISTNAME = $ARGV[0];
  10. $LISTNAME =~ tr/A-Z/a-z/;  # Convert everything to lower case for now.
  11.  
  12. %GLOBALS = ();
  13.  
  14. ## We need to set the hostname.  You this is done by querying hostname and
  15. ## domainname.  You can override this here or set your FQDN global explicitly
  16. ## in the bmw.cf file.
  17.  
  18. $HOSTNAME = `hostname`; chop($HOSTNAME);
  19. $DOMAINNAME = `domainname`; chop($DOMAINNAME);
  20.  
  21. ## Path to bmw.cf - CHANGE THIS FOR YOUR SYSTEM
  22. #$BMWCF = "/etc/bmw.cf";
  23. $BMWCF = "/home/bmw/bmw.cf";
  24.  
  25. ## Process the config file and learn about all the globals.
  26. ## FORMAT OF CONFIG FILE:
  27. ##   Each line of the config file should have the format
  28. ##     <globalname> = <value>
  29. ##   for example,
  30. ##     BASEDIR = /usr/local/lib/bmw
  31. ##
  32. ## I now set the defaults.  You should override these in your bmw.cf file.
  33. ##
  34. $GLOBALS{'SENDMAIL'} = "/usr/lib/sendmail";
  35. $GLOBALS{'SENDMAILOPTS'} = "";
  36. $GLOBALS{'ENCODE'} = "/usr/bin/uuencode";
  37. $GLOBALS{'COMPRESS'} = "/bin/gzip";
  38. $GLOBALS{'COMPSUFFIX'} = ".gz";
  39. $GLOBALS{'ARCDIR'} = "/home/ftp/pub/lists";
  40. $GLOBALS{'ARCOWNER'} = "ftp";
  41. $GLOBALS{'OWNER'} = "postmaster";
  42. $GLOBALS{'DEBUG'} = 0;
  43. $GLOBALS{'LOG'} = 0;
  44. $GLOBALS{'MAXGETS'} = 5;
  45. $GLOBALS{'PREFERFTP'} = 0;
  46. $GLOBALS{'TRACE'} = 0;
  47. $GLOBALS{'BASEDIR'} = "/usr/local/lib/bmw";
  48. $GLOBALS{'FQDN'} = $HOSTNAME . "." . $DOMAINNAME;
  49. $GLOBALS{'DIGEST'} = 0;
  50. $GLOBALS{'TMPDIR'} = "/var/tmp";
  51. $GLOBALS{'USER'} = "bmw";
  52. $GLOBALS{'GROUP'} = "bin";
  53.  
  54.  
  55. @VALIDGLOBALS = ("SENDMAIL", "SENDMAILOPTS", "TMPDIR", "ENCODE",
  56.                  "COMPRESS", "COMPSUFFIX", "ARCDIR", "ARCOWNER",
  57.                  "OWNER", "DEBUG", "LOG", "MAXGETS", "PREFERFTP",
  58.                  "TRACE", "BASEDIR", "FQDN", "DIGEST", "USER", "GROUP");
  59.  
  60.  
  61.  
  62. sub validGlobal {
  63. ## Determine if the string is a valid global reference.
  64.   local($s) = @_;
  65.   local($i);
  66.   for ($i=0; $i<=$#VALIDGLOBALS; $i++) {
  67.     if ($s eq $VALIDGLOBALS[$i]) { return 1; }
  68.   }
  69.   return 0;
  70. }
  71.  
  72.  
  73.  
  74. ## Load the globals from the cf file.
  75. if (-e $BMWCF) {
  76.   local($lno) = 0;
  77.   local(@LINE);
  78.   open(CF, "<$BMWCF") || die "Cannot open $BMWCF: $!\n";
  79.   while (<CF>) {
  80.     $lno++;
  81.     chop;
  82.     tr/\t //d;
  83.     @LINE = split("=");
  84.     if (!$LINE[0]) { die "ERROR in $BMWCF line $lno; $_\n"; }
  85.     $LINE[0] =~ tr/a-z/A-Z/;
  86.     if (!&validGlobal($LINE[0])) {
  87.       die "ERROR in $BMWCF line $lno; Unknown global \"$LINE[0]\"\n";
  88.     }
  89. ## Good.  We have a valid global
  90.     $GLOBALS{$LINE[0]} = $LINE[1];
  91.   }
  92. }
  93. else {
  94.   die "$BMWCF does not exist!\n";
  95. }
  96.  
  97. if ($GLOBALS{'DEBUG'}) {
  98.   local($key);
  99.   foreach $key (keys %GLOBALS) {
  100.     print "$key = $GLOBALS{$key}",$LF;
  101.   }
  102. }
  103.  
  104.  
  105. ## Internal global values.  Do not fiddle with these without good reason.
  106. $VERSION = "5.0";
  107. $LISTDIR = $GLOBALS{'BASEDIR'} . "/$LISTNAME";
  108. $LISTARCDIR = $GLOBALS{'ARCDIR'} . "/$LISTNAME";
  109. $DIGESTFILE = "$LISTDIR/digest";
  110. $TOCFILE = "$LISTDIR/digesttoc";
  111. $LOGFILE = "$LISTDIR/log";
  112. $MONTHLY = "$LISTDIR/monthly";
  113. $MESSAGE = "$LISTDIR/message";
  114. $HELP = "$LISTDIR/help";
  115. $WDIR = "";                   # working directory suffix for gets
  116.  
  117. $TMPFILE = $GLOBALS{'TMPDIR'} . "/bmw$$";
  118. $REPLYFILE = "$TMPFILE.reply";
  119. $TMPLOGFILE = "$TMPFILE.log";
  120.  
  121. $LISTOWNER = "$LISTNAME-owner";
  122. $LISTREQUEST = "$LISTNAME-request";
  123.  
  124. @ERRORS = ();
  125. %LOCKS = ();
  126.  
  127. ##
  128. ## Exit routines.  These make sure everything is cleaned up.
  129. ##
  130. sub finish {
  131.   local($rc) = @_;
  132.   local($i);
  133.   system("rm -f $TMPFILE");
  134.   if ($#ERRORS > -1) {
  135.     open(T, ">$TMPFILE");
  136.     print T "Subject: Errors from $LISTREQUEST\n";
  137.     print T "From: $LISTOWNER\n";
  138.     print T "To: $LISTOWNER\n\n";
  139.     for ($i = 0; $i <= $#ERRORS; $i++) {
  140.       print T $ERRORS[$i],$LF;
  141.     }
  142.     close(T);
  143.     system("cat $TMPFILE | $GLOBALS{'SENDMAIL'} \'$LISTOWNER\'");
  144.     system("rm -f $TMPFILE")
  145.   }
  146.   exit($rc);
  147. }
  148.  
  149.  
  150. sub DIE {
  151.   local($msg) = @_;
  152.   print STDERR "$msg",$LF;
  153.   $ERRORS[$#ERRORS+1] = $msg;
  154.   local($key);
  155.   foreach $key (keys %LOCKS) {
  156.     system("rm -f $key");
  157.   }
  158.   &finish(-1);
  159. }
  160.  
  161.  
  162. # Test for things that must exist.
  163.  
  164. &DIE("$LISTDIR does not exist!\n") if (! -d $LISTDIR);
  165. &DIE("$LISTARCDIR does not exist!\n") if (! -d $LISTARCDIR);
  166.  
  167.  
  168. $FROM = "";
  169. $SUBJECT = "";
  170. $MID = "";
  171. $DATE = `date`; chop($DATE);
  172.  
  173. if (! -e $MONTHLY)
  174. {
  175.   system("touch $MONTHLY");
  176.   chown $GLOBALS{'USER'}, $GLOBALS{'GROUP'}, $DIGESTFILE;
  177.   chmod 0664 , $MONTHLY;
  178.   &finish(0);
  179. }
  180.  
  181. shift;
  182.  
  183.  
  184. # Copy monthly to tmpdir with a new name
  185. $thismonth = (Jan,Feb,Mar,Apr,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[(localtime)[4]];
  186. $thisyear = (localtime)[5];
  187.  
  188. $FNAME = $LISTNAME . "-" . $thismonth . "-" . $thisyear;
  189. $FNAMECMP = $LISTARCDIR . "/" . $FNAME . $GLOBALS{'COMPSUFFIX'};
  190. $TMPF = $TMPFILE . $GLOBALS{'COMPSUFFIX'};
  191.  
  192. $COMPRESSOR = $GLOBALS{'COMPRESS'} . " " . $TMPFILE;
  193.  
  194. system("mv $MONTHLY $TMPFILE");
  195. #print $COMPRESSOR . "\n";
  196. system("$GLOBALS{'COMPRESS'} $TMPFILE");
  197. system("mv $TMPF $FNAMECMP");
  198. chmod 0444, $FNAMECMP;
  199.  
  200. &finish();
  201.  
  202.