#!/bin/sh # irl -- irc-rss-listener set -e die() { echo "$*" 1>&2 exit 1 } usage() { die 'Usage: irl.sh -c CHANNEL [-h HOST] [-p PORT]' } port=6667 host=localhost args=$(getopt c:h:p: $*) if [ $? -ne 0 ]; then usage fi set -- $args while [ $# -ne 0 ]; do case "$1" in -c) channel="$2"; shift; shift;; -h) host="$2"; shift; shift;; -p) port="$2"; shift; shift;; --) shift; break;; esac done [ -z "$channel" ] && usage notify() { nc $host $port </dev/null NICK rssbot USER rssbot rssbot $host :rssbot PRIVMSG #$channel :New post '$1' here: $2 QUIT EOM } feeds=/etc/irl/$host.$channel known_ids=/tmp/irl-known.$host.$channel.ids all_ids=/tmp/irl-all.$host.$channel.ids new_ids=/tmp/irl-new.$host.$channel.ids [ ! -e $feeds ] && die "Create $feeds to begin!" command -v sfeed >/dev/null || die "sfeed not installed" # Truncate last pull >"$all_ids" for feed in $(cat "$feeds"); do curl -sS "$feed" | sfeed | \ awk -F' ' "{ print \$3, \$2 }" >>"$all_ids" done if [ -e "$known_ids" ]; then diff "$known_ids" "$all_ids" | grep '^>' | sed 's/^..//' > "$new_ids" while read url subj; do notify "$subj" "$url" done < "$new_ids" fi # Update cp -f "$all_ids" "$known_ids"