From 2b92e4ecd4bcf1401331c79149ab3b41fc687e64 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Fri, 26 Mar 2021 15:31:54 +0100 Subject: [PATCH] contrib/casemap-logs.sh: new utility script Previous soju versions were storing log without converting the channel and nick names to their canonical lower-case representation. This could result in two log directories for the same channel/nick. This script fixes old log dirs. --- contrib/casemap-logs.sh | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 contrib/casemap-logs.sh diff --git a/contrib/casemap-logs.sh b/contrib/casemap-logs.sh new file mode 100755 index 0000000..72be262 --- /dev/null +++ b/contrib/casemap-logs.sh @@ -0,0 +1,42 @@ +#!/bin/sh -eu + +# Converts a log dir to its case-mapped form. +# +# soju needs to be stopped for this script to work properly. The script may +# re-order messages that happened within the same second interval if merging +# two daily log files is necessary. +# +# usage: casemap-logs.sh + +root="$1" + +for net_dir in "$root"/*/*; do + for chan in $(ls "$net_dir"); do + cm_chan="$(echo $chan | tr '[:upper:]' '[:lower:]')" + if [ "$chan" = "$cm_chan" ]; then + continue + fi + + if ! [ -d "$net_dir/$cm_chan" ]; then + echo >&2 "Moving case-mapped channel dir: '$net_dir/$chan' -> '$cm_chan'" + mv "$net_dir/$chan" "$net_dir/$cm_chan" + continue + fi + + echo "Merging case-mapped channel dir: '$net_dir/$chan' -> '$cm_chan'" + for day in $(ls "$net_dir/$chan"); do + if ! [ -e "$net_dir/$cm_chan/$day" ]; then + echo >&2 " Moving log file: '$day'" + mv "$net_dir/$chan/$day" "$net_dir/$cm_chan/$day" + continue + fi + + echo >&2 " Merging log file: '$day'" + sort "$net_dir/$chan/$day" "$net_dir/$cm_chan/$day" >"$net_dir/$cm_chan/$day.new" + mv "$net_dir/$cm_chan/$day.new" "$net_dir/$cm_chan/$day" + rm "$net_dir/$chan/$day" + done + + rmdir "$net_dir/$chan" + done +done