#!/bin/sh

case "${0}" in
	/etc/network/if-*.d/*) ;;
	*) exit 1;;
esac
if [ "x${IFACE}" = 'x' ]; then
	exit 1
fi

get_iface_opts()
{
	local opt_cb="${1}"
	local script=
	local opts=
	local opt=

	script="$(printf '
		/^iface[ \\t][ \\t]*%s/,/^[^ \\t]/{
			/^$/q;
			s/^[ \\t][ \\t]*//p;
		}
		' "${IFACE}")"

	opts="$(sed -n "${script}" /var/run/net-ifaces)"
	if [ "x${opts}" = 'x' ]; then
		return 0
	fi

	while read -r opt; do
		${opt_cb} ${opt}
	done <<-EOF
		${opts}
		EOF

	return 0
}