🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: news.software.readers
9 messages
9 total messages Started by J.D. Falk Wed, 22 Feb 1995 03:25
TRN: change .signature by newsgroup
#15442
Author: J.D. Falk
Date: Wed, 22 Feb 1995 03:25
17 lines
1757 bytes
	I currently use a Perl script to randomly choose my .signature 
file (very simple -- each time I run it my .signature changes.)  Also, 
there are a few newsgroups in which I'd like to consistently have the 
same .signature (each and every time I post there.)
	So, basically, I think what I'm looking for is the way to write a 
macro which will call a script (or other UNIX command) as soon as I enter 
a specific newsgroup.
	I've seen a few hints that this is possible, but could find 
nothing specific in either the man file or the trn FAQ.
	Any suggestions?


-- 
 -------------========== J.D. Falk <jdfalk@cais.com> =========-------------
  | "My lockpick of choice has always been the Panther Assault Cannon."  |
  |                                             -David L. Hoff           |
 --------========== http://www.cais.com/jdfalk/home.html ==========--------
Re: TRN: change .signature by newsgroup
#15464
Author: Tim Pierce
Date: Wed, 22 Feb 1995 23:08
171 lines
6512 bytes
In article <3iearp$227@news.cais.com>, J.D. Falk <jdfalk@cais.com> wrote:

>	I currently use a Perl script to randomly choose my .signature 
>file (very simple -- each time I run it my .signature changes.)  Also, 
>there are a few newsgroups in which I'd like to consistently have the 
>same .signature (each and every time I post there.)

I wrote a Perl script a couple of years ago, based heavily
on Tom Christiansen's getsig.pl, to do just that.  It's not
entirely functional: it must be run by inews after your
article has been written (i.e. won't work with all TIN
implementations) and getting it to work right for Elm or
something would require a lot of work.

Here's the overview: create a directory named ".Signatures"
in your home directory.  (Or call it something else, and
change the value of $SIGS in the script.)  This directory
contains two configuration files, "news-index" and
"mail-index", which specify which signature to use for
different mail and news messages.

For example, here's the contents of a recent news-index file
of mine:

uchi\..*	local
soc\.motss	global
news\.		green-card
soc\.genealogy\.surnames	surnames
^		unsolicited-email

The first field is a regexp identifying the newsgroup in
question.  The second is the name of a file in your
.signatures directory to use as the .signature.
"green-card" is the "Green Card fodder" signature I was
using recently, "unsolicited-email" is the current one, and
so on.  The algorithm used is a first-match: if I
crossposted an article between uchi.general and
news-admin.misc, the script would use "local" for the
signature rather than "green-card."

Presented without warranty: you gets what you pays for.  Any
elegance, cleverness or beauty in this script is entirely
the fault of Tom Christiansen, and it's a wonder it survived
until the present day.

#!/usr/local/bin/perl
#
# signature.pl -- supply a .signature based on whether the newsgroup or
# recipient name matches a certain pattern
#
# Unless changed by the user, all signatures are in the directory
# $HOME/.Signatures.  This directory also contains two files, "news-index" and
# "mail-index".  Each line of each file contains two fields, separated
# by whitespace.  The first field is a regular expression matching a set
# of newsgroup names (or, in the case of mail-index, e-mail addresses),
# and the second field names the signature file that is to be used for
# those newsgroups (or mail addresses).
#
# This script first determines whether the user is posting or mailing
# based on the modification times of $HOME/.article and $HOME/.letter.
# Then it identifies the first recipient (either newsgroup or e-mail
# address) of the message and, for lack of a better yardstick, uses that
# as the sole determinant in choosing a .signature.  Then it searches
# news-index (or mail-index) for the first regexp that matches the
# target newsgroup or address, and uses the file thus named for the
# contents of the signature file.
#
# Tim Pierce, March 1993.  Liberally hacked from Tom Christiansen's
# sigrand.pl.
################################################################
# begin configuration section 

