1#!/bin/sh
2#
3# $NetBSD: rtadvd,v 1.11 2020/07/04 06:24:53 skrll Exp $
4#
5
6# PROVIDE: rtadvd
7# REQUIRE: DAEMON
8# BEFORE:  LOGIN
9
10$_rc_subr_loaded . /etc/rc.subr
11
12name=rtadvd
13rcvar=$name
14command="/usr/sbin/$name"
15pidfile="/var/run/$name.pid"
16extra_commands=reload
17start_precmd=rtadvd_prestart
18reload_precmd=rtadvd_prereload
19
20rtadvd_prereload()
21{
22	local chdir="$(getent passwd _rtadvd | cut -d: -f6)"
23	local conf=/etc/rtadvd.conf myflags o confdir
24	local cflag=false
25
26	[ -z "${chdir}" ] || [ "/${chdir}" = // ] && return 0
27
28	if [ -n "${flags}" ]; then
29		myflags=${flags}
30	else
31		eval myflags=\$${name}_flags
32	fi
33	set -- ${myflags}
34	while getopts c:dDfM:Rs o; do
35		# ignore other args, they are processed by rtadvd itself
36		case "${o}" in
37		c)	conf="${OPTARG}"
38			case "${conf}" in
39			/*)	;;
40			*)	echo "${name}: config file (${conf}) must be" \
41					"full pathname"
42				return 1
43				;;
44			esac
45			cflag=true;;
46		esac
47	done
48
49	${cflag} || test -f "${conf}" && {
50		confdir=$(dirname "${conf}")
51		echo "${name}: copying ${conf} to ${chdir}${conf}"
52		mkdir -p "${chdir}${confdir}"
53		cp "${conf}" "${chdir}${conf}" || return 1
54	}
55
56	# Make sure /var/run exists in the chroot
57	mkdir -p "${chdir}/var/run"
58
59	# Provide a link to the chrooted dump file
60	ln -snf "${chdir}/var/run/${name}.dump" /var/run
61
62	# Note: actual chroot is done by rtadvd itself
63
64	return 0
65}
66
67rtadvd_prestart()
68{
69	if [ "$ip6mode" != router ]; then
70		warn \
71	"${name} cannot be used on IPv6 host, only on an IPv6 router."
72		return 1
73	fi
74
75	rtadvd_prereload
76}
77
78load_rc_config $name
79run_rc_command "$1"
80