#!/bin/sh

for IPV4 in $(find /tmp -type f -name "newwanip_*"); do
	INTERFACE=$(cat "${IPV4}")
	rm "${IPV4}"

	echo "Reconfiguring IPv4 on ${INTERFACE}"
	configctl -dq interface newip ${INTERFACE} force
done

for IPV6 in $(find /tmp -type f -name "newwanipv6_*"); do
	INTERFACE=$(cat "${IPV6}")
	rm "${IPV6}"

	echo "Reconfiguring IPv6 on ${INTERFACE}"
	configctl -dq interface newipv6 ${INTERFACE} force
done

for PPP in $(find /tmp -type f -name "pppconfigure_*"); do
	INTERFACE=$(cat "${PPP}")
	rm "${PPP}"

	# Dailing is not the same as e.g. dhclient already
	# running in the backgound for the above so do the
	# main connectivity part synchronously (no -d).

	echo "Dialing PPP on ${INTERFACE}"
	configctl -q interface ppp configure ${INTERFACE}
done
