#!/bin/bash

help() {
  >&2 echo '
s6 compatibility script of:

Syntax: /usr/bin/deb-systemd-invoke <action> <unit file> [<unit file> ...]
'
}

# discard all option parameters
while [[ $1 =~ ^- ]]; do
  if [ "$1" = '--help' ] || [ "$1" = '-h' ]; then
    help
    exit 0
  fi
  shift
done

# need at least 2 non-option arguments (service name and action)
if [ $# -lt 2 ]; then
  help
  exit 1
fi

# forward all types of actions to invoke-rc.d
exec invoke-rc.d "$2" "${1%.service}"
