Home | History | Annotate | Download | only in scripts
      1 #! /bin/sh
      2 ## Shit-simple script to supply the "privmsg <recipient>" of IRC typein, and
      3 ## keep the connection alive.  Pipe this thru "nc -v -w 5 irc-server port".
      4 ## Note that this mechanism makes the script easy to debug without being live,
      5 ## since it just echoes everything bound for the server.
      6 ## if you want autologin-type stuff, construct some appropriate files and
      7 ## shovel them in using the "<" mechanism.
      8 
      9 # magic arg: if "tick", do keepalive process instead of main loop
     10 if test "$1" = "tick" ; then
     11 # ignore most signals; the parent will nuke the kid
     12 # doesn't stop ^Z, of course.
     13   trap '' 1 2 3 13 14 15 16
     14   while true ; do
     15     sleep 60
     16     echo "PONG !"
     17   done
     18 fi
     19 
     20 # top level: fire ourselves off as the keepalive process, and keep track of it
     21 sh $0 tick &
     22 ircpp=$!
     23 echo "[Keepalive: $ircpp]" >&2
     24 # catch our own batch of signals: hup int quit pipe alrm term urg
     25 trap 'kill -9 $ircpp ; exit 0' 1 2 3 13 14 15 16
     26 sleep 2
     27 
     28 sender=''
     29 savecmd=''
     30 
     31 # the big honkin' loop...
     32 while read xx yy ; do
     33   case "${xx}" in
     34 # blank line: do nothing
     35     "")
     36 	continue
     37     ;;
     38 # new channel or recipient; if bare ">", we're back to raw literal mode.
     39     ">")
     40 	if test "${yy}" ; then
     41 	  sender="privmsg ${yy} :"
     42 	else
     43 	  sender=''
     44 	fi
     45 	continue
     46     ;;
     47 # send crud from a file, one line per second.  Can you say "skr1pt kidz"??
     48 # *Note: uses current "recipient" if set.
     49     "<")
     50 	if test -f "${yy}" ; then
     51 	  ( while read zz ; do
     52 	    sleep 1
     53 	    echo "${sender}${zz}"
     54 	  done ) < "$yy"
     55 	  echo "[done]" >&2
     56 	else
     57 	  echo "[File $yy not found]" >&2
     58 	fi
     59 	continue
     60     ;;
     61 # do and save a single command, for quick repeat
     62     "/")
     63 	if test "${yy}" ; then
     64 	  savecmd="${yy}"
     65 	fi
     66 	echo "${savecmd}"
     67     ;;
     68 # default case goes to recipient, just like always
     69     *)
     70 	echo "${sender}${xx} ${yy}"
     71 	continue
     72     ;;
     73   esac
     74 done
     75 
     76 # parting shot, if you want it
     77 echo "quit :Bye all!"
     78 kill -9 $ircpp
     79 exit 0
     80