Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 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 and Chris Hanson.
  9. # Licensed under the GNU GPL. See /usr/share/common-licenses/GPL.
  10. #
  11. # Example envs set from openvpn:
  12. #
  13. # foreign_option_1='dhcp-option DNS 193.43.27.132'
  14. # foreign_option_2='dhcp-option DNS 193.43.27.133'
  15. # foreign_option_3='dhcp-option DOMAIN be.bnc.ch'
  16. #
  17. #
  18. #
  19. # This script has been edited by Ntrepid Corp. and is available for public use.
  20. # The script was found in the openvpn debian package.
  21. #
  22.  
  23.  
  24. # exit on errors
  25. set -eEuo pipefail
  26. trap 'st=$?;set +x;env;echo "*** SCRIPT FAILED *** (line ${LINENO}): \"${BASH_COMMAND}\" exited with code ${st}"' ERR
  27.  
  28. [ "$script_type" ] || exit 1
  29.  
  30. split_into_parts()
  31. {
  32. part1="$1"
  33. part2="$2"
  34. part3="$3"
  35. }
  36.  
  37. case "$script_type" in
  38. up)
  39. NMSRVRS=""
  40. SRCHS=""
  41. for optionvarname in ${!foreign_option_*} ; do
  42. option="${!optionvarname}"
  43. echo "$option"
  44. split_into_parts $option
  45. if [ "$part1" = "dhcp-option" ] ; then
  46. if [ "$part2" = "DNS" ] ; then
  47. NMSRVRS="${NMSRVRS:+$NMSRVRS }$part3"
  48. elif [ "$part2" = "DOMAIN" ] ; then
  49. SRCHS="${SRCHS:+$SRCHS }$part3"
  50. fi
  51. fi
  52. done
  53. R=""
  54. [ "$SRCHS" ] && R="search $SRCHS
  55. "
  56. for NS in $NMSRVRS ; do
  57. R="${R}nameserver $NS
  58. "
  59. done
  60.  
  61. # save off resolv.conf and replace it with our own
  62. mv -f /etc/resolv.conf /etc/openvpn/resolv.conf.bak
  63. echo -n "$R" > /etc/resolv.conf
  64. chmod 777 /etc/resolv.conf
  65.  
  66. ;;
  67. down)
  68. # restore the resolv.conf we saved off
  69. mv -f /etc/openvpn/resolv.conf.bak /etc/resolv.conf
  70. ;;
  71. esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement