summaryrefslogtreecommitdiff
path: root/net/openvpn/files/openvpn.sh
blob: f1d55fdb08be542d429eaa99847c598a2754ce64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!@RCD_SCRIPTS_SHELL@
#
# $NetBSD: openvpn.sh,v 1.1 2005/08/17 19:55:57 jlam Exp $
#
# PROVIDE: openvpn
# REQUIRE: NETWORKING
#
# To start openvpn at startup, copy this script to /etc/rc.d.  You will
# also need to set the following variables:
#
# openvpn=YES
#
# The following variables are optional:
#
#	openvpn_cfg="server.conf"	# whitespace-separated list of
#					# OpenVPN config files relative to
#					# directory @PKG_SYSCONFDIR@.  If
#					# set, then an openvpn process is
#					# started for each file, otherwise
#					# a process is started for all
#					# *.conf files.
#
# For information on how to write an OpenVPN config file, please read the
# openvpn(8) man page or check the website at:
#
#	http://openvpn.net/
#

. /etc/rc.subr

name="openvpn"
rcvar=$name
sysconfdir="@PKG_SYSCONFDIR@"
command="@PREFIX@/sbin/openvpn"
command_args="--cd $sysconfdir --daemon"
extra_commands="reload"
required_dirs="$sysconfdir"

start_cmd="openvpn_start"

openvpn_start()
{
	: ${openvpn_cfg="*.conf"}

	for d in $required_dirs; do
		if [ ! -d "$d/." ]; then
			warn "$d is not a directory."
			return 1
		fi
	done
	if [ -z "$openvpn_cfg" ]; then
		warn "\$openvpn_cfg is empty."
		return 1
	fi
	savewd="$PWD"
	cd $sysconfdir
	for f in $openvpn_cfg; do
		if [ ! -r "$f" ]; then
			warn "$f is not readable."
			cd $savewd
			return 1
		fi
	done
	for f in $openvpn_cfg; do
		doit="$command $command_args --config $f"
		if ! eval $doit; then
			cd $savewd
			return 1
		fi
	done
	cd $savewd
}

load_rc_config $name
run_rc_command "$1"