[Unit]
Description=static importer

# Dependency ordering
Before=static-git@%i.service
Before=backup@%i.timer

[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; \
  git_folder=/data/runtime/domains/%i/static-git; \
  if [ ! -d $git_folder/www-content/.git ]; then \
    mkdir -p $git_folder; \
    git clone `cat /data/domains/%i/static-git/GITURL` $git_folder/www-content; \
  fi;'

[Install]
WantedBy=static-git@%i.service
