#!/usr/bin/sh

set -e
set -u

if [ -d '/run/systemd/system' ]; then
  /usr/bin/systemctl --system daemon-reload > '/dev/null' 2>&1 || \
    /usr/bin/true
fi

case "${1}" in
  configure)
    if [ -x '/usr/bin/deb-systemd-helper' ]; then
      /usr/bin/deb-systemd-helper unmask 'act_runner.service' > '/dev/null' 2>&1 || \
        /usr/bin/true
    fi
    if /usr/bin/deb-systemd-helper --quiet was-enabled 'act_runner.service'; then
      /usr/bin/deb-systemd-helper enable 'act_runner.service' > '/dev/null' 2>&1 || \
        /usr/bin/true
    else
      /usr/bin/deb-systemd-helper update-state 'act_runner.service' > '/dev/null' 2>&1 || \
        /usr/bin/true
    fi
    if [ -x '/etc/init.d/traefik-certs-dumper' ]; then
      /usr/sbin/update-rc.d 'act_runner' defaults > '/dev/null' 2>&1 || \
        /usr/bin/true
    fi
    /usr/bin/touch '/etc/act_runner/act_runner.env'
    /usr/bin/chown --quiet --recursive 'git':'root' '/etc/act_runner'
    /usr/bin/chown --quiet 'git':'git' '/var/cache/act_runner'
    /usr/bin/chown --quiet 'git':'git' '/var/lib/act_runner'
  ;;
esac
