From 51a7c6fdeb4c46ca42d79ceb9b0e65ad0f5f5102 Mon Sep 17 00:00:00 2001 From: Garret Premo Date: Thu, 19 Dec 2024 10:10:13 -0500 Subject: [PATCH] fix: openvpn/start.sh add condition to prevent appending duplicative name server entries --- openvpn/start.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/openvpn/start.sh b/openvpn/start.sh index 3ef9456..4b858ae 100755 --- a/openvpn/start.sh +++ b/openvpn/start.sh @@ -144,9 +144,13 @@ for name_server_item in "${name_server_list[@]}"; do # strip whitespace from start and end of lan_network_item name_server_item=$(echo "${name_server_item}" | sed -e 's~^[ \t]*~~;s~[ \t]*$~~') - echo "[info] Adding ${name_server_item} to resolv.conf" | ts '%Y-%m-%d %H:%M:%.S' - echo "nameserver ${name_server_item}" >> /etc/resolv.conf - + # check if name server is already defined + existing_name_servers=$(awk "/^nameserver ${name_server_item}$/" /etc/resolv.conf | wc -l) + + if [ "$existing_name_servers" -eq 0 ]; then + echo "[info] Adding ${name_server_item} to resolv.conf" | ts '%Y-%m-%d %H:%M:%.S' + echo "nameserver ${name_server_item}" >> /etc/resolv.conf + fi done if [[ -z "${PUID}" ]]; then