github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/bin/package/config/linux/update-resolv-conf (about) 1 #!/bin/bash 2 # 3 # Parses DHCP options from passed through ENV to update resolv.conf 4 # Called from myst node binary 5 # 6 # Script adapted from update-resolv-conf script provided by Openvpn project. 7 # Licensed under the GNU GPL. See /usr/share/common-licenses/GPL. 8 # 9 # Used snippets of resolvconf script by Thomas Hood and Chris Hanson. 10 # Licensed under the GNU GPL. See /usr/share/common-licenses/GPL. 11 # 12 # Example envs set from openvpn: 13 # 14 # foreign_option_1='dhcp-option DNS 193.43.27.132' 15 # foreign_option_2='dhcp-option DNS 193.43.27.133' 16 # foreign_option_3='dhcp-option DOMAIN be.bnc.ch' 17 # 18 19 RESOLVCONFBIN=$(command -v resolvconf) 20 21 if ! [ -x "$RESOLVCONFBIN" ]; then 22 echo "ERROR: resolvconf not found, DNS will not be updated" 23 exit 0 24 fi 25 [ "$script_type" ] || exit 0 26 [ "$dev" ] || exit 0 27 28 split_into_parts() 29 { 30 part1="$1" 31 part2="$2" 32 part3="$3" 33 } 34 35 case "$script_type" in 36 up) 37 NMSRVRS="" 38 SRCHS="" 39 for optionvarname in ${!foreign_option_*} ; do 40 option="${!optionvarname}" 41 echo "$option" 42 split_into_parts $option 43 if [ "$part1" = "dhcp-option" ] ; then 44 if [ "$part2" = "DNS" ] ; then 45 NMSRVRS="${NMSRVRS:+$NMSRVRS }$part3" 46 elif [ "$part2" = "DOMAIN" ] ; then 47 SRCHS="${SRCHS:+$SRCHS }$part3" 48 fi 49 fi 50 done 51 R="" 52 [ "$SRCHS" ] && R="search $SRCHS\n" 53 54 for NS in $NMSRVRS ; do 55 R="${R}nameserver $NS\n" 56 done 57 echo -e -n "$R" | sudo $RESOLVCONFBIN -a "${dev}" 58 ;; 59 down) 60 sudo $RESOLVCONFBIN -d "${dev}" 61 ;; 62 esac