summaryrefslogtreecommitdiff
path: root/bin/.bin/update-resolv-conf.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/.bin/update-resolv-conf.sh')
-rwxr-xr-xbin/.bin/update-resolv-conf.sh71
1 files changed, 71 insertions, 0 deletions
diff --git a/bin/.bin/update-resolv-conf.sh b/bin/.bin/update-resolv-conf.sh
new file mode 100755
index 0000000..16622a1
--- /dev/null
+++ b/bin/.bin/update-resolv-conf.sh
@@ -0,0 +1,71 @@
1#!/usr/bin/env bash
2#
3# Parses DHCP options from openvpn to update resolv.conf
4# To use set as 'up' and 'down' script in your openvpn *.conf:
5# up /etc/openvpn/update-resolv-conf
6# down /etc/openvpn/update-resolv-conf
7#
8# Used snippets of resolvconf script by Thomas Hood <jdthood@yahoo.co.uk>
9# and Chris Hanson
10# Licensed under the GNU GPL. See /usr/share/common-licenses/GPL.
11# 07/2013 colin@daedrum.net Fixed intet name
12# 05/2006 chlauber@bnc.ch
13#
14# Example envs set from openvpn:
15# foreign_option_1='dhcp-option DNS 193.43.27.132'
16# foreign_option_2='dhcp-option DNS 193.43.27.133'
17# foreign_option_3='dhcp-option DOMAIN be.bnc.ch'
18# foreign_option_4='dhcp-option DOMAIN-SEARCH bnc.local'
19
20## The 'type' builtins will look for file in $PATH variable, so we set the
21## PATH below. You might need to directly set the path to 'resolvconf'
22## manually if it still doesn't work, i.e.
23## RESOLVCONF=/usr/sbin/resolvconf
24export PATH=$PATH:/sbin:/usr/sbin:/bin:/usr/bin
25RESOLVCONF=$(type -p resolvconf)
26
27case $script_type in
28
29up)
30 for optionname in ${!foreign_option_*} ; do
31 option="${!optionname}"
32 echo $option
33 part1=$(echo "$option" | cut -d " " -f 1)
34 if [ "$part1" == "dhcp-option" ] ; then
35 part2=$(echo "$option" | cut -d " " -f 2)
36 part3=$(echo "$option" | cut -d " " -f 3)
37 if [ "$part2" == "DNS" ] ; then
38 IF_DNS_NAMESERVERS="$IF_DNS_NAMESERVERS $part3"
39 fi
40 if [[ "$part2" == "DOMAIN" || "$part2" == "DOMAIN-SEARCH" ]] ; then
41 IF_DNS_SEARCH="$IF_DNS_SEARCH $part3"
42 fi
43 fi
44 done
45 R=""
46 if [ "$IF_DNS_SEARCH" ]; then
47 R="search "
48 for DS in $IF_DNS_SEARCH ; do
49 R="${R} $DS"
50 done
51 R="${R}
52"
53 fi
54
55 for NS in $IF_DNS_NAMESERVERS ; do
56 R="${R}nameserver $NS
57"
58 done
59 #echo -n "$R" | $RESOLVCONF -x -p -a "${dev}"
60 echo -n "$R" | $RESOLVCONF -x -a "${dev}.inet"
61 ;;
62down)
63 $RESOLVCONF -d "${dev}.inet"
64 ;;
65esac
66
67# Workaround / jm@epiclabs.io
68# force exit with no errors. Due to an apparent conflict with the Network Manager
69# $RESOLVCONF sometimes exits with error code 6 even though it has performed the
70# action correctly and OpenVPN shuts down.
71exit 0