updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / netcfg-openvpn / openvpn
blobe5f78513b013e77c9dc4eca8fa89b1c6eab82ba3
1 #! /bin/bash
2 . /usr/lib/network/network
4 openvpn_up() {
5 load_profile $1
6 [[ -z "$OVPN_CONFIG" ]] && OVPN_CONFIG="/etc/openvpn/openvpn.conf"
7 [[ -z "$OVPN_PID_FILE" ]] && OVPN_PID_FILE="/var/run/openvpn-$1.pid"
8 [[ -z "$OVPN_FLAGS" ]] && OVPN_FLAGS=""
10 OVPN_CONF_DIR="`dirname $OVPN_CONFIG`"
11 OVPN_CONF_FILE="`basename $OVPN_CONFIG`"
13 /usr/sbin/openvpn --writepid $OVPN_PID_FILE --daemon --cd "$OVPN_CONF_DIR" --config "$OVPN_CONF_FILE" $OVPN_FLAGS
15 if [[ $? -ne 0 ]]; then
16 report_fail "OpenVPN connection failed"
17 exit 1
20 # Generate a new resolv.conf
21 if [[ -n "$DNS" ]]; then
22 [[ -e /etc/resolv.conf ]] && cp /etc/resolv.conf /tmp/openvpn-$1-resolv.conf
23 : >/etc/resolv.conf
24 [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf
25 [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf
27 for dns in "${DNS[@]}"; do
28 echo "nameserver $dns" >>/etc/resolv.conf
29 done
30 elif [[ -n "$DNS1" ]]; then # support older 'ethernet' syntax.
31 [[ -e /etc/resolv.conf ]] && cp /etc/resolv.conf /tmp/openvpn-$1-resolv.conf
32 : >/etc/resolv.conf
33 [[ -n "$DOMAIN" ]] && echo "domain $DOMAIN" >>/etc/resolv.conf
34 [[ -n "$SEARCH" ]] && echo "search $SEARCH" >>/etc/resolv.conf
35 [[ -n "$DNS1" ]] && echo "nameserver $DNS1" >>/etc/resolv.conf
36 [[ -n "$DNS2" ]] && echo "nameserver $DNS2" >>/etc/resolv.conf
40 openvpn_down() {
41 load_profile $1
42 [[ -z "$OVPN_PID_FILE" ]] && OVPN_PID_FILE="/var/run/openvpn-$1.pid"
44 kill $(head -1 $OVPN_PID_FILE)
45 rm $OVPN_PID_FILE
47 # Restore an old resolv.conf
48 if [[ -e /tmp/openvpn-$1-resolv.conf ]]; then
49 mv -f /tmp/openvpn-$1-resolv.conf /etc/resolv.conf
53 openvpn_$1 $2
54 exit $?
55 # vim: set ts=4 et sw=4: