#!/bin/bash dir='/srv/arch-mirror/arch/arch/archlinux32/irc-logs/#archlinux-ports/' declare -A colors sed ' s/([^()]*@[^()]*) // ' | \ sed ' :a $!N s/\n\s\+ | / / ta P D ' | \ while read -r a b dummy c; do if [ "${dummy}" != '|' ]; then >&2 printf 'wrong dummy "%s"\n' "${dummy}" exit 42 fi time=$( date -d@$(($(date -d"${a}" +%s)+3600*6)) +%T ) if [ "${b}" = '-->' ]; then name="${c%% *}" channel="${c##* }" printf '[%s] -!- %s has joined %s\n
\n' \ "${time}" "${time}" "${time}" "${name}" "${channel}" continue fi if [ "${b}" = '<--' ]; then name="${c%% *}" reason="${c##* (}" reason="${reason%)*}" printf '[%s] -!- %s has quit [%s]\n
\n' \ "${time}" "${time}" "${time}" "${name}" "${reason}" continue fi if [ -z "${colors["${b}"]}" ]; then colors["${b}"]=$( find "${dir}" -type f -name '*-*-*.html' -exec \ grep -h "style=\"color:#[0-9a-f]\{6\}\"><${b}>" {} \; | \ sed 's@.* style="color:#\([0-9a-f]\{6\}\)"><.*@\1@' | \ sort -u ) fi if [ -z "${colors["${b}"]}" ]; then >&2 printf 'unkown user "%s"\n' "${b}" exit 42 fi if [ $(echo "${colors["${b}"]}" | wc -l) -ne 1 ]; then >&2 printf 'user "%s" has multiple colors\n' "${b}" exit 42 fi printf '[%s] <%s> %s\n
\n' \ "${time}" "${time}" "${time}" "${colors["${b}"]}" "${b}" "${c}" done