#!/bin/sh
set -e
if type systemctl >/dev/null 2>/dev/null; then
	OPTS=""

	if [ -n "$D" ]; then
		OPTS="--root=$D"
	fi

	if [ "enable" = "enable" ]; then
		for service in connman-wait-online.service; do
			systemctl ${OPTS} enable "$service"
		done

		for service in ; do
			systemctl --global ${OPTS} enable "$service"
		done
	fi

	if [ -z "$D" ] && systemctl >/dev/null 2>/dev/null; then
		# Reload only system service manager
		# --global for daemon-reload is not supported: https://github.com/systemd/systemd/issues/19284
		systemctl daemon-reload
		[ -n "connman-wait-online.service" ] && \
			systemctl preset connman-wait-online.service

		[ -n "" ] && \
			systemctl --global preset 

		if [ "enable" = "enable" ]; then
			# --global flag for restart is not supported by systemd (see above)
			[ -n "connman-wait-online.service" ] && \
				systemctl --no-block restart connman-wait-online.service
		fi
	fi
fi
