4 # Repeatedly parse config file for GPG key and bot screen configs.
6 db_dir="${HOME}/plomlombot_db"
7 irclogs_dir=/var/www/html/irclogs
8 irclogs_pw_dir=/var/www/irclogs_pw
9 hostname_mod_epoch=$(stat -c%Y /etc/hostname)
11 if [ -f "${path}" ]; then
12 cat "${path}" | while read line; do
13 first_word=$(echo -n "${line}" | cut -d' ' -f1)
15 # Read "bot:" line, start bot screen session from it if not yet existing,
16 # set up irclogs dir if not yet existing.
17 if [ "${first_word}" = "bot:" ]; then
18 session_name=$(echo -n "${line}" | cut -d' ' -f2)
19 bot_name=$(echo -n "${line}" | cut -d' ' -f3)
20 channel_name=$(echo -n "${line}" | cut -d' ' -f4)
21 shortened_channel_name="${channel_name}"
22 first_char=$(echo -n "${channel_name}" | cut -c1)
23 if [ "${first_char}" = "#" ]; then
24 shortened_channel_name=$(echo -n "${channel_name}" | cut -c2-)
26 server_name=$(echo -n "${line}" | cut -d' ' -f5)
27 login_user=$(echo -n "${line}" | cut -d' ' -f6)
28 login_pw=$(echo -n "${line}" | cut -d' ' -f7)
29 add_option=$(echo -n "${line}" | cut -d' ' -f8-)
31 screen -S "${session_name}" -Q select . > /dev/null
34 if [ "${start_screen}" -eq "1" ]; then
36 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}
38 md5_server=$(echo -n "${server_name}" | md5sum | cut -d' ' -f1)
39 md5_channel=$(echo -n "${channel_name}" | md5sum | cut -d' ' -f1)
40 logs_dir="${db_dir}/${md5_server}/${md5_channel}/logs"
41 # FIXME: Note the trouble we will have if we have the same channel
42 # name on different servers …
43 ln -sfn "${logs_dir}" "${irclogs_dir}/${shortened_channel_name}"
44 echo "${login_user}":'{PLAIN}'"${login_pw}" > "${irclogs_pw_dir}/${shortened_channel_name}"
46 # If "gpg_key" line, encrypt old raw logs to that GPG key.
47 elif [ "${first_word}" = "gpg_key" ]; then
48 key=$(echo -n "${line}" | cut -d' ' -f2)
49 mkdir -p ~/plomlombot_db
51 # Dirty hack: To avoid trouble with GPG key expiration, fake
52 # system to something reasonbly old (younger than key creation,
53 # older than expiration) by taking the mod datetime of
54 # /etc/hostname, which should have last be changed when the
56 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 {} \;