#!/bin/bash dirs='/srv/arch-mirror/arch/arch/archlinux32/irc-logs/' declare -A colors create_color() { if [ -z "${colors["$1"]}" ]; then colors["$1"]=$( find "${dirs}" -type f -name '*-*-*.html' -exec \ grep -h "style=\"color:#[0-9a-f]\{6\}\"><$1>" {} \; | \ sed 's@.* style="color:#\([0-9a-f]\{6\}\)"><.*@\1@' | \ sort -u ) fi if [ -z "${colors["$1"]}" ]; then colors["${b}"]=$(hexdump -n 4 -e '4/4 "%08X" 1 "\n"' /dev/urandom | head -c 6) # >&2 printf 'unkown user "%s"\n' "$1" # exit 42 fi if [ $(echo "${colors["$1"]}" | wc -l) -ne 1 ]; then >&2 printf 'user "%s" has multiple colors\n' "$1" exit 42 fi } # the desired format is: # "time nick | msg" # "time --> | nick ... channel" # "time <-- | nick ... (reason)" # "time -- | old-nick new-nick" # "time * | nick action" # we reformat other formats accordingly if [ "$2" = 'ii' ]; then sed ' s/^\([0-9]\+\) -!- \(.* has joined \S\+$\)/\1 --> | \2 / s/^\([0-9]\+\) -!- \(.* has left \S\+$\)/\1 <-- | \2 / s/^\([0-9]\+\) <\(\S\+\)> /\1 \2 | / s/^/@/ ' elif [ "$2" = 'tyzoid' ]; then channel="$3" sed ' s/^\[\([^]]\+\)] \*\*\* Joins: \(\S\+\) .*$/\1 --> | \2 has joined '"${channel}"' / t s/^\[\([^]]\+\)] \*\*\* Quits: \(\S\+\) (\(.*\))$/\1 <-- | \2 has quit (\3)/ t s/\[\([^]]\+\)] <\(\S\+\)> /\1 \2 | / t d ' elif [ "$2" = 'html' ]; then channel="$3" sed -n ' /^/{ s@^(\([^)]\+\)) @\1 @ /entered the room\.<\/b>$/{ s@^\(\S\+\) \(.*\S\) \[.*] entered the room\.<\/b>$@\1 --> | \2 has joined '"${channel}"' @ p d } / left the room /{ s@^\(\S\+\) \(.*\S\) left the room (quit: \(.*\))\.
$@\1 <-- | \2 has quit (\3)@ p d } / left the room\./{ s@^\(\S\+\) \(.*\S\) left the room\.
$@\1 <-- | \2 has quit (Quit: \2)@ p d } / is now known as /{ s@^\(\S\+\) \(.*\S\)\s*
$@\1 -- | \2@ p d } d } \@
\*\*\*\S\+ @{ s@^(\([^)]\+\)) \*\*\*\(\S*\) \(.*\)
$@\1 * | \2 \3@ p d } //{ s@^(\([^)]\+\)) \(\S\+\): @\1 \2 | @ s@
$@@ p d } ' else cat fi | \ sed ' s/([^()]*@[^()]*) // ' | \ sed ' :a $!N s/\n\s\+ | / / ta P D ' | \ sed ' s@\(\s\)\(https\?://\S\+\)@\1\2@g ' | \ while read -r a b dummy c; do if [ "${dummy}" != '|' ]; then >&2 printf 'wrong dummy "%s" in line:\n%s\n' "${dummy}" "${a} ${b} ${dummy} ${c}" exit 42 fi time=$( date -d@$(($(date -d"${a}" +%s)+3600*$1)) +%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 [ "${b}" = '--' ]; then before="${c%% *}" after="${c##* }" printf '[%s] %s is now known as %s\n
\n' \ "${time}" "${time}" "${time}" "${before}" "${after}" continue fi if [ "${b}" = '*' ]; then nick="${c%% *}" action="${c#* }" create_color "${nick}" printf '[%s] * %s %s\n
\n' \ "${time}" "${time}" "${time}" "${colors["${nick}"]}" "${nick}" "${action}" continue fi create_color "${b}" printf '[%s] <%s> %s\n
\n' \ "${time}" "${time}" "${time}" "${colors["${b}"]}" "${b}" "${c}" done