Subject: Re: Random .sigs?
From: [email-masked] (Steven King, Software Archaeologist)
Date: 11 Oct 1993 16:32:53 GMT
Newsgroups: news.newusers.questions

[email-masked] (Peter Sarrett) publicly declared:
>Is it possible to post a random .sig file?  That is, have your .sig file
>chosen randomly from one of a number of possible files every time you
>include it?

Here's a message I posted to news.software readers just last week.
This lets me have a different signature for every newsgroup, or every
hierarchy.  In addition, if no relevant signature is found it'll choose
one from a random collection.  I use 'trn'.  You may be able to adapt
the concept if you use another newsreader.

For my script, signatures are stored under ~/News in the same directory
structure as KILL files.  The name of the signature is "signature",
with no leading dot.  If you want a signature for rec.sport.rugby you 
create ~/News/rec/sport/rugby/signature.  If you want a signature for
all of rec.sport.*, create ~/News/rec/sport/signature. Signatures are
searched from the bottom of the tree. A signature for rec.sport.rugby
would be used in preference to the one for the rest of rec.sport.*
when you're posting to the rugby group. If no signatures are found
under ~/News a random one is selected from ~/.sigs. Every file in .sigs
is fair game to be included as a signature, so don't leave your love
letters there!

Trn honors the "NEWSPOSTER" environment variable to tell it to use
a posting program other than Pnews.  You should set this to:

    NEWSPOSTER=Psig %C -h %h

Psig is the script included below.  %C is the name of the newsgroup
to which you're posting, and "-h %h" is the name of the header file.
FYI, the default for NEWSPOSTER is "Pnews -h %h".

This should do it.  Create the signatures, run the script, knock
yourself out!

---=== Cut Here ===---  ---=== Cut Here ===---
#! /usr/local/bin/perl
#
# Steve King, 18 Dec 91
#
# Synopsis: Psig newsgroup [Pnews-parms]
# (Though this should only be called from a newsreader...)
#
# Selects a signature based on the current newsgroup.  Psig will
# read the News directory tree in the user's home directory
# ($HOME/News/...) to find a file called "signature" in the
# current newsgroup.  If that file doesn't exist, the directory
# tree will be followed backwards through the hierarchy looking for
# a signature.  If none are found a random signature will be picked
# out of $sigdir
#
# When a signature is found it is copied to $HOME/.signature for
# inclusion in the article by inews.  Pnews is then called to
# create and post the article.
#
# The $sigdir variable can be pointed to any directory.  That 
# directory should contain ONLY files you want to use as .signatures, 
# and nothing else.  Any file in $sigdir is fair game for inclusion.
#
# To get this to work from (t)rn, set the NEWSPOSTER environment
# variable to "Psig %C -h %h".

$home   = $ENV{'HOME'};
$sigdir = "$home/.sigs";

@group = ("News",split(/\./,shift(@ARGV)));
$count  = @group;
$found  = 0;

while (@group) {
  $gname = join('/',@group);
  if (-f "$home/$gname/signature") {
    print "(Using signature from $home/$gname)\n";
    system("cp $home/$gname/signature $home/.signature");
    $found = 1;
    @group = ("dummy");
  }
  pop(@group);
}

if (! $found) {
  opendir(SIGS,$sigdir);
  @siglist = grep(!/^\./,readdir(SIGS));
  closedir(SIGS);
   
  $seed = time % ($$ * $$);              # Seems to provide a good seed.
  srand($seed);
  $chosen = int((rand() * @siglist));

  print "(Using random signature)\n";
  system("cp $sigdir/@siglist[$chosen] $home/.signature");
}

if ($ENV{'DOTDIR'} && ($ENV{'DOTDIR'} ne $home)) {
  system("cp $home/.signature $ENV{'DOTDIR'}/.signature");
}
system("cat $home/.signature");
system("Pnews @ARGV");
---=== Cut Here ===---  ---=== Cut Here ===---

-- 
-------------------------------------------------------+-----------------------
You don't know how much you don't know until you       |      Steven King
know a lot.                                            |   Motorola Cellular
                                       (Nick Holland)  |   [email-masked]