From patchwork Tue Jan 28 15:14:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 2729 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 486VXP3mjjz3xY8 for ; Tue, 28 Jan 2020 15:14:45 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 486VXM1fxCz1jq; Tue, 28 Jan 2020 15:14:43 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1580224484; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=u67Ahy6VNHZg8hwBd+aJv3Gipl1rlYfRJcONGf5XyJo=; b=ObLJBney3RjyIRxc83tWAiC4afMSMVUdU2m6UWC+8ETm+lHHGSS3VRkT/fuBfXXQgtg2Jg rgMELmjYlanvy3Bw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1580224484; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=u67Ahy6VNHZg8hwBd+aJv3Gipl1rlYfRJcONGf5XyJo=; b=R6MY3ufoTrkgAPhqND0OZR3cjYjd1OjVpdy89PSnx/o7rjhdnPVa2ldbvZfUVk+WIU9s+5 NsxBcVmhR2FU1y5xQPAeCXwcBibcyaBYL7meciZgeSvxax8w+Gbyg+7rON5H/ledoCm2Ot CSrBoLbH3TPFReYSQwnpfyOIYhNe0k8IeQ8KXBbPaMi91kJrTWxl/xfT4px49f3VN9Ho0t Jw6Gp/qGp6y0KgfrSrkJynYfZpUV9b7unWgVdDXx7yz+3VcS57j7xSCJ0XUvHXNt/PTDu1 OoaaOLRqCS1cQD/+fvDfcB4bKQWuboQTO1DTj8jLkbjSuH5qC6oDSlqOYuCw/w== Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 486VXL3fztz2yXx; Tue, 28 Jan 2020 15:14:42 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384 client-signature ECDSA (P-384) client-digest SHA384) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 486VXK26dtz2xnq for ; Tue, 28 Jan 2020 15:14:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPSA id 486VXJ1stXz1jq; Tue, 28 Jan 2020 15:14:40 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909ed25519; t=1580224480; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=u67Ahy6VNHZg8hwBd+aJv3Gipl1rlYfRJcONGf5XyJo=; b=JI3AWFY3MHjLmPzhWmpoe06HmTxRCsqX7l3LtHxhwSu6792rZUkG2bRgClZm4dcS+DhZWj WMbTFomffdwR1fCg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=201909rsa; t=1580224480; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=u67Ahy6VNHZg8hwBd+aJv3Gipl1rlYfRJcONGf5XyJo=; b=BD2GD4IRWtpUGRgQASdtPoEOr2+yoMlcHpx85cQIPAfuWv7r8BtXZuN0vCXlUr16Qk/ULP Krn1Imk3nepA38anfmLHIi/Z+VGgKzXNqcogyru7740BVVHfBl9NtaD93CeBxVSfFtbQnK fkMsPszYUqYT22eOz8wczSM38sYW2NY1SLSz1QYRbQ5vdIa4UpIOtsq00FAZXAeQJDknZB E8tGoSQo6OPv2d62rkvY+G3YFAb5eM35r6ml8IxQk93jGCSiTngqiBCb8Kd+SUg9rSSYYV 1YHCGvjqvyWgEi4pTlJweCx2OYq6moMGQswWPtr7KVYspU43bW7IJAfNyOUsoA== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH] convert-dns-settings: Fix check to prevent doubble-adding the same server Date: Tue, 28 Jan 2020 16:14:35 +0100 Message-Id: <20200128151435.8671-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 Authentication-Results: mail01.ipfire.org; auth=pass smtp.mailfrom=stefan.schantl@ipfire.org X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Stefan Schantl --- 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