#!/bin/bash set -eux set -o pipefail _clear_service () { local SERVICE_NAME="${1:?_clear_service: missing argument}" systemctl stop "$SERVICE_NAME.service" 2>/dev/null || : rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.d rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME".service.{wants,requires} if [[ $SERVICE_NAME == *@ ]]; then systemctl stop "$SERVICE_NAME"*.service 2>/dev/null || : rm -f /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.d rm -fr /{etc,run,usr/lib}/systemd/system/"$SERVICE_NAME"*.service.{wants,requires} fi } clear_services () { for u in "$@"; do _clear_service "$u" done systemctl daemon-reload } create_service () { local SERVICE_NAME="${1:?create_service: missing argument}" clear_services "$SERVICE_NAME" cat >/etc/systemd/system/"$SERVICE_NAME".service </usr/lib/systemd/system/service.d/override.conf </usr/lib/systemd/system/$dropin/override.conf systemctl daemon-reload check_ok a-b-c ExecCondition "/bin/echo $dropin" done for dropin in service.d a-.service.d a-b-.service.d a-b-c.service.d; do rm -rf /usr/lib/systemd/system/$dropin done clear_services a-b-c } test_template_dropins () { echo "Testing template dropins..." create_services foo bar@ yup@ # Declare some deps to check if the body was loaded cat >>/etc/systemd/system/bar@.service <>/etc/systemd/system/yup@.service </usr/lib/systemd/system/test15-a.service.d/override.conf </usr/lib/systemd/system/test15-a.service.d/wants-b.conf<