#!/sbin/openrc-run
description="Encrypted networking for regular people."

CONFFILE=/etc/cjdroute.conf

command="/usr/sbin/cjdroute"

depend() {
	use net dns
	after precursor
}

start() {
	if [ ! -e /dev/net/tun ]; then
		ebegin "Inserting TUN module"

		if ! modprobe tun;  then
			eerror "Failed to insert TUN kernel module"
			exit 1
		fi
	fi

	ebegin "Starting CJDNS"
	start-stop-daemon --start --quiet --exec "${command}" -- < "${CONFFILE}"
	eend $?
}

stop() {
	ebegin "Stopping CJDNS"
	start-stop-daemon --stop --exec "${command}"
	eend $?
}
