openvpn-config-clean.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. #!/bin/bash
  2. # convert dos to unix
  3. /etc/scripts/dos2unix.sh "${1}";
  4. # Remove up/down resolv-conf script calls (Mullvad)
  5. sed -i "/update-resolv-conf/d" "${1}"
  6. # if 'proto' is old format 'tcp' then replace with newer 'tcp-client' format
  7. sed -i "s/^proto\stcp$/proto tcp-client/g" "${1}"
  8. # remove persist-tun from ovpn file if present, this allows reconnection to tunnel on disconnect
  9. #sed -i '/^persist-tun/d' "${1}"
  10. # remove reneg-sec from ovpn file if present, this is removed to prevent re-checks and dropouts
  11. sed -i '/^reneg-sec.*/d' "${1}"
  12. # remove windows specific openvpn options
  13. sed -i '/^route-method exe/d' "${1}"
  14. sed -i '/^service\s.*/d' "${1}"
  15. sed -i '/^block-outside-dns/d' "${1}"
  16. VPN_DEVICE_TYPE=$(cat "${1}" | grep -P -o -m 1 '(?<=^dev\s)[^\r\n\d]+' | sed -e 's~^[ \t]*~~;s~[ \t]*$~~')
  17. if [[ ! -z "${VPN_DEVICE_TYPE}" ]]; then
  18. # forcibly set virtual network device to 'tun0/tap0'
  19. sed -i "s/^dev\s${VPN_DEVICE_TYPE}.*/dev ${VPN_DEVICE_TYPE}/g" "${1}"
  20. else
  21. echo "VPN_DEVICE_TYPE not found in ${1}, deleting file"
  22. rm "${1}" && exit 1
  23. fi