Work around a bug in netcat

This commit is contained in:
polyfloyd 2016-09-21 13:01:50 +02:00
parent 3d9ad47064
commit addddffddc

View file

@ -1,8 +1,6 @@
#!/bin/bash #!/bin/bash
# Super simple IRC bot. # Super simple IRC bot.
#
# Note: Requires the OpenBSD version of netcat!
NICK="bitlair-space" NICK="bitlair-space"
CHANNEL="#bitlair-test" CHANNEL="#bitlair-test"
@ -23,13 +21,13 @@ echo "JOIN $CHANNEL"
# FIXME: Possible race condition between loop and stdin. # FIXME: Possible race condition between loop and stdin.
tail -f "$loop" & tail -f "$loop" &
nc -6 -k -lp "$INPORT" | while read line; do while true; do
echo "NOTICE $CHANNEL $line" echo "NOTICE $CHANNEL $(nc -lp "$INPORT")"
done done
} | \ } | \
nc "$SERVER" 6667 | while read message; do nc "$SERVER" 6667 | while read message; do
case "$message" in case "$message" in
PING*) echo "PONG ${message#PING :}" | tee "$loop";; PING*) echo "PONG ${message#PING :}" > "$loop";;
ERROR*) echo "$message"; exit;; ERROR*) echo "$message"; exit;;
*PRIVMSG*) echo "${message}" | sed -nr "s/^:([^!]+).*PRIVMSG[^:]+:(.*)/[$(date '+%R')] <\1> \2/p";; *PRIVMSG*) echo "${message}" | sed -nr "s/^:([^!]+).*PRIVMSG[^:]+:(.*)/[$(date '+%R')] <\1> \2/p";;
*) echo "${message}";; *) echo "${message}";;