opnsense / update

OPNsense update tools
https://opnsense.org/
BSD 2-Clause "Simplified" License
128 stars 78 forks source link

update: silence grep #73

Closed oshogbo closed 3 years ago

oshogbo commented 3 years ago

The -c option is printing on stdout the count of the founded items, even when the -q option is provided: $ grep -qc sh security.sh 1

In this if we are checking only the return code. So the amount of founded items is printed to stdout. Checking an return code should be sufficient.

This is breakes the version option when opnsense-update is used:

0 20.7.8

The output is used to build a JSON. For example in firmware/check.sh: base_to_reboot="$(opnsense-update -v)"

And later is used to build a JSON: packages_upgraded=$packages_upgraded"\"current_version\":\"$base_to_delete\","

Which ends up with invalid JSON: "new_version":"0 20.7.8"

Then the php script (like ./firmware/product.php) can't parse such invalid JSON.

This seems to be also a bug in FreeBSD so I failed separate bug report there.

Sponsored by: DynFi

fichtner commented 3 years ago

While I agree that -qc is silly can you help me reproduce this?

# cd /usr/core/
# grep -qc pkg Makefile
# grep -c pkg Makefile
6
# uname -a
FreeBSD localhost 12.1-RELEASE-p18-HBSD FreeBSD 12.1-RELEASE-p18-HBSD #0  2e2d4484b05(stable/21.7)-dirty: Tue Jun 29 08:38:24 CEST 2021     root@sensey:/usr/obj/usr/src/amd64.amd64/sys/SMP  amd64
oshogbo commented 3 years ago

Do you use bsdgrep?

fichtner commented 3 years ago

Well, the one provided by FreeBSD:

# which grep
/usr/bin/grep
oshogbo commented 3 years ago

I'm running FreeBSD-13.0 stable. So something might change between FreeBSD-13 and FreeBSD-12.2 or we are using different grep (gnu version doesn't behave such way).

Can you run: grep -V

FYI: https://reviews.freebsd.org/D31108

fichtner commented 3 years ago
# grep -V
grep (GNU grep) 2.5.1-FreeBSD
oshogbo commented 3 years ago

So this is why. You are are using gnu version. The standard bsdgrep behaves differently. You should be able do reproduce this using: bsdgrep -qc pkg Makefile

fichtner commented 3 years ago

Ah ok, from https://www.freebsd.org/releases/13.0R/announce/

The BSD version of grep(1) is now installed by default. The obsolete GNU version that was the previous default has been removed.
oshogbo commented 3 years ago

I still think that this is a bug in bsdgrep., but the -c option is not needed in this case.

fichtner commented 3 years ago

Merged, thanks! I changed the commit message a bit to reflect the incoming change in FreeBSD 13.x ... I don't want to leave the impression that anything is currently not as it should be within our ecosystem. 21.7 will still use FreeBSD 12, but FreeBSD 13 is coming to 22.1.

Cheers, Franco

oshogbo commented 3 years ago

Sure. Thanks!

Have a good one, Mariusz