$MKNOD = "/etc/mknod";

&gethome;

$FIFO 		= "$DOTDIR/.signature";
$ART 		= "$DOTDIR/.article";
$LET            = "$DOTDIR/.letter";
$SIGS 		=   "$HOME/.Signatures";
$SEMA		=   "$HOME/.getsigpid";

# end configuration section -- HOME gets autoconf'd
################################################################

&setup;

&justme;

fork && exit; 	# be a daemon 

open (SEMA, ">$SEMA") || die "can't write $SEMA: $!";
print SEMA "$$\n";
close SEMA || die "can't close $SEMA: $!";

MAIN: while (1) {
    open (FIFO, "> $FIFO") || die "can't write $FIFO: $!";

    # choose signature based on mtimes of .article and .letter
    if ((stat($ART))[9] > (stat($LET))[9]) {
	$target = '^Newsgroups: ';
        $INFILE = $ART;
	$INDEX = "$SIGS/news-index";
    } else {
	$target = '^To: ';
        $INFILE = $LET;
	$INDEX = "$SIGS/mail-index";
    }
    $signame = &choose;

    if ($signame) {
       open (SIGFILE, "$SIGS/$signame");
       while (<SIGFILE>) { print FIFO; }
    } else {
       print "$0: warning: found no signature\n";
    }
    close FIFO;
    sleep 2; # to avoid dup sigs
}

################################################################

sub setup {
    unless (-p $FIFO) {
	if (!-e _) {
	    system("$MKNOD $FIFO p") && die "can't mknod $FIFO";
	    warn "created $FIFO as a named pipe\n";
	} else {
	    die "$0: won't overwrite file .signature\n";
	} 
    }
}

