set -e
if false; then
cat >> $D/etc/network/interfaces << EOF

auto lxcbr0
iface lxcbr0 inet dhcp
	bridge_ports eth0
	bridge_fd 0
	bridge_maxwait 0
EOF

cat<<EOF>$D/etc/network/if-pre-up.d/lxcbr0
#! /bin/sh

if test "x\$IFACE" = xlxcbr0 ; then
        brctl show |grep lxcbr0 > /dev/null 2>/dev/null
        if [ \$? != 0 ] ; then
                brctl addbr lxcbr0
                brctl addif lxcbr0 eth0
                ip addr flush eth0
                ifconfig eth0 up
        fi
fi
EOF
chmod 755 $D/etc/network/if-pre-up.d/lxcbr0
fi
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 lxc-net.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 "lxc-net.service" ] && \
			systemctl preset lxc-net.service

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

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