#!/bin/sh # Oracle v1.0 # # $Copyright: $ # Copyright (c) 2002 by Steve Baker (ice@mama.indstate.edu) # 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 IFS=":" questions=/usr/games/oracledb/questions skipped=0 user="`/usr/bin/whoami`" get_question() { line=1 while read usr question <&3 do if [ "$usr" != "$user" ]; then ask_question "$usr" "$question" if [ $? = 0 ]; then remove "$line" return fi fi line=$[$line+1] done 3< $questions } ask_question() { if [ $skipped -ne 0 ]; then echo "Perhaps this question is more to your liking:" echo "" else echo "Before I answer your question, you must answer one of mine:" echo "" fi echo "\"$question\"" echo "" echo "What is your answer?" read answer if [ "x$answer" = "x" ]; then echo "You should at least try to answer one of my questions." skipped=1 return 1 fi /bin/telnet localhost mail << ANSWER >& /dev/null helo localhost mail From: Oracle@localhost rcpt To: $1 data From: The Great Oracle Subject: The oracle answers your question. The answer to your question: "$2" is: "$answer" The great Oracle hath spoken. - The Oracle . quit ANSWER echo "Thank you." echo "" return 0 } remove() { tmp=/tmp/oracle.$$ sed ${1}d $questions > $tmp cat $tmp > $questions rm $tmp return 0 } echo "Ask the oracle: The oracle is IN." if [ -s $questions ]; then get_question fi echo "What is your question, my child?" echo "" read question echo "" if [ "x$question" = "x" ]; then echo "You call that a question? Beat it kid!" exit 0 fi echo "$user:$question" >> $questions echo "Hmm, that is an interesting question. I will have to think about it" echo "for a while. Now, go away, you bother me."