diff --git a/bin/freebsd-version/freebsd-version.1 b/bin/freebsd-version/freebsd-version.1 index 710bb23ac4c3..b580c580fcbc 100644 --- a/bin/freebsd-version/freebsd-version.1 +++ b/bin/freebsd-version/freebsd-version.1 @@ -1,124 +1,133 @@ .\"- .\" Copyright (c) 2013 Dag-Erling Smørgrav .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $FreeBSD$ .\" -.Dd November 14, 2017 +.Dd October 1, 2021 .Dt FREEBSD-VERSION 1 .Os .Sh NAME .Nm freebsd-version .Nd print the version and patch level of the installed system .Sh SYNOPSIS .Nm .Op Fl kru +.Op Fl j Ar jail .Sh DESCRIPTION The .Nm utility makes a best effort to determine the version and patch level of the installed kernel and / or userland. .Pp The following options are available: .Bl -tag -width Fl .It Fl k Print the version and patch level of the installed kernel. Unlike .Xr uname 1 , if a new kernel has been installed but the system has not yet rebooted, .Nm will print the version and patch level of the new kernel. .It Fl r Print the version and patch level of the running kernel. Unlike .Xr uname 1 , this is unaffected by environment variables. .It Fl u Print the version and patch level of the installed userland. These are hardcoded into .Nm during the build. +.It Fl j Ar jail +Print the version and patch level of the installed userland in the +given jail specified by +.Va jid +or +.Va name . +This option can be specified multiple times. .El .Pp If several of the above options are specified, .Nm will print the installed kernel version first, then the running kernel -version, and finally the userland version, on separate lines. +version, next the userland version, and finally the userland version +of the specified jails, on separate lines. If neither is specified, it will print the userland version only. .Sh IMPLEMENTATION NOTES The .Nm utility should provide the correct answer in the vast majority of cases, including on systems kept up-to-date using .Xr freebsd-update 8 , which does not update the kernel version unless the kernel itself was affected by the latest patch. .Pp To determine the name (and hence the location) of a custom kernel, the .Nm utility will attempt to parse .Pa /boot/defaults/loader.conf and .Pa /boot/loader.conf , looking for definitions of the .Va kernel and .Va bootfile variables, both with a default value of .Dq kernel . It may however fail to locate the correct kernel if either or both of these variables are defined in a non-standard location, such as in .Pa /boot/loader.rc . .Sh ENVIRONMENT .Bl -tag -width ROOT .It Ev ROOT Path to the root of the filesystem in which to look for .Pa loader.conf and the kernel. .El .Sh EXAMPLES To determine the version of the currently running userland: .Bd -literal -offset indent /bin/freebsd-version -u .Ed .Pp To inspect a system being repaired using a live CD: .Bd -literal -offset indent mount -rt ufs /dev/ada0p2 /mnt env ROOT=/mnt /mnt/bin/freebsd-version -ku .Ed .Sh SEE ALSO .Xr uname 1 , .Xr loader.conf 5 .Sh HISTORY The .Nm command appeared in .Fx 10.0 . .Sh AUTHORS The .Nm utility and this manual page were written by .An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org . diff --git a/bin/freebsd-version/freebsd-version.sh.in b/bin/freebsd-version/freebsd-version.sh.in index 9541b86a2636..be1be366f652 100644 --- a/bin/freebsd-version/freebsd-version.sh.in +++ b/bin/freebsd-version/freebsd-version.sh.in @@ -1,141 +1,164 @@ #!/bin/sh #- # Copyright (c) 2013 Dag-Erling Smørgrav # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ # set -e USERLAND_VERSION="@@REVISION@@-@@BRANCH@@" : ${ROOT:=} : ${LOADER_DIR:=$ROOT/boot} : ${LOADER_CONF_FILES:=$LOADER_DIR/defaults/loader.conf $LOADER_DIR/loader.conf $LOADER_DIR/loader.conf.local} LOADER_RE1='^\([A-Z_a-z][0-9A-Z_a-z]*=[-./0-9A-Z_a-z]\{1,\}\).*$' LOADER_RE2='^\([A-Z_a-z][0-9A-Z_a-z]*="[-./0-9A-Z_a-z]\{1,\}"\).*$' KERNEL_RE='^@@TYPE@@ \([-.0-9A-Za-z]\{1,\}\) .*$' progname=${0##*/} # # Print an error message and exit. # error() { echo "$progname: $*" >&2 exit 1 } # # Try to get the name of the installed kernel from loader.conf and # return the full path. If loader.conf does not exist or we could not # read it, return the path to the default kernel. # kernel_file() { eval $(sed -n "s/$LOADER_RE1/\\1;/p; s/$LOADER_RE2/\\1;/p" \ $LOADER_CONF_FILES 2>/dev/null) echo "$LOADER_DIR/${kernel:-kernel}/${bootfile:-kernel}" } # # Extract the kernel version from the installed kernel. # kernel_version() { kernfile=$(kernel_file) if [ ! -f "$kernfile" -o ! -r "$kernfile" ] ; then error "unable to locate kernel" fi what -qs "$kernfile" | sed -n "s/$KERNEL_RE/\\1/p" } # # Print the version of the currently running kernel. # running_version() { sysctl -n kern.osrelease } # # Print the hardcoded userland version. # userland_version() { echo $USERLAND_VERSION } +# +# Print the hardcoded userland version of a jail. +# +jail_version() { + for i in $jail; do + jexec -- $i freebsd-version + done +} + # # Print a usage string and exit. # usage() { - echo "usage: $progname [-kru]" >&2 + echo "usage: $progname [-kru] [-j jail]" >&2 exit 1 } # # Main program. # main() { # parse command-line arguments - while getopts "kru" option ; do + local OPTIND=1 OPTARG option + while getopts "kruj:" option ; do case $option in k) opt_k=1 ;; r) opt_r=1 ;; u) opt_u=1 ;; + j) + if [ $opt_j ] ; then + jail="$jail $OPTARG" + else + opt_j=1 + jail="$OPTARG" + fi + ;; *) usage ;; esac done if [ $OPTIND -le $# ] ; then usage fi # default is -u - if [ $((opt_k + opt_r + opt_u)) -eq 0 ] ; then + if [ $((opt_k + opt_r + opt_u + opt_j)) -eq 0 ] ; then opt_u=1 fi # print installed kernel version if [ $opt_k ] ; then kernel_version fi # print running kernel version if [ $opt_r ] ; then running_version fi # print userland version if [ $opt_u ] ; then userland_version fi + + # print jail version + if [ $opt_j ] ; then + jail_version + fi } main "$@"