From: Christian Heller Date: Wed, 12 Dec 2018 17:13:15 +0000 (+0100) Subject: Improve plomlombot setup. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/calendar?a=commitdiff_plain;h=f0645216fd72fab16e246bdb1104ae952d5f12db;p=config Improve plomlombot setup. --- diff --git a/all_new_2018/linkable_etc_files/web/etc/systemd/system/plomlombot.service b/all_new_2018/linkable_etc_files/web/etc/systemd/system/plomlombot.service index 6e228cb..e836e46 100644 --- a/all_new_2018/linkable_etc_files/web/etc/systemd/system/plomlombot.service +++ b/all_new_2018/linkable_etc_files/web/etc/systemd/system/plomlombot.service @@ -4,7 +4,8 @@ Description=plomlombot screen [Service] Type=forking User=plom -ExecStart=/bin/sh -c 'screen -d -m -S plomlombot ~/start_plomlombot.sh plomlombob "#plomlompomtest"' +ExecStart=/bin/sh -c '~/start_plomlombot.sh' +Restart=always [Install] WantedBy=multi-user.target diff --git a/all_new_2018/setup_plomlombot.sh b/all_new_2018/setup_plomlombot.sh index eeb1688..2282603 100755 --- a/all_new_2018/setup_plomlombot.sh +++ b/all_new_2018/setup_plomlombot.sh @@ -1,14 +1,14 @@ #!/bin/sh set -e -config_tree_prefix="${HOME}/config/all_new_2018//" -cp "${config_tree_prefix}"/user_scripts/start_plomlombot.sh /home/plom/ -chown plom:plom /home/plom/start_plomlombot.sh +config_tree_prefix="${HOME}/config/all_new_2018/" +irclogs_dir=/var/www/html/irclogs +cp "${config_tree_prefix}"/user_scripts/plomlombot_daemon.sh /home/plom/ +chown plom:plom /home/plom/plomlombot_daemon.sh apt -y install screen python3-venv su plom -c "cd && git clone /var/public_repos/plomlombot-irc" systemctl enable /etc/systemd/system/plomlombot.service service plomlombot start -mkdir -p /var/www/html/irclogs -plomlompomtest_dir=/home/plom/plomlombot_db/6f322d574618816aa2d6d1ceb4fd2551/789a38c5af11bb71833d89cd74387fcb/logs -su plom -c "cd && mkdir -p ${plomlompomtest_dir}" -ln -s "${plomlompomtest_dir}" /var/www/html/irclogs/plomlompomtest +mkdir -p "${irclogs_dir}" +chown -r plom:plom "${irclogs_dir}" +echo "Don't forget to add an encryption key to plom's key chain and to his ~/.plomlombot." diff --git a/all_new_2018/user_scripts/plomlombot_daemon.sh b/all_new_2018/user_scripts/plomlombot_daemon.sh new file mode 100755 index 0000000..60b0d9c --- /dev/null +++ b/all_new_2018/user_scripts/plomlombot_daemon.sh @@ -0,0 +1,43 @@ +#!/bin/sh +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 +while true; do + 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) + server_name=$(echo -n "${line}" | cut -d' ' -f5) + set +e + screen -S "${session_name}" -Q select . > /dev/null + start_screen=$? + set -e + if [ "${start_screen}" -eq "1" ]; then + cd ~/plomlombot-irc + screen -d -m -S "${session_name}" ./run.sh -n "${bot_name}" -s "${server_name}" "${channel_name}" + 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 -sf "${logs_dir}" "${irclogs_dir}/${channel_name}" + + # If "key:" line, encrypt old raw logs to that GPG key. + elif [ "${first_word}" = "gpg_key": ]; then + key=$(echo -n "${line}" | cut -d' ' -f2) + cd ~/plomlombot_db + find . -path '*/*/raw_logs/*.txt' -mtime +1 -type f -exec gpg --recipient "${key}" --trust-model always --encrypt {} \; -exec rm {} \; + fi + + done + sleep 1 +done