sub choose {
    local ($line, $pat, $file);
    open INFILE || die "cannot open $INFILE";
    while (<INFILE>) {
        /\S/ || return "";
	/$target/ && last;
    }
    ($_) = /: ([^,\s]*)/;
    open INDEX || die "cannot open $INDEX";
    while ($line = <INDEX>) {
	next if ($line =~ /^\#/);
	chop ($line);
	($pat, $file) = split (/\s+/, $line);
	last if /$pat/;
    }
    (defined ($line)) ? $file : "";
}

sub gethome {
    @pw = getpwuid($<);
    $HOME = $ENV{HOME} || $ENV{LOGDIR} || $pw[7]
		       || die "no home directory for user $<";
    $DOTDIR = $ENV{DOTDIR} || $HOME;
}

# "There can be only one."  --the Highlander
sub justme {
    if (open SEMA) {
	chop($pid = <SEMA>);
	kill(0, $pid) && die "$0 already running (pid $pid)\n";
	#warn "COOL: no $pid: $!";
	close SEMA;
    } 
} 

-- 
Unsolicited commercial electronic mail sent to this address will be
proofread at a cost of $200/hour (one half-hour minimum).
Re: TRN: change .signature by newsgroup
#15481
Author: Eugene Tyurin
Date: Thu, 23 Feb 1995 04:06
10 lines
1429 bytes
The last time I looked through Perl archives, I remember seeing a
script that would append an apropriate signature basing on the
Newsgroups field. I think it was a drop-in replacement for Pnews,
but I'm not sure.

-- 
Eugene Tyurin, Inst. for Theoretical Physics  -  Stony Brook Univ.
            WWW: http://www.physics.sunysb.edu:80/~gene/plan.html
       Internet: gene@insti.physics.sunysb.edu
Those who don't understand Unix are doomed to reinvent it, poorly.
Re: TRN: change .signature by newsgroup
#15501
Author: J.D. Falk
Date: Thu, 23 Feb 1995 16:26
21 lines
1991 bytes
In news.software.readers, Tim Pierce <twpierce@midway.uchicago.edu> wrote...

> I wrote a Perl script a couple of years ago, based heavily
> on Tom Christiansen's getsig.pl, to do just that.  It's not
> entirely functional: it must be run by inews after your
> article has been written (i.e. won't work with all TIN
> implementations) and getting it to work right for Elm or
> something would require a lot of work.
[rest deleted]

	That looks like it might help -- thanks, Tim!  I'll probably hack
it a little further, so that it can run my script whenever it doesn't
choose a .signature in one of the normal fashions.
	Only problem is, how does one get inews to run it?  (The inews man
file isn't installed on this system for some reason.)

-- 
 -------------========== J.D. Falk <jdfalk@cais.com> =========-------------
  |     "Just take your pills and kiss your apogee goodbye."             |
  |                                            -Crow T. Robot, MST3K     |
 --------========== http://www.cais.com/jdfalk/home.html ==========--------
Re: TRN: change .signature by newsgroup
#15517
Author: Tom Christiansen
Date: Thu, 23 Feb 1995 21:32
158 lines
4982 bytes
In news.software.readers, 
    twpierce@midway.uchicago.edu (Tim Pierce) writes:
:Presented without warranty: you gets what you pays for.  Any
:elegance, cleverness or beauty in this script is entirely
:the fault of Tom Christiansen, and it's a wonder it survived
:until the present day.

Hm.. hm...

Here's the current version in use as we speak.  Somewhere there's
a version that build Markov chains to figure the best signature,
but that's a little slower. :-)

--tom

#!/usr/bin/perl
#
# sigrand -- supply random fortunes for .signature file

################################################################
# begin configuration section 

$MKNOD = "/etc/mknod";

$SIG{'PIPE'} = 'IGNORE';  # idiot vi

&gethome;

# for rec/humor/funny instead of rec.humor.funny
$NG_IS_DIR 	= 1; 	

$FULLNAME 	= "$HOME/.fullname";
$FIFO 		= "$HOME/.signature";
$ART 		= "$HOME/.article";
$NEWS 		= "$HOME/News";
$SIGS 		= "$NEWS/SIGNATURES";
$SEMA		= "$HOME/.sigrandpid";
$GLOBRAND	= 1/4;	# chance to use global sigs anyway

# end configuration section -- HOME and FORTUNE get autoconf'd
################################################################

&setup;

&justme;

#fork && exit; 	# be a daemon 

open (SEMA, ">$SEMA") || die "can't write $SEMA: $!";
print SEMA "$$\n";
close SEMA || die "can't close $SEMA: $!";

MAIN: while (1) {
    open (FIFO, "> $FIFO") || die "can't write $FIFO: $!";
    &load_sigs;
    $sig = $sig[rand @sig];
    print FIFO $name, "\n" x (3 - ($sig =~ tr/\n//)), $sig;
    close FIFO;
    sleep 2; # to avoid dup sigs
}
die "NOT REACHED";

################################################################

sub setup {
    if (-e $FULLNAME) {
	$name = `cat $FULLNAME`;
	die "$FULLNAME should contain only 1 line, aborting" 
	    if $name =~ tr/\n// > 1;
    } else {
	chop($host = `hostname`);
	($host) = gethostbyname($host) unless $host =~ /\./;
	$user = $ENV{USER} || $ENV{LOGNAME} || $pw[0] || die "intruder alert";
	($name = $pw[6]) =~ s/,.*//;
	$name =~ s/&/\u\L$user/g; # can't believe some folks still do this
	$name = "\t$name\t$user\@$host\n";
    } 


    &check_fortunes if !-e $SIGS;

    unless (-p $FIFO) {
	if (!-e _) {
	    system("$MKNOD $FIFO p") && die "can't mknod $FIFO";
	    warn "created $FIFO as a named pipe\n";
	} else {
	    die "$0: won't overwrite file .signature\n";
	} 
    }


    srand(time|$$);
}

sub load_sigs {
    local($sigfile) = &ng;
    if (!-e $sigfile) {
	@sig = (&fortune);
	return;
    } 
    open (SIGS,$sigfile) || die "can't open $sigfile";
    local($/) = "%%\n";
    undef @sig;
    while (<SIGS>) {
	s!$/$!!o;
	push(@sig,$_);
    } 
    close SIGS;
} 

sub ng {
     (rand(1.0) > ($GLOBRAND) && open ART) || return $SIGS;   
     local($/) = '';
     $_ = <ART>;
     ($ng) = /Newsgroups:\s*([^,\s]*)/;
     $ng =~ s!\.!/!g if $NG_IS_DIR; 	# if rn -/,  or SAVEDIR=%p/%c
     $ng = "$NEWS/$ng/SIGNATURES";
     -f $ng ? $ng : $SIGS;
} 

sub fortune {
   local($_, $tries);
   do { 
       $_ = `$FORTUNE -s`; 
   } until tr/\n// < 4 || $tries++ > 20;
   local($*) = 1;
   s/^/ /g;
   $_ || " SIGRAND: deliver random signals to all processes.\n";
} 

sub check_fortunes {
    return if $FORTUNE;
    foreach $dir (split(/:/, $ENV{PATH}), '/usr/games') {
	return if -x ($FORTUNE = "$dir/fortune");
    } 
    die "Need either $SIGS or a fortune program, bailing out";
} 

sub gethome {
    @pw = getpwuid($<);
    $HOME = $ENV{HOME} || $ENV{LOGDIR} || $pw[7]
		       || die "no home directory for user $<";
}

# "There can be only one."  --the Highlander
sub justme {
    if (open SEMA) {
	chop($pid = <SEMA>);
	kill(0, $pid) && die "$0 already running (pid $pid)\n";
	#warn "COOL: no $pid: $!";
	close SEMA;
    } 
} 
-- 
Tom Christiansen      Perl Consultant, Gamer, Hiker      tchrist@mox.perl.com

	    Ivy, privy, famous; clamour
	    And enamour rhyme with hammer.
Re: TRN: change .signature by newsgroup
#15543
Author: Tim Pierce
Date: Fri, 24 Feb 1995 15:08
20 lines
1754 bytes
In article <3iicvp$j88@news.cais.com>, J.D. Falk <jdfalk@cais.com> wrote:

>In news.software.readers, Tim Pierce <twpierce@midway.uchicago.edu> wrote...
>
>> I wrote a Perl script a couple of years ago, based heavily
>> on Tom Christiansen's getsig.pl, to do just that.
>
>	Only problem is, how does one get inews to run it?

It's a named pipe.  Put "getsig.pl" (or whatever you call
the script) into your .login and "kill -9 `cat
$HOME/.getsigpid`" in your .logout, and it'll be started
every time you log in.  Then it will be run any time a
process tries to read .signature -- if your inews presently
includes .signature when you post, it'll work without
modifying inews, Pnews, or anything.

-- 
Unsolicited commercial electronic mail sent to this address will be
proofread at a cost of $200/hour (one half-hour minimum).
Random .signature changer
#15574
Author: J.D. Falk
Date: Sat, 25 Feb 1995 07:38
68 lines
2864 bytes
[continuing a thread I started in news.software.readers]

	Well, based on the script I was already using and the ones posted
here, I came up with something which is /close/ to what I'd been hunting
for -- it now randomly chooses each time the .signature file is read. 
	Now I just need to steal s'more code (unless somebody can think 
of something simpler) so that, for example, I use one specific file every 
time I'm reading alt.internet.media-coverage, but keeps scrambling in all 
the other groups.
	Also, this routine doesn't quite work right with PINE -- I have 
to manually load the .signature file, even though my .pinerc is set right 
and /used/ to work.
	Obviously, it requires a mkfifo command to start working right.

---------- [~/perl/scramble2]
#!/usr/bin/perl
#
# J.D.'s Sunny Side Signature Scrambler
# Based on a bunch of perl routines written by better programmers than me
#

$HOME = "/home/jdfalk";
$name = shift || ($name = "");
$FIFO = "$HOME/.signature";
$MKNOD = "/etc/mknod";
$QUOTES = "$HOME/TAG/.quotes";

unless (-p $FIFO) {
	if (!-e _) {
		system("$MKNOD $FIFO p");
		warn "Created $FIFO as a named pipe\n";
	} else {
		die "$0: won't overwrite file $FIFO \n";
	}
}

MAIN: while (1) {
	open (FIFO, "> $FIFO") || die "Can't write FIFO: $!";

	open(QUOTES, "$QUOTES") || die "Cannot open ~/.quotes for input.\n"; while(<QUOTES>) {
		if(/^\s*#\s*$/) {
			if($quote) {
				if( ($name EQ "") || ($quote =~ /$name/i) ) {
					push(@quotes, $quote);
				}
			}
			undef $quote;
			next;
		}
		$quote .= $_;
	}
	close(QUOTES);

	srand(time()^$$);
	$index = int(rand(@quotes));

	print FIFO $quotes[$index];	
	close FIFO;

	sleep 2;
}
---------- [ END ]
-- 
 -------------========== J.D. Falk <jdfalk@cais.com> =========-------------
  |   "I came alone as me, just an idea in a long chain of discovery."   |
  |                                      -Roy Harper                     |
 --------========== http://www.cais.com/jdfalk/home.html ==========--------
Re: Random .signature changer
#15585
Author: Russell Mosemann
Date: Sat, 25 Feb 1995 19:59
21 lines
1936 bytes
jdfalk@cais.cais.com (J.D. Falk) writes:

>	Also, this routine doesn't quite work right with PINE -- I have 
>to manually load the .signature file, even though my .pinerc is set right 
>and /used/ to work.

   You mean pine doesn't work right with the routine.  The function
they use to read small files like .signature files checks to see how
large the file is so that it can preallocate a buffer.  It sees that the
named pipe has a size of 0 and decides nothing needs to be read.  I told
them about this years ago, but the maintainers of pine say that it is
further down on their list than other things.  Let them know you would
like it fixed.
   I'd also like to point out that randomly selecting .signatures is the
same as selecting them in order.
-- 
Russell Mosemann     Concordia College      Voice: (402) 643-7445
Computing Center     Seward, NE 68434       Fax:   (402) 643-4073
"If I break into the Unix operating system, it will be with a hammer."
 - Lon Jungemann
Re: Random .signature changer
#15648
Author: Peter Kappesser
Date: Tue, 28 Feb 1995 10:02
26 lines
2306 bytes
Recently in news.software.readers, jdfalk@cais.com wrote:
>[continuing a thread I started in news.software.readers]
>
>	Well, based on the script I was already using and the ones posted
>here, I came up with something which is /close/ to what I'd been hunting
>for -- it now randomly chooses each time the .signature file is read. 
>	Now I just need to steal s'more code (unless somebody can think 
>of something simpler) so that, for example, I use one specific file every 
>time I'm reading alt.internet.media-coverage, but keeps scrambling in all 
>the other groups.

While [t]rn is running, it keeps the name of the newsgroup you're currently
reading in $HOME/.rnlast (the first line of the file). You could read this
to find out which group you're in and select the file you want, or if there
is no file for that group, generate a random sig. Easiest way I think
would be to have a .sigs directory, and name the group's signature file
after the group so you don't have to do any further looking-up; it's the
same way most folks are handling killfiles nowadays (see the trn FAQ).

--
"Do I contradict myself? Very well then I contradict myself,
(I am large, I contain multitudes.) (No you don't.) (Yes, I do.)
(No you don't!) (Yes I do!!) HEY! I'm trying to write here!!"
				-- "Leaves of Grass", first draft
pjkappes@mailbox.syr.edu (Peter Kappesser)
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads