home *** CD-ROM | disk | FTP | other *** search
/ Hacks & Cracks / Hacks_and_Cracks.iso / hackersclub / km / library / hack / irc2.txt < prev    next >
Text File  |  1998-03-25  |  2KB  |  81 lines

  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 77
  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 then save a single command, for quick repeat [such as "join #hack"
  62. # when they're being kick-happy...]
  63.     "/")
  64.     if test "${yy}" ; then
  65.       savecmd="${yy}"
  66.     fi
  67.     echo "${savecmd}"
  68.     ;;
  69. # default case goes to recipient, just like always
  70.     *)
  71.     echo "${sender}${xx} ${yy}"
  72.     continue
  73.     ;;
  74.   esac
  75. done
  76.  
  77. # parting shot, if you want it
  78. echo "quit :TTFN"
  79. kill -9 $ircpp
  80. exit 0
  81.