#!/bin/sh
# deb-systemd-invoke for s6-rc: passes the action for each unit to
# invoke-rc.d, which asks policy-rc.d and calls svctl.
set -u

usage() {
	cat >&2 <<'USAGE'
Usage: deb-systemd-invoke [--user] [--no-dbus] <action> <unit> [<unit> ...]

Runs invoke-rc.d <unit> <action> for each unit, NAME.service as NAME.
Meant for dpkg maintainer scripts.
USAGE
}

while [ $# -gt 0 ]; do
	case $1 in
	--user | --no-dbus) ;;
	-h | --help) usage; exit 0 ;;
	--) shift; break ;;
	-*) ;;
	*) break ;;
	esac
	shift
done
[ $# -ge 2 ] || { usage; exit 1; }
action=$1
shift
rc=0
for unit in "$@"; do
	invoke-rc.d "${unit%.service}" "$action" || rc=$?
done
exit "$rc"
