From: Christian Heller Date: Mon, 13 Dec 2021 19:27:44 +0000 (+0100) Subject: Fix plomlombot setup. X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/decks/index.html?a=commitdiff_plain;h=178c9ac8013f275f83f0282d772cb46749ec8018;p=config Fix plomlombot setup. --- diff --git a/bullseye/other_files/plomlombot_daemon.sh b/bullseye/other_files/plomlombot_daemon.sh index c4627af..a9285bf 100755 --- a/bullseye/other_files/plomlombot_daemon.sh +++ b/bullseye/other_files/plomlombot_daemon.sh @@ -1,2 +1,62 @@ #!/bin/sh -GIT_WORK_TREE=/home/plom/plomlombot-irc git checkout -f +set -e + +# Repeatedly parse config file for GPG key and bot screen configs. +path=~/.plomlombot +db_dir="${HOME}/plomlombot_db" +irclogs_dir=/var/www/html/irclogs +irclogs_pw_dir=/var/www/irclogs_pw +hostname_mod_epoch=$(stat -c%Y /etc/hostname) +while true; do + if [ -f "${path}" ]; then + cat "${path}" | while read line; do + first_word=$(echo -n "${line}" | cut -d' ' -f1) + + # Read "bot:" line, start bot screen session from it if not yet existing, + # set up irclogs dir if not yet existing. + if [ "${first_word}" = "bot:" ]; then + session_name=$(echo -n "${line}" | cut -d' ' -f2) + bot_name=$(echo -n "${line}" | cut -d' ' -f3) + channel_name=$(echo -n "${line}" | cut -d' ' -f4) + shortened_channel_name="${channel_name}" + first_char=$(echo -n "${channel_name}" | cut -c1) + if [ "${first_char}" = "#" ]; then + shortened_channel_name=$(echo -n "${channel_name}" | cut -c2-) + fi + server_name=$(echo -n "${line}" | cut -d' ' -f5) + login_user=$(echo -n "${line}" | cut -d' ' -f6) + login_pw=$(echo -n "${line}" | cut -d' ' -f7) + add_option=$(echo -n "${line}" | cut -d' ' -f8-) + set +e + screen -S "${session_name}" -Q select . > /dev/null + start_screen=$? + set -e + if [ "${start_screen}" -eq "1" ]; then + cd ~/plomlombot-irc + LANG="en_US.UTF-8" screen -d -m -S "${session_name}" ./run.sh -r 604800 -n "${bot_name}" -s "${server_name}" -c "${channel_name}" ${add_option} + fi + md5_server=$(echo -n "${server_name}" | md5sum | cut -d' ' -f1) + md5_channel=$(echo -n "${channel_name}" | md5sum | cut -d' ' -f1) + logs_dir="${db_dir}/${md5_server}/${md5_channel}/logs" + # FIXME: Note the trouble we will have if we have the same channel + # name on different servers … + ln -sfn "${logs_dir}" "${irclogs_dir}/${shortened_channel_name}" + echo "${login_user}":'{PLAIN}'"${login_pw}" > "${irclogs_pw_dir}/${shortened_channel_name}" + + # If "gpg_key" line, encrypt old raw logs to that GPG key. + elif [ "${first_word}" = "gpg_key" ]; then + key=$(echo -n "${line}" | cut -d' ' -f2) + mkdir -p ~/plomlombot_db + cd ~/plomlombot_db + # Dirty hack: To avoid trouble with GPG key expiration, fake + # system to something reasonbly old (younger than key creation, + # older than expiration) by taking the mod datetime of + # /etc/hostname, which should have last be changed when the + # system was set up. + find . -path '*/*/raw_logs/*.txt' -mtime +1 -type f -exec gpg --recipient "${key}" --trust-model always --faked-system-time="${hostname_mod_epoch}" --encrypt {} \; -exec rm {} \; + fi + + done + sleep 1 + fi +done diff --git a/bullseye/other_files/plomlombot_hook_post-receive b/bullseye/other_files/plomlombot_hook_post-receive new file mode 100755 index 0000000..c4627af --- /dev/null +++ b/bullseye/other_files/plomlombot_hook_post-receive @@ -0,0 +1,2 @@ +#!/bin/sh +GIT_WORK_TREE=/home/plom/plomlombot-irc git checkout -f