# inetd output backend
# shellcheck shell=bash

export_inetd() {
	systemd_unit=$1
	base_dir=$2

	if [[ "${socket[ListenStream]:-}" ]]; then
		port="${socket[ListenStream]}"
		type="stream"
		proto="tcp"
		flags="wait"
	elif [[ "${socket[ListenDatagram]:-}" ]]; then
		port="${socket[ListenDatagram]}"
		type="dgram"
		proto="udp"
		flags="nowait"
	elif [[ "${socket[ListenSequentialPackets]:-}" ]]; then
	     	echo "Sequential Packets not supported by inetd backend" >&2
		exit 1
	fi
	# <service_name> <sock_type> <proto> <flags> <user> <server_path> <args>
	printf 'Run "update-inetd --add '
	printf "'%s %s %s %s %s %s %s'\n" "$port" "$type" "$proto" "$flags" "${service[User]:-root}" "${service[ExecStart]// */}" "${service[ExecStart]#* }"
}
