#!/bin/sh # run and handle the irc client # shellcheck source=../conf/default.conf . "${0%/*}/../conf/default.conf" # start ii if it is not running if ! pgrep -x ii > /dev/null; then rm -rf --one-file-system "${irc_dir}" screen -S ii -d -m ii -s irc.freenode.net -f buildmaster -n buildmaster sleep 10 fi # register if not yet done if tail -n1 "${irc_dir}/nickserv/out" 2> /dev/null | \ grep -qF 'This nickname is registered. Please choose a different nickname'; then printf 'identify %s\n' "${irc_password}" | \ sponge "${irc_dir}/nickserv/in" fi # join #archlinux32 if not yet done if ! grep ' buildmaster\.archlinux32\.org .* buildmaster$' "${irc_dir}/out" | \ tail -n1 | \ grep -q ' #archlinux32 '; then { echo '/j #archlinux32' echo '/WHO buildmaster' } | \ sponge "${irc_dir}/in" fi # start watch daemon if not running yet if ! pgrep -f '/ii-connect watch$' > /dev/null; then screen -S ii-connect.watch -d -m "${base_dir}/bin/ii-connect" watch fi # watch if asked to if [ "$1" = 'watch' ]; then done_something=false while pgrep -x 'ii' > /dev/null; do # this avoids missing modifications during our last execution if ! ${done_something}; then # shellcheck disable=SC2046 inotifywait -e 'CLOSE_WRITE,CLOSE' $( find "${irc_dir}" \ -type f \ -name 'out' ) fi done_something=false find "${irc_dir}" \ -type f \ -name 'out' \ -printf '%p\n' | \ while read -r out_file; do channel="${out_file%/out}" channel="${channel##*/}" if [ -z "${channel%%#*}" ]; then prefix='buildmaster: ' else prefix='' fi regex='^\(\S\+ \)\?\S\+ <\S\+> '"${prefix}"'why[- ]don'"'"'\?t[- ]you \(build\|stabilize\|unstage\|keep\|stubbornly_keep\) ' if grep -q "${regex}" "${out_file}"; then done_something=true sed -n ' s/'"${regex}"'/\2 / T p ' "${out_file}" | \ while read -r line; do reason=$( echo "${line}" | \ xargs "${base_dir}/bin/why-dont-you" 2>&1 ) if [ "$(echo "${reason}" | wc -l)" -le 5 ]; then echo "${reason}" else echo "${reason}" | \ head -n5 printf '... (%s lines total)\n' "$(echo "${reason}" | wc -l)" fi | \ sponge "${out_file%/out}/in" done sed -i "/${regex}/d" "${out_file}" fi regex='^\(\S\+ \)\?\S\+ <\S\+> '"${prefix}"'wtf ' if grep -q "${regex}" "${out_file}"; then done_something=true sed -n ' s/'"${regex}"'// T p ' "${out_file}" | \ while read -r line; do if ! reason=$(pkgfile "${line}"); then reason="Huh, I don't know that one." fi if [ "$(echo "${reason}" | wc -l)" -le 5 ]; then echo "${reason}" else echo "${reason}" | \ head -n5 printf '... (%s lines total)\n' "$(echo "${reason}" | wc -l)" fi | \ sponge "${out_file%/out}/in" done sed -i "/${regex}/d" "${out_file}" fi done sleep 1 done exit fi