+# Set up website. TODO: use non-/var/www dir for better separation to dump site
+rm -rf /var/www
+mkdir /var/www
+chown plom:plom /var/www
+if [ "${init_state}" = "upgrade" ]; then
+ # This assumes the old core.plomlompom.com filesystem hierarchy.
+ su -lc "cd /var/repos && git clone --mirror ${old_server}:repos/website" plom
+elif [ "${init_state}" = "new" ]; then
+ su -lc "cd /var/repos && git init --bare website.git" plom
+fi
+# TODO: find out whether this can be part of cloned repo …?
+cp "${config_tree_prefix}/other_files/website_hook_post-receive" /var/repos/website.git/hooks/post-receive
+su -lc 'cd /var/www && git clone /var/repos/website.git .' plom
+
+# Add encryption key.
+keyservers='sks-keyservers.net/ keys.gnupg.net'
+set +e
+while true; do
+ do_break=0
+ for keyserver in $(echo "${keyservers}"); do
+ su plom -c "gpg --no-tty --keyserver $keyserver --recv-key ${gpg_key}"
+ if [ $? -eq "0" ]; then
+ do_break=1
+ break
+ fi
+ echo "Attempt with keyserver ${keyserver} unsuccessful, trying other."
+ done
+ if [ "${do_break}" -eq "1" ]; then
+ break
+ fi
+done
+set -e
+
+# Set up plomlombot.
+irclogs_dir=/var/www/html/irclogs
+irclogs_pw_dir=/var/www/irclogs_pw
+mkdir -p "${irclogs_dir}"
+chown -R plom:plom "${irclogs_dir}"
+mkdir -p "${irclogs_pw_dir}"
+chown -R plom:plom "${irclogs_pw_dir}"
+if [ "${init_state}" = "new" ]; then
+ # Handle the case that the repo is in the old pre-buster server setup –
+ # even then, the URL should be the same.
+ su -lc "cd /var/repos && git clone --mirror https://plomlompom.com/repos/clone/plomlombot-irc" plom
+ su -lc "touch /var/repos/plomlombot-irc.git/git-daemon-export-ok" plom
+ cp "${config_tree_prefix}/other_files/plomlombot_hook_post-receive" /var/repos/plomlombot-irc.git/hooks/post-receive
+fi
+su -lc "git clone /var/repos/plomlombot-irc.git" plom
+cp "${config_tree_prefix}/other_files/plomlombot_daemon.sh" /home/plom/
+chown plom:plom /home/plom/plomlombot_daemon.sh
+if [ "${init_state}" = "new" ]; then
+ echo 'bot: plomlombog plomlombog #plomlomtest irc.freenode.net foo bar' >> /home/plom/.plomlombot
+ chown plom:plom /home/plom/.plomlombot
+else
+ cp "${config_tree_prefix}/setup_scripts/mirror_dir.sh" /home/plom/
+ su -lc "./mirror_dir.sh ${old_server} /home/plom/plomlombot_db" plom
+ rm /home/plom/mirror_dir.sh
+ su -lc "scp plom@${old_server}:.plomlombot ~" plom
+ su -lc "ssh plom@${old_server} \"su -lc 'service plomlombot stop'\"" plom
+fi
+
+systemctl enable plomlombot.service
+service plomlombot start
+
+# TODO:
+# - commit git-daemon-export-ok directly into the public repos; rename
+# /home/plom/public_repos to /home/plom/repos
+