#!/sbin/openrc-run

description="VPN proxy"

depend()
{
	before net
}

start()
{
	[ "$(mobyplatform)" != "windows" ] && exit 0

	mobyconfig exists network || exit 0
	NETWORK_MODE="$(mobyconfig get network | tr -d '[[:space:]]')"
	[ "${NETWORK_MODE}" = "hybrid" ] || exit 0

	ebegin "Starting VPN proxy"

	PIDFILE=/var/run/tap-vsockd.pid
	start-stop-daemon --start \
		--exec /sbin/tap-vsockd \
		--background \
		--pidfile ${PIDFILE} \
		-- \
		--tap eth0 \
		--pidfile "${PIDFILE}" \
		--listen

	eend $? "Failed to start VPN proxy"
}

stop()
{
	[ "$(mobyplatform)" != "windows" ] && exit 0

	ebegin "Stopping VPN proxy"

	PIDFILE=/var/run/tap-vsockd.pid

	start-stop-daemon --stop --quiet \
		--pidfile "${PIDFILE}"

	eend $? "Failed to stop VPN proxy"
}
