File: openvpn-generator

package info (click to toggle)
openvpn 2.6.3-1%2Bdeb12u3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 11,340 kB
  • sloc: ansic: 97,644; sh: 5,801; makefile: 791; python: 203; javascript: 73; perl: 66
file content (40 lines) | stat: -rwxr-xr-x 899 bytes parent folder | download | duplicates (9)
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
#!/bin/sh

# This systemd generator creates dependency symlinks that make all OpenVPN
# tunnels listed in /etc/default/openvpn's AUTOSTART be started/stopped/reloaded
# when openvpn.service is started/stopped/reloaded.

set -eu

GENDIR="$1"
WANTDIR="$1/openvpn.service.wants"
SERVICEFILE="/lib/systemd/system/openvpn@.service"
AUTOSTART="all"
CONFIG_DIR=/etc/openvpn

mkdir -p "$WANTDIR"

if test -e /etc/default/openvpn ; then
	. /etc/default/openvpn
fi

# No VPNs automatically started
if test "x$AUTOSTART" = "xnone" ; then
	exit 0
fi

if test "x$AUTOSTART" = "xall" -o -z "$AUTOSTART" ; then
	for CONFIG in `cd $CONFIG_DIR; ls *.conf 2> /dev/null`; do
		NAME=${CONFIG%%.conf}
		ln -s "$SERVICEFILE" "$WANTDIR/openvpn@$NAME.service"
	done
else
	for NAME in $AUTOSTART ; do
		if test -e $CONFIG_DIR/$NAME.conf ; then
			ln -s "$SERVICEFILE" "$WANTDIR/openvpn@$NAME.service"
		fi
	done
fi

exit 0