From fad2cbc26effbede0b192a43fefa9298d0cc86c3 Mon Sep 17 00:00:00 2001
From: Sergio Talens-Oliag <sto@mixinet.net>
Date: Sat, 15 Mar 2025 10:33:28 +0100
Subject: [PATCH] feat(remark42): initial image

---
 remark42/Dockerfile |  2 ++
 remark42/init.sh    | 42 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100644 remark42/Dockerfile
 create mode 100755 remark42/init.sh

diff --git a/remark42/Dockerfile b/remark42/Dockerfile
new file mode 100644
index 0000000..a4d0af0
--- /dev/null
+++ b/remark42/Dockerfile
@@ -0,0 +1,2 @@
+FROM umputun/remark42:v1.14.0
+COPY init.sh /init.sh
diff --git a/remark42/init.sh b/remark42/init.sh
new file mode 100755
index 0000000..cbecca3
--- /dev/null
+++ b/remark42/init.sh
@@ -0,0 +1,42 @@
+#!/sbin/dinit /bin/sh
+
+uid="$(id -u)"
+
+if [ "${uid}" -eq "0" ]; then
+  echo "init container"
+
+  # set container's time zone
+  cp "/usr/share/zoneinfo/${TIME_ZONE}" /etc/localtime
+  echo "${TIME_ZONE}" >/etc/timezone
+  echo "set timezone ${TIME_ZONE} ($(date))"
+
+  # set UID & GID for the app
+  if [ "${APP_UID}" ] || [ "${APP_GID}" ]; then
+    [ "${APP_UID}" ] || APP_UID="1001"
+    [ "${APP_GID}" ] || APP_GID="${APP_UID}"
+    echo "set custom APP_UID=${APP_UID} & APP_GID=${APP_GID}"
+    sed -i "s/^app:x:1001:1001:/app:x:${APP_UID}:${APP_GID}:/" /etc/passwd
+    sed -i "s/^app:x:1001:/app:x:${APP_GID}:/" /etc/group
+  else
+    echo "custom APP_UID and/or APP_GID not defined, using 1001:1001"
+  fi
+  chown -R app:app /srv /home/app
+fi
+
+echo "prepare environment"
+
+# replace {% REMARK_URL %} by content of REMARK_URL variable
+find /srv -regex '.*\.\(html\|js\|mjs\)$' -print \
+  -exec sed -i "s|{% REMARK_URL %}|${REMARK_URL}|g" {} \;
+
+if [ -n "${SITE_ID}" ]; then
+  #replace "site_id: 'remark'" by SITE_ID
+  sed -i "s|'remark'|'${SITE_ID}'|g" /srv/web/*.html
+fi
+
+echo "execute \"$*\""
+if [ "${uid}" -eq "0" ]; then
+  exec su-exec app "$@"
+else
+  exec "$@"
+fi