]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
convert-dns-settings: Fix check to prevent doubble-adding the same server
authorStefan Schantl <stefan.schantl@ipfire.org>
Tue, 28 Jan 2020 15:14:35 +0000 (16:14 +0100)
committerArne Fitzenreiter <arne_f@ipfire.org>
Tue, 28 Jan 2020 15:38:36 +0000 (15:38 +0000)
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
src/scripts/convert-dns-settings

index e9d4de86baac587a81b180f9165895b4cb70f25c..073356f50ce4f22d9024ba773b7841dbbfa381c3 100755 (executable)
@@ -43,17 +43,24 @@ main() {
                                for var in DNS1 DNS2; do
                                        local server="${!var}"
 
                                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.
                                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
                        done
 
                elif [ -s "/var/ipfire/dns/settings" ]; then