From 7975ff6d2dc1459a7047494d440d19f5a65cee14 Mon Sep 17 00:00:00 2001
From: Christian Heller <c.heller@plomlompom.de>
Date: Thu, 9 Apr 2020 22:45:57 +0200
Subject: [PATCH] Add redo blog URL catcher.

---
 buster/apt-mark/dumpsite                           |  5 +++++
 .../etc/nginx/sites-available/dumpsite.nginx       | 11 ++++++++---
 .../etc/systemd/system/url_catcher.service         | 11 +++++++++++
 buster/setup_scripts/setup_dumpsite.sh             | 14 +++++++++++++-
 4 files changed, 37 insertions(+), 4 deletions(-)
 create mode 100644 buster/etc_files/dumpsite/etc/systemd/system/url_catcher.service

diff --git a/buster/apt-mark/dumpsite b/buster/apt-mark/dumpsite
index 403aefb..881bba2 100644
--- a/buster/apt-mark/dumpsite
+++ b/buster/apt-mark/dumpsite
@@ -6,3 +6,8 @@ pandoc
 html2text
 uuid-runtime
 python3
+# for url_catcher daemon
+python3-venv
+build-essential
+python3-dev
+screen
diff --git a/buster/etc_files/dumpsite/etc/nginx/sites-available/dumpsite.nginx b/buster/etc_files/dumpsite/etc/nginx/sites-available/dumpsite.nginx
index edd79fb..25c2d62 100644
--- a/buster/etc_files/dumpsite/etc/nginx/sites-available/dumpsite.nginx
+++ b/buster/etc_files/dumpsite/etc/nginx/sites-available/dumpsite.nginx
@@ -16,8 +16,13 @@ server {
     }
 
     location /zettel/ {
-            # rewrite non-suffixed filenames to .html ones
-            rewrite ^(/zettel/(.*/)*[^./]+)$ $1.html;
-            autoindex on;
+        # rewrite non-suffixed filenames to .html ones
+        rewrite ^(/zettel/(.*/)*[^./]+)$ $1.html;
+        autoindex on;
+    }
+
+    location /uwsgi/ {
+        include uwsgi_params;
+        uwsgi_pass 127.0.0.1:3031;
     }
 }
diff --git a/buster/etc_files/dumpsite/etc/systemd/system/url_catcher.service b/buster/etc_files/dumpsite/etc/systemd/system/url_catcher.service
new file mode 100644
index 0000000..8b8f2d9
--- /dev/null
+++ b/buster/etc_files/dumpsite/etc/systemd/system/url_catcher.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=url_catcher screen
+
+[Service]
+Type=forking
+User=plom
+ExecStart=/bin/sh -c 'cd ~/url-catcher && screen -d -m ./run.sh'
+Restart=always
+
+[Install]
+WantedBy=multi-user.target
diff --git a/buster/setup_scripts/setup_dumpsite.sh b/buster/setup_scripts/setup_dumpsite.sh
index 2fa9d89..5a0bec3 100755
--- a/buster/setup_scripts/setup_dumpsite.sh
+++ b/buster/setup_scripts/setup_dumpsite.sh
@@ -49,16 +49,28 @@ su -lc "git clone --mirror ${old_server}:zettel.git" plom
 cp "${config_tree_prefix}/other_files/zettel_hook_post-receive" /home/plom/zettel.git/hooks/post-receive
 su -lc "git clone ~/zettel.git && cd zettel && redo" plom
 su -lc "ln -s /home/plom/zettel /var/www-dump/zettel" plom
+# NOTE: Locally, to update content, clone zettel.git, not zettel.
 
 # Set up redo blog.
 su -lc "git clone --mirror ${old_server}:blog.git" plom
 cp "${config_tree_prefix}/other_files/blog_hook_post-receive" /home/plom/blog.git/hooks/post-receive
 su -lc "git clone ~/blog.git" plom
-# FIXME: we should not depend on a GitHub repo
+# FIXME: we should not depend on a GitHub repo;
+# instead, set up like plomlombot repo (with post-recieve hook)
 su -lc "git clone https://github.com/plomlompom/redo-blog.git" plom
 su -lc "cd redo-blog && ./add_dir.sh ~/blog" plom
 su -lc "cd blog && redo" plom
 su -lc "ln -s /home/plom/blog/public /var/www-dump/blog" plom
+# NOTE: Locally, to update content, clone blog.git, not blog.
+
+# Set up url catcher.
+su -lc "git clone https://github.com/plomlompom/url-catcher.git" plom
+# FIXME: we should not depend on a GitHub repo;
+# instead, set up like plomlombot repo (with post-recieve hook)
+su -lc "cd url-catcher && ln -s ../blog/captchas/linkable/ captchas" plom
+systemctl enable url_catcher.service
+service url_catcher startc
+# NOTE: fix metadata/article_tmpl referencing dump.plomlompom.com explicitely
 
 # Prepare NGINX.
 sed -i "s/REPLACE_fqdn_ECALPER/${domain}/g" /etc/nginx/sites-available/dumpsite.nginx
-- 
2.30.2