home · contact · privacy
Add maximum age for non-raw log files to plomlombot daemon.
authorChristian Heller <c.heller@plomlompom.de>
Fri, 14 Dec 2018 00:33:22 +0000 (01:33 +0100)
committerChristian Heller <c.heller@plomlompom.de>
Fri, 14 Dec 2018 00:33:22 +0000 (01:33 +0100)
all_new_2018/user_scripts/plomlombot_daemon.sh

index b7054e1c23a7d37cd630031453027f5f55965b45..4831b3ce0cc9b83880eef5998c880a444f5159c1 100755 (executable)
@@ -9,45 +9,45 @@ irclogs_pw_dir=/var/www/irclogs_pw
 while true; do
     if [ -f "${path}" ]; then
         cat "${path}" | while read line; do
-           first_word=$(echo -n "${line}" | cut -d' ' -f1)
+            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)
+            # 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)
+                server_name=$(echo -n "${line}" | cut -d' ' -f5)
                 login_user=$(echo -n "${line}" | cut -d' ' -f6)
                 login_pw=$(echo -n "${line}" | cut -d' ' -f7)
-               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 …
+                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 -r 604800 -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 -sfn "${logs_dir}" "${irclogs_dir}/${shortened_channel_name}"
                 echo "${login_user}":'{PLAIN}'"${login_pw}" > "${irclogs_pw_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)
+            # 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
+                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