Set (sub)domain name via environment
diff --git a/.gitignore b/.gitignore
index 68973c5..6e6928b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
+/environment
 /gerrit/environment
 /gerrit/cache/
 /gerrit/db/
diff --git a/TODO.on.site b/TODO.on.site
index 39983d4..3c680a9 100644
--- a/TODO.on.site
+++ b/TODO.on.site
@@ -5,9 +5,7 @@
 * docker-compose -f sourcearcade.yml build --build-arg SELFSIGNED_REQ_HOST=hostname
   - same build-args!
 
-Adapt checked in files:
-* Set server_name in `nginx/sa.conf`
-* Set SIMPLEID_BASE_URL in `simpleid/www/config.php`
-* Make sure identities point to the right URL
+Create environment files (cf. `git ls-files \*environment.template`):
+* Set SA_PUBLIC_DOMAIN_NAME in `environment`
 * Set CANONICAL_WEB_URL in `gerrit/environment`
 * Enable GitHub OAUTH in `gerrit/environment`
diff --git a/environment.template b/environment.template
new file mode 100644
index 0000000..b435fa5
--- /dev/null
+++ b/environment.template
@@ -0,0 +1,2 @@
+# Set to public (sub)domain name
+SA_PUBLIC_DOMAIN_NAME=miau.local
diff --git a/nginx/Dockerfile b/nginx/Dockerfile
index 18cbc8e..9809c58 100644
--- a/nginx/Dockerfile
+++ b/nginx/Dockerfile
@@ -23,3 +23,9 @@
 
 
 FROM nginx_${SSL_VARIANT}
+
+COPY nginx/Dockerfile.entrypoint /nginx-entrypoint
+RUN chmod 544 /nginx-entrypoint
+
+ENTRYPOINT ["/bin/sh", "/nginx-entrypoint"]
+CMD ["nginx", "-g", "daemon off;"]
diff --git a/nginx/Dockerfile.entrypoint b/nginx/Dockerfile.entrypoint
new file mode 100644
index 0000000..0c2ff96
--- /dev/null
+++ b/nginx/Dockerfile.entrypoint
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+set -e
+
+{
+    domain=${SA_PUBLIC_DOMAIN_NAME:-miau.local}
+    html=/var/www/html
+
+    rm -rf ${html}
+    cp -a /var/www/simpleid ${html}
+
+    for tmpl in /var/db/simpleid-templates/*.identity; do
+        ref=$(dirname ${tmpl})/$(basename ${tmpl} .identity)
+        name=$(basename ${ref})
+        sed "s/miau.local/${domain}/" ${ref} >${html}/${name}
+    done
+
+    for f in /etc/nginx/conf.d/sa.conf; do
+        sed "s/miau.local/${domain}/" ${f}.template >${f}
+    done
+}
+
+chown -R nginx:nginx /var/www/html/
+
+chmod -R a-w /etc/nginx/conf.d/sa.conf /var/www/html/
+
+exec /docker-entrypoint.sh "$@"
diff --git a/simpleid/Dockerfile.entrypoint b/simpleid/Dockerfile.entrypoint
index f98185b..fd85408 100644
--- a/simpleid/Dockerfile.entrypoint
+++ b/simpleid/Dockerfile.entrypoint
@@ -2,8 +2,31 @@
 
 set -e
 
+{
+    domain=${SA_PUBLIC_DOMAIN_NAME:-miau.local}
+    ids=/var/db/simpleid
+    html=/var/www/html
+
+    mkdir -p ${ids}
+    rm -rf ${html}
+    cp -a /var/www/simpleid ${html}
+
+    for tmpl in /var/db/simpleid-templates/*.identity; do
+        id=$(basename ${tmpl})
+        sed "s/miau.local/${domain}/" ${tmpl} >${ids}/${id}
+    done
+
+    for f in /var/www/simpleid/config.php; do
+        sed "s/miau.local/${domain}/" ${f} >${html}/$(basename ${f})
+    done
+}
+
 chown -R www-data:www-data /var/cache/simpleid/
 chown -R www-data:www-data /var/lib/simpleid/
+chown -R www-data:www-data /var/db/simpleid/
+chown -R www-data:www-data /var/www/html/
 chown -R www-data:www-data /var/log/
 
+chmod -R a-w /var/db/simpleid/ /var/www/html/
+
 exec docker-php-entrypoint php-fpm "$@"
diff --git a/simpleid/www/icon b/simpleid/identities/icon
similarity index 100%
rename from simpleid/www/icon
rename to simpleid/identities/icon
diff --git a/sourcearcade.yml b/sourcearcade.yml
index ffb1279..6d91d78 100644
--- a/sourcearcade.yml
+++ b/sourcearcade.yml
@@ -4,6 +4,7 @@
     build:
       context: .
       dockerfile: nginx/Dockerfile
+    env_file: environment
     ports:
       - "80:80"
       - "443:443"
@@ -11,24 +12,23 @@
       - simpleidnet
       - gerritnet
     volumes:
-      - ./simpleid/cache/:/var/cache/simpleid/:ro
-      - ./simpleid/identities/:/var/db/simpleid/:ro
-      - ./simpleid/store/:/var/lib/simpleid/:ro
-      - ./simpleid/www/:/var/www/html/:ro
-      - ./nginx/sa.conf:/etc/nginx/conf.d/sa.conf:ro
+      - ./simpleid/identities/:/var/db/simpleid-templates/:ro
+      - ./simpleid/www/:/var/www/simpleid/:ro
+      - ./nginx/sa.conf:/etc/nginx/conf.d/sa.conf.template:ro
       - ./nginx/empty.conf:/etc/nginx/conf.d/default.conf:ro
       - ./logs/nginx:/var/log/nginx/:rw
   simpleid:
     build:
       context: .
       dockerfile: simpleid/Dockerfile
+    env_file: environment
     networks:
       - simpleidnet
     volumes:
       - ./simpleid/cache/:/var/cache/simpleid/:rw
-      - ./simpleid/identities/:/var/db/simpleid/:ro
+      - ./simpleid/identities/:/var/db/simpleid-templates/:ro
       - ./simpleid/store/:/var/lib/simpleid/:rw
-      - ./simpleid/www/:/var/www/html/:ro
+      - ./simpleid/www/:/var/www/simpleid/:ro
       - ./logs/simpleid/:/var/log/:rw
   gerrit:
     build: