[Unit]
Description=WordPress importer

# Dependency ordering
After=mysql@%i.service
Before=known@%i.service
Before=backup@%i.timer

# Dependency binding
BindsTo=known@%i.service

[Service]
Type=oneshot
RemainAfterExit=yes
Environment=DOMAIN=%i
ExecStartPre=/data/indiehosters/scripts/backup-init.sh
ExecStartPre=/data/indiehosters/scripts/import.sh
ExecStart=/bin/bash -euxc ' \
  cp /data/domains/%i/TLS/%i.pem /data/runtime/haproxy/approved-certs/%i.pem; \
  known_folder=/data/domains/%i/known; \
  if [ ! -d $known_folder/known-content ]; then \
    mkdir -p $known_folder; \
    cd $known_folder; \
    tar xvzf /data/indiehosters/blueprints/known-0.6.5.tgz; \
    touch .htaccess; \
  fi; \
  cat /data/domains/%i/mysql/.env | sed s/MYSQL_PASS/DB_PASS/ > $known_folder/.env'

[Install]
WantedBy=known@%i.service
