1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2008-2013 OpenWrt.org
3 # Copyright (C) 2008 Jo-Philipp Wich
4 # This is free software, licensed under the GNU General Public License v2.
5 # See /LICENSE for more information.
11 PROG=/usr/sbin/openvpn
23 *_*_*_*) v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
24 *_*_*) v=${v%%_*}-${v#*_}; v=${v%%_*}-${v#*_} ;;
25 *_*) v=${v%%_*}-${v#*_} ;;
27 echo -n "$v" >> "/var/etc/openvpn-$s.conf"
32 local p; local v; local s="$1"; shift
34 config_get_bool v "$s" "$p"
35 [ "$v" = 1 ] && append_param "$s" "$p" && echo >> "/var/etc/openvpn-$s.conf"
40 local p; local v; local s="$1"; shift
42 config_get v "$s" "$p"
45 [ -n "$v" ] && [ "$p" != "push" ] && append_param "$s" "$p" && echo " $v" >> "/var/etc/openvpn-$s.conf"
46 [ -n "$v" ] && [ "$p" == "push" ] && append_param "$s" "$p" && echo " \"$v\"" >> "/var/etc/openvpn-$s.conf"
53 config_get_bool enable "$1" 'enable' 0
54 config_get_bool enabled "$1" 'enabled' 0
55 [ $enable -gt 0 ] || [ $enabled -gt 0 ]
58 openvpn_add_instance() {
64 procd_set_param command "$PROG" \
65 --syslog "openvpn($name)" \
66 --status "/var/run/openvpn.$name.status" \
69 procd_set_param file "$dir/$conf"
70 procd_set_param respawn
77 config_get config "$s" config
78 config="${config:+$(readlink -f "$config")}"
80 section_enabled "$s" || {
81 append UCI_DISABLED "$config" "$LIST_SEP"
85 [ ! -d "/var/run" ] && mkdir -p "/var/run"
87 if [ ! -z "$config" ]; then
88 append UCI_STARTED "$config" "$LIST_SEP"
89 openvpn_add_instance "$s" "${config%/*}" "$config"
93 [ ! -d "/var/etc" ] && mkdir -p "/var/etc"
94 [ -f "/var/etc/openvpn-$s.conf" ] && rm "/var/etc/openvpn-$s.conf"
96 append_bools "$s" $OPENVPN_BOOLS
97 append_params "$s" $OPENVPN_PARAMS
99 openvpn_add_instance "$s" "/var/etc" "openvpn-$s.conf"
103 . /usr/share/openvpn/openvpn.options
104 config_load 'openvpn'
105 config_foreach start_instance 'openvpn'
108 for path in /etc/openvpn/*.conf; do
109 if [ -f "$path" ]; then
110 name="${path##*/}"; name="${name%.conf}"
112 # don't start configs again that are already started by uci
113 if echo "$UCI_STARTED" | grep -qxF "$path"; then
116 # don't start configs which are set to disabled in uci
117 elif echo "$UCI_DISABLED" | grep -qxF "$path"; then
118 logger -t openvpn "$name.conf is disabled in /etc/config/openvpn"
122 openvpn_add_instance "$name" "${path%/*}" "$path"
128 procd_add_reload_trigger openvpn