#!/usr/bin/perl -w # # Copyright (c) 2002 Steve Slaven, All Rights Reserved. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of # the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, # MA 02111-1307 USA # use strict; use vars qw( %ENV ); use Getopt::Std; eval { use Time::HiRes qw(stat); }; undef $/; my %o; $o{ S } = "$ENV{HOME}/.signature"; $o{ b } = "$ENV{HOME}/.signature.base"; $o{ s } = "$ENV{HOME}/.signature.sigs"; $o{ t } = 0.25; getopts( 'hdVb:s:S:t:A', \%o ); die( qq{ sigmaker v0.92 Makes signatures from a base file and a sig file Author: Steve Slaven - http://hoopajoo.net Usage: $0 [-hdVA] [-S SIGFILE] [-b BASEFILE] [-s SIGLIST] [-t TIME] -h This help -d Daemon mode, make a new .signature file every time the old one is read -A Do not use atime when determining if writing a new sig is needed in daemon mode -t Seconds to sleep between atime checks in daemon mode. Default is 0.25 seconds -V Verbose operation -S The output signature file, defaults to ~/.signature -s SIGLIST file, contains all taglines. Defaults to ~/.signature.sigs -b SIG base file, basic info like name, email, etc that is in every sig. Defaults to ~/.signature.base Reads .signature.base for the base sig and .signature.sigs for the list of possible taglines to include. The .signature.sigs file is just a list of tag lines separated by a '%' on a line by itself, and the .signature.base is the whole sig with a '\$\$' where the tag line should be inserted. In daemon mode a new sig is written only if the sigfile has already been read. This cuts down on the time the system spends writing out files and instead it just watches the atime. To force writing a sig file every iteration use -A. This is needed with mailers such as Mozilla Mail which cannot read a FIFO and need a real file to read. A base file might look like: -- \$\$ Steve Slaven - http://hoopajoo.net And the sigs file might look like: End hunger Save the whales Free the mallocs % Computer - A device designed to speed and automate errors. Which might create a sig like: -- Computer - A device designed to speed and automate errors. Steve Slaven - http://hoopajoo.net } ) if $o{ h }; my $sig; my @witty_sigs; my @sigstack; load_sigs(); load_base(); if( ! $o{ d } ) { # Non-daemon mode, write and get out write_sig(); exit; } # Handle HUP to re-read stuff $SIG{ HUP } = \&load_all; my( $last_atime, $atime ); $last_atime = 0; while( 1 ) { # Only write if accessed $atime = ( stat( $o{ S } ) )[ 8 ]; # Ignore atime option $last_atime = $atime - 1 if $o{ A }; write_sig() if $last_atime < $atime; $last_atime = $atime; # Microsleepys select(undef, undef, undef, 0.25); } sub write_sig { my $sigcopy = $sig; my $usesig; if( ! @sigstack ) { shuffle_sigs(); @sigstack = @witty_sigs; } $usesig = shift( @sigstack ); #$sigcopy =~ s/\$\$/$witty_sigs[ int(rand(scalar(@witty_sigs))) ]/ge; $sigcopy =~ s/\$\$/$usesig/ge; msg( "Writing sig at " . scalar( localtime() ) ); local *OUT; open( OUT, ">$o{S}" ); print OUT $sigcopy; close( OUT ); } sub msg { print STDERR shift() . "\n" if $o{ V }; } sub load_sigs { # Read sigs local *IN; open( IN, $o{ s } ); @witty_sigs = split( /\n%\s*\n/s, ); close( IN ); } sub load_base { # Read the base part local *IN; open( IN, $o{ b } ); $sig = ; close( IN ); } # Added in 0.91 so that you don't see repeat sigs sub shuffle_sigs { my $array = \@witty_sigs; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); @$array[$i,$j] = @$array[$j,$i]; } } sub load_all { @sigstack = (); load_sigs(); load_base(); }