#!/bin/sh
#Usage: Create a new signature with a random quote.
sigpath=`eval getenv SIGNATURE`
sigpath=`echo $sigpath | awk '{ print $3 }' -`

if [ \( "$sigpath" = "" \) -o \( "$sigpath" = "(null)" \) ]
 then
	sigpath=$HOME/.signature
fi

if [ "$1" = "-h" ]
 then
	echo "Use newsig creates a signature file for you, with a random quote"
	echo "from the quote program. The signature file will be .signature"
	echo "in your home directory, unless you 'setenv' the environment"
	echo "variable SIGNATURE to another filepath."
	echo " "
	echo "You can send to newsig the same options that you would to the"
	echo "quote program."
	exit
fi

if test $# -eq 0
 then
	quote 1 > $HOME/.qotd
 else
	quote $@ > $HOME/.qotd
fi

if test -r $HOME/.sigline
 then
	cat $HOME/.sigline $HOME/.qotd > $sigpath
 else
	USERNAME=`whoami`
	HOSTNAME=`hostname`
	REALNAME=`grep "^$USERNAME:" /etc/passwd | awk -F":" '{ print $5 }' -`
	(echo $REALNAME;echo "$USERNAME@$HOSTNAME";echo "------------";cat $HOME/.qotd) > $sigpath
fi
cat $HOME/.qotd
rm $HOME/.qotd
