Changeset View
Standalone View
bin/freebsd-version/freebsd-version.sh.in
Context not available. | |||||
KERNEL_RE='^@@TYPE@@ \([-.0-9A-Za-z]\{1,\}\) .*$' | KERNEL_RE='^@@TYPE@@ \([-.0-9A-Za-z]\{1,\}\) .*$' | ||||
progname=${0##*/} | progname=${0##*/} | ||||
progverbose=0 | |||||
kevans: Let's spell this out a little more: `progverbose` | |||||
# | # | ||||
# Print an error message and exit. | # Print an error message and exit. | ||||
Context not available. | |||||
if [ ! -f "$kernfile" -o ! -r "$kernfile" ] ; then | if [ ! -f "$kernfile" -o ! -r "$kernfile" ] ; then | ||||
error "unable to locate kernel" | error "unable to locate kernel" | ||||
fi | fi | ||||
what -qs "$kernfile" | sed -n "s/$KERNEL_RE/\\1/p" | if [ $progverbose -gt 0 ] ; then | ||||
Done Inline ActionsPlease expand this one to a full if/else construction -- it'll be a little bit easier to read than following line continuations and multiple logical operations. kevans: Please expand this one to a full `if`/`else` construction -- it'll be a little bit easier to… | |||||
what -qs "$kernfile" | awk -F':' '{ print $1 }' | cut -d' ' -f2- | |||||
else | |||||
Done Inline Actions^12? imp: ^12? | |||||
Done Inline Actionsthat's indeed necessary; as we might take care about output's compatibility here.
the outputs for what -qs /boot/kernel/kernel are documented here on a previous comment;
egypcio: that's indeed necessary; as we might take care about output's compatibility here.
> probably… | |||||
Done Inline Actions^12 is wrong though. But more importantly, the problem here isn't stable vs release. It's reproducible build vs not reproducible build. You should be testing more directly for that in the output rather than using this heuristic that just tests for environments where reproducible build was yes vs no. imp: ^12 is wrong though.
What about FreeBSD 11?
But more importantly, the problem here isn't… | |||||
Done Inline Actionshmm. tho the current outcome is reproducible, now I am confused; "two" (and a half) questions here:
egypcio: hmm. tho the current outcome is reproducible, now I am confused; "two" (and a half) questions… | |||||
Done Inline ActionsI would like to flag one little thing still; should we've being talking about WITH_REPRODUCIBLE_BUILD. newvers.sh do produces a kern.version that is used as base for us here to format our verbose output. taking the example of a recent FreeBSD CURRENT we have the following: egypcio@gaz:~ % sysctl -n kern.version FreeBSD 14.0-CURRENT #11 main-n257521-97be6fced7d: Sat Aug 20 11:07:35 UTC 2022 root@gaz.localhost.localdomain:/usr/obj/usr/src/amd64.amd64/sys/GENERIC-NODEBUG egypcio@gaz:~ % sysctl -n kern.version | head -1 FreeBSD 14.0-CURRENT #11 main-n257521-97be6fced7d: Sat Aug 20 11:07:35 UTC 2022 egypcio@gaz:~ % what -qs /boot/kernel/kernel FreeBSD 14.0-CURRENT #11 main-n257521-97be6fced7d: Sat Aug 20 11:07:35 UTC 2022 based on what the newvers.sh does, sysctl -n kern.version | head -1 is pretty much what one gets by default, should reproducible builds are enabled; and that's exact the same (reproducible) output as we do get from what -qs egypcio: I would like to flag one little thing still; should we've being talking about… | |||||
Done Inline ActionsI guess my point is that this should be data driven based on the number of fields, not looking for a specific tag like RELEASE which likely is going to be unreliable. imp: I guess my point is that this should be data driven based on the number of fields, not looking… | |||||
Done Inline Actionsthanks for clarifying that out. much appreciated! I shall take care of it and update the diff ASAP. -if ( echo "$out" | grep -Eiq '^12|RELEASE' ) ; then +if [ $(echo "$out" | wc -w) -lt 4 ] ; then egypcio: thanks for clarifying that out. much appreciated! I shall take care of it and update the diff… | |||||
what -qs "$kernfile" | sed -n "s/$KERNEL_RE/\\1/p" | |||||
fi | |||||
} | } | ||||
# | # | ||||
# Print the version of the currently running kernel. | # Print the version of the currently running kernel. | ||||
# | # | ||||
Done Inline ActionsFor these two, consider just building the string then outputting it: out=$(sysctl -n kern.osrelease) [ $progverbose -gt 0 ] && out="${out} $(sysctl -n kern.osreldate)" echo "$out" In these cases, the main purpose is making it trivial to understand upon inspection that the first column remains constant between -v and normal invocation. It also reduces duplication in doing so. kevans: For these two, consider just building the string then outputting it:
```
out=$(sysctl -n kern. | |||||
running_version() { | running_version() { | ||||
sysctl -n kern.osrelease | out=$(sysctl -n kern.osrelease) | ||||
[ $progverbose -gt 0 ] && out="${out} $(sysctl -n kern.osreldate)" | |||||
echo "$out" | |||||
} | } | ||||
# | # | ||||
# Print the hardcoded userland version. | # Print the hardcoded userland version. | ||||
# | # | ||||
userland_version() { | userland_version() { | ||||
echo $USERLAND_VERSION | out=$USERLAND_VERSION | ||||
[ $progverbose -gt 0 ] && out="${USERLAND_VERSION} $(uname -U)" | |||||
echo "$out" | |||||
} | } | ||||
# | # | ||||
Context not available. | |||||
# Print a usage string and exit. | # Print a usage string and exit. | ||||
# | # | ||||
usage() { | usage() { | ||||
echo "usage: $progname [-kru] [-j jail]" >&2 | echo "usage: $progname [-kruv] [-j jail]" >&2 | ||||
exit 1 | exit 1 | ||||
} | } | ||||
Context not available. | |||||
main() { | main() { | ||||
# parse command-line arguments | # parse command-line arguments | ||||
local OPTIND=1 OPTARG option | local OPTIND=1 OPTARG option | ||||
while getopts "kruj:" option ; do | while getopts "kruvj:" option ; do | ||||
case $option in | case $option in | ||||
k) | k) | ||||
opt_k=1 | opt_k=1 | ||||
Context not available. | |||||
u) | u) | ||||
opt_u=1 | opt_u=1 | ||||
;; | ;; | ||||
v) | |||||
progverbose=1 | |||||
;; | |||||
j) | j) | ||||
if [ $opt_j ] ; then | if [ $opt_j ] ; then | ||||
jail="$jail $OPTARG" | jail="$jail $OPTARG" | ||||
Context not available. |
Let's spell this out a little more: progverbose