Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #!/bin/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. #
  12. # Adjusted for openSUSE and its 'netconfig' component
  13. # using dirty tricks by multiple1902.
  14. # Omitted the 'DOMAIN' part.
  15. #
  16. # 05/2006 chlauber@bnc.ch
  17. # 01/2012 multiple1902@gmail.com
  18. #
  19. # Example envs set from openvpn:
  20. # foreign_option_1='dhcp-option DNS 193.43.27.132'
  21. # foreign_option_2='dhcp-option DNS 193.43.27.133'
  22. # foreign_option_3='dhcp-option DOMAIN be.bnc.ch'
  23.  
  24. NETCONFIG="/sbin/netconfig"
  25. CONFIGFILE="/var/run/netconfig/NetworkManager.netconfig"
  26.  
  27. case $script_type in
  28.  
  29. up)
  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. fi
  41. done
  42. cp $CONFIGFILE{,.bak}
  43. grep -v DNSSERVERS $CONFIGFILE.bak > $CONFIGFILE
  44. echo "DNSSERVERS='$IF_DNS_NAMESERVERS'" >> $CONFIGFILE
  45. $NETCONFIG update -f
  46. ;;
  47. down)
  48. cp $CONFIGFILE{.bak,}
  49. $NETCONFIG update -f
  50. ;;
  51. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement