public inbox for development@lists.ipfire.org
 help / color / mirror / Atom feed
* [PATCH] convert-dns-settings: Fix check to prevent doubble-adding the same server
@ 2020-01-28 15:14 Stefan Schantl
  2020-01-28 15:32 ` Michael Tremer
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Schantl @ 2020-01-28 15:14 UTC (permalink / raw)
  To: development

[-- Attachment #1: Type: text/plain, Size: 1379 bytes --]

Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
---
 src/scripts/convert-dns-settings | 23 +++++++++++++++--------
 1 file changed, 15 insertions(+), 8 deletions(-)

diff --git a/src/scripts/convert-dns-settings b/src/scripts/convert-dns-settings
index e9d4de86b..073356f50 100755
--- a/src/scripts/convert-dns-settings
+++ b/src/scripts/convert-dns-settings
@@ -43,17 +43,24 @@ main() {
 				for var in DNS1 DNS2; do
 					local server="${!var}"
 
-					# Check if the current server is allready part
-					# of the array.
-					for element in "${SERVERS[@]}"; do
-						[[ $element == $server ]] && continue
-					done
-
-					SERVERS+=($server)
+					# Check if the servers array is empty.
+					if [ ${#SERVERS[@]} -eq 0 ]; then
+						# Allways add the first found nameserver to the array.
+						SERVERS+=($server)
+					else
+						# Check if the current server is allready part ot the array.
+						if [[ ! "${SERVERS[@]}" =~ "${server}" ]]; then
+							# Add the server to the array.
+							SERVERS+=($server)
+						fi
+					fi
 				done
 
 				# Remove DNS1 and DNS2 settings from profile file.
-				sed -i "/^DNS[12]?=/d" $file
+				sed -i "/^DNS[12]=/d" $file
+
+				# Unset the local variables for the next round.
+				unset DNS1 DNS2
 			done
 
 		elif [ -s "/var/ipfire/dns/settings" ]; then
-- 
2.25.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-01-28 15:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-28 15:14 [PATCH] convert-dns-settings: Fix check to prevent doubble-adding the same server Stefan Schantl
2020-01-28 15:32 ` Michael Tremer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox