home · contact · privacy
Improve IRC bot/logs setup.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 13 Dec 2018 18:18:10 +0000 (19:18 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 13 Dec 2018 18:18:10 +0000 (19:18 +0100)
all_new_2018/linkable_etc_files/web/etc/systemd/system/plomlombot.service
all_new_2018/setup_plomlombot.sh
all_new_2018/user_scripts/plomlombot_daemon.sh

index e836e468ac824e6b85eee6236046946375870fd3..a4f67694378dc909647485bf504e1f605ba42576 100644 (file)
@@ -2,9 +2,9 @@
 Description=plomlombot screen
 
 [Service]
 Description=plomlombot screen
 
 [Service]
-Type=forking
+Type=simple
 User=plom
 User=plom
-ExecStart=/bin/sh -c '~/start_plomlombot.sh'
+ExecStart=/bin/sh -c '~/plomlombot_daemon.sh'
 Restart=always
 
 [Install]
 Restart=always
 
 [Install]
index 22826037f2b4f713a0f76a9827670400db8d5392..93e857d7d4f2c7b0a25fb29ae157d2f059031199 100755 (executable)
@@ -1,14 +1,25 @@
 #!/bin/sh
 set -e
 
 #!/bin/sh
 set -e
 
+# Ensure we have a GPG target to encrypt to.
+if [ $# -lt 1 ]; then
+    echo "Need public key ID as argument."
+    false
+fi
+gpg_key="$1"
+
 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
 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
+apt -y install screen python3-venv gpg dirmngr
+su plom -c "gpg --recv-key ${gpg_key}"
+# TODO: After this, we could in theory remove dirmngr if we only installed it just now.
 su plom -c "cd && git clone /var/public_repos/plomlombot-irc"
 systemctl enable /etc/systemd/system/plomlombot.service
 service plomlombot start
 mkdir -p "${irclogs_dir}"
 su plom -c "cd && git clone /var/public_repos/plomlombot-irc"
 systemctl enable /etc/systemd/system/plomlombot.service
 service plomlombot start
 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."
+chown -R plom:plom "${irclogs_dir}"
+echo "Don't forget to add a file ~/.plomlombot with content such as:"
+echo "gpg_key ${gpg_key}"
+echo "bot: SCREEN_SESSION_NAME BOT_NAME #CHANNEL_NAME IRC_SERVER_NAME"
index 60b0d9c6f559bab6d9ecdc2e5177202992b16d5f..b7d07093f138ee82e8802ce432776ba011f50b7c 100755 (executable)
@@ -6,38 +6,46 @@ path=~/.plomlombot
 db_dir="${HOME}/plomlombot_db"
 irclogs_dir=/var/www/html/irclogs
 while true; do
 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)
+    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)
-            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}"
+           # 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 …
+                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
+               ln -sf "${logs_dir}" "${irclogs_dir}/${shortened_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
+           # If "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
+               find . -path '*/*/raw_logs/*.txt' -mtime +1 -type f -exec gpg --recipient "${key}" --trust-model always --encrypt {} \; -exec rm {} \;
+           fi
 
 
-    done
-    sleep 1
+        done
+        sleep 1
+    fi
 done
 done