#!/bin/sh
set -e
	update-alternatives --install /usr/sbin/klogd klogd /usr/bin/busybox.nosuid 50
	update-alternatives --install /usr/sbin/syslogd syslogd /usr/bin/busybox.nosuid 50
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 busybox-syslog.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 "busybox-syslog.service" ] && \
			systemctl preset busybox-syslog.service

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

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