--- openvpn.orig/files/openvpn.sh.in Fri Jan 26 14:18:49 2007 +++ openvpn/files/openvpn.sh.in Fri Jan 26 14:16:25 2007 @@ -44,6 +44,18 @@ # file and directory where keys and certificates reside differ from the above # settings. # +# Add "openvpn_profiles" to run several instances of the openvpn with +# different parameters. Consider the following example: +# +# openvpn_enable="YES" +# openvpn_profiles="def tcp" +# openvpn_tcp_configfile="/usr/local/etc/openvpn/openvpn_tcp.conf" +# openvpn_tcp_pidfile="/var/run/openpvn_tcp.pid" +# +# This will run two instances of the openvpn with parameters taken +# from appropriate openvpn_PROFILENAME_xxx variables. For unspecified +# parameters openvpn_xxx varialbes will be used. +# # Note that we deliberately refrain from unloading drivers. # # For further documentation, please see openvpn(8). @@ -78,6 +90,36 @@ rm -f "$pidfile" || warn "Could not remove $pidfile." } +setup_profile_vars() +{ + name=openvpn_$1 + eval ": \${openvpn_${1}_configfile=${openvpn_configfile}}" + eval ": \${openvpn_${1}_dir=${openvpn_dir}}" + eval ": \${openvpn_${1}_flags=${openvpn_flags}}" + eval ": \${openvpn_${1}_pidfile=${pidfile}}" + eval "pidfile=\"\${openvpn_${1}_pidfile}\"" + eval "required_files=\"\${openvpn_${1}_configfile}\"" + eval "command_args=\"--cd \${openvpn_${1}_dir} --daemon --config \${openvpn_${1}_configfile} --writepid \${pidfile}\"" +} + +start_profiles() +{ + unset start_cmd start_precmd + for _profile in ${openvpn_profiles}; do + setup_profile_vars $_profile + run_rc_command "${rc_arg}" + done +} + +stop_profiles() +{ + unset stop_cmd + for _profile in ${openvpn_profiles}; do + setup_profile_vars $_profile + run_rc_command "${rc_arg}" + done +} + # support SIGHUP to reparse configuration file extra_commands="reload" @@ -93,11 +135,26 @@ stop_postcmd="stop_postcmd" load_rc_config ${name} + : ${openvpn_enable="NO"} : ${openvpn_flags=""} : ${openvpn_if=""} : ${openvpn_configfile="${prefix}/etc/openvpn/openvpn.conf"} : ${openvpn_dir="${prefix}/etc/openvpn"} + required_files="${openvpn_configfile}" command_args="--cd ${openvpn_dir} --daemon --config ${openvpn_configfile} --writepid ${pidfile}" -run_rc_command "$1" + +cmd="$1" +if [ $# -gt 0 ]; then + shift +fi + +[ -n "$*" ] && openvpn_profiles="$*" + +if [ "${openvpn_profiles}" ]; then + start_cmd="start_profiles" + stop_cmd="stop_profiles" +fi + +run_rc_command "$cmd"