Permalink
Browse files

Improve omv_is_ipv6_enabled helper function. Filter the loopback netw…

…ork device.

Signed-off-by: Volker Theile <votdev@gmx.de>
  • Loading branch information...
votdev committed Jan 12, 2018
1 parent 038c844 commit e6e78fba1acc2344834cd50a3d67b5dc5f15e37c
Showing with 1 addition and 1 deletion.
  1. +1 −1 deb/openmediavault/usr/share/openmediavault/scripts/helper-functions
@@ -822,7 +822,7 @@ omv_is_gateway6() {
# Check if IPv6 is enabled.
# @return 0 if enabled, otherwise 1.
omv_is_ipv6_enabled() {
[ -e /proc/net/if_inet6 -a $(sed -r '/\s+lo$/d' /proc/net/if_inet6 | wc -l) -gt 0 ] && return 0
[ -e /proc/net/if_inet6 -a $(grep --count --invert-match 'lo$' /proc/net/if_inet6) -gt 0 ] && return 0
return 1
}

4 comments on commit e6e78fb

@hpreusse

This comment has been minimized.

Show comment
Hide comment
@hpreusse

hpreusse Jan 13, 2018

Finally you could simply suppress the output and and simply check the exit code. grep (1) ;-) :

   -q, --quiet, --silent
          Quiet;  do  not  write  anything  to  standard   output.    Exit
          immediately  with  zero status if any match is found, even if an
          error was detected.  Also see the -s or --no-messages option.

hpreusse replied Jan 13, 2018

Finally you could simply suppress the output and and simply check the exit code. grep (1) ;-) :

   -q, --quiet, --silent
          Quiet;  do  not  write  anything  to  standard   output.    Exit
          immediately  with  zero status if any match is found, even if an
          error was detected.  Also see the -s or --no-messages option.
@ryecoaaron

This comment has been minimized.

Show comment
Hide comment
@ryecoaaron

ryecoaaron Jan 13, 2018

Contributor

Exit code will still return zero if count is zero.

Contributor

ryecoaaron replied Jan 13, 2018

Exit code will still return zero if count is zero.

@hpreusse

This comment has been minimized.

Show comment
Hide comment
@hpreusse

hpreusse Jan 14, 2018

Sorry, I'm not able to reproduce this:

hille@haka:$ echo a|grep -q a && echo b
b
hille@haka:
$ echo b|grep -q -c a && echo b
hille@haka:~$ echo b|grep -c a && echo b
0

So even when not removing --count option I still have an non-zero exit code if the string is not found.

hpreusse replied Jan 14, 2018

Sorry, I'm not able to reproduce this:

hille@haka:$ echo a|grep -q a && echo b
b
hille@haka:
$ echo b|grep -q -c a && echo b
hille@haka:~$ echo b|grep -c a && echo b
0

So even when not removing --count option I still have an non-zero exit code if the string is not found.

@votdev

This comment has been minimized.

Show comment
Hide comment
@votdev

votdev Jan 14, 2018

Collaborator

The current implementation is more readable and works as expected. This function is not called that often, so we do not need to optimize it to the best. There are many ways to implement things.

Collaborator

votdev replied Jan 14, 2018

The current implementation is more readable and works as expected. This function is not called that often, so we do not need to optimize it to the best. There are many ways to implement things.

Please sign in to comment.