From: Michael Tremer <michael.tremer@ipfire.org>
To: development@lists.ipfire.org
Subject: Re: [PATCH] convert-dns-settings: Fix check to prevent doubble-adding the same server
Date: Tue, 28 Jan 2020 15:32:08 +0000 [thread overview]
Message-ID: <F7C6E232-950A-4EEE-8398-4A17A9C8A7B7@ipfire.org> (raw)
In-Reply-To: <20200128151435.8671-1-stefan.schantl@ipfire.org>
[-- Attachment #1: Type: text/plain, Size: 1981 bytes --]
Hi,
I am not sure if I agree with this patch, yet...
> On 28 Jan 2020, at 15:14, Stefan Schantl <stefan.schantl(a)ipfire.org> wrote:
>
> 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)
Please quote things in shell and use curly brackets for variables. It should read: SERVERS+=( “${server}” )
> + else
> + # Check if the current server is allready part ot the array.
> + if [[ ! "${SERVERS[@]}" =~ "${server}" ]]; then
Why would this not work when the array is empty? i.e. why do we need to check above?
> + # Add the server to the array.
> + SERVERS+=($server)
Same.
> + fi
> + fi
> done
>
> # Remove DNS1 and DNS2 settings from profile file.
> - sed -i "/^DNS[12]?=/d" $file
> + sed -i "/^DNS[12]=/d" $file
Again missing quotes, but why is the DNS=Automatic or DNS=Manual settings not being removed any more?
The question mark was intentional.
> +
> + # Unset the local variables for the next round.
> + unset DNS1 DNS2
> done
>
> elif [ -s "/var/ipfire/dns/settings" ]; then
> —
> 2.25.0
>
-Michael
prev parent reply other threads:[~2020-01-28 15:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-28 15:14 Stefan Schantl
2020-01-28 15:32 ` Michael Tremer [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=F7C6E232-950A-4EEE-8398-4A17A9C8A7B7@ipfire.org \
--to=michael.tremer@ipfire.org \
--cc=development@lists.ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox