View | Details | Raw Unified | Return to bug 213665 | Differences between
and this patch

Collapse All | Expand All

(-)bin/freebsd-version/freebsd-version.1 (-9 / +10 lines)
Lines 25-31 Link Here
25
.\"
25
.\"
26
.\" $FreeBSD$
26
.\" $FreeBSD$
27
.\"
27
.\"
28
.Dd October 5, 2013
28
.Dd October 25, 2016
29
.Dt FREEBSD-VERSION 1
29
.Dt FREEBSD-VERSION 1
30
.Os
30
.Os
31
.Sh NAME
31
.Sh NAME
Lines 33-39 Link Here
33
.Nd print the version and patch level of the installed system
33
.Nd print the version and patch level of the installed system
34
.Sh SYNOPSIS
34
.Sh SYNOPSIS
35
.Nm
35
.Nm
36
.Op Fl ku
36
.Op Fl kru
37
.Sh DESCRIPTION
37
.Sh DESCRIPTION
38
The
38
The
39
.Nm
39
.Nm
Lines 50-55 Link Here
50
rebooted,
50
rebooted,
51
.Nm
51
.Nm
52
will print the version and patch level of the new kernel.
52
will print the version and patch level of the new kernel.
53
.It Fl r
54
Print the version and patch level of the running kernel.
55
Unlike
56
.Xr uname 1 ,
57
this is unaffected by environment variables.
53
.It Fl u
58
.It Fl u
54
Print the version and patch level of the installed userland.
59
Print the version and patch level of the installed userland.
55
These are hardcoded into
60
These are hardcoded into
Lines 57-70 Link Here
57
during the build.
62
during the build.
58
.El
63
.El
59
.Pp
64
.Pp
60
If both
65
If several of the above options are specified,
61
.Fl k
62
and
63
.Fl u
64
are specified,
65
.Nm
66
.Nm
66
will print the kernel version first, then the userland version, on
67
will print the installed kernel version first, then the running kernel
67
separate lines.
68
version, and finally the userland version, on separate lines.
68
If neither is specified, it will print the userland version only.
69
If neither is specified, it will print the userland version only.
69
.Sh IMPLEMENTATION NOTES
70
.Sh IMPLEMENTATION NOTES
70
The
71
The
(-)bin/freebsd-version/freebsd-version.sh.in (-6 / +21 lines)
Lines 36-42 Link Here
36
: ${LOADER_CONF_FILES:=$LOADER_DIR/defaults/loader.conf $LOADER_DIR/loader.conf $LOADER_DIR/loader.conf.local}
36
: ${LOADER_CONF_FILES:=$LOADER_DIR/defaults/loader.conf $LOADER_DIR/loader.conf $LOADER_DIR/loader.conf.local}
37
LOADER_RE1='^\([A-Z_a-z][0-9A-Z_a-z]*=[-./0-9A-Z_a-z]\{1,\}\).*$'
37
LOADER_RE1='^\([A-Z_a-z][0-9A-Z_a-z]*=[-./0-9A-Z_a-z]\{1,\}\).*$'
38
LOADER_RE2='^\([A-Z_a-z][0-9A-Z_a-z]*="[-./0-9A-Z_a-z]\{1,\}"\).*$'
38
LOADER_RE2='^\([A-Z_a-z][0-9A-Z_a-z]*="[-./0-9A-Z_a-z]\{1,\}"\).*$'
39
KERNEL_RE='^@(#)@@TYPE@@ \([-.0-9A-Za-z]\{1,\}\) .*$'
39
KERNEL_RE='^@@TYPE@@ \([-.0-9A-Za-z]\{1,\}\) .*$'
40
40
41
progname=$(basename $0)
41
progname=$(basename $0)
42
42
Lines 67-76 Link Here
67
	if [ ! -f "$kernfile" -o ! -r "$kernfile" ] ; then
67
	if [ ! -f "$kernfile" -o ! -r "$kernfile" ] ; then
68
		error "unable to locate kernel"
68
		error "unable to locate kernel"
69
	fi
69
	fi
70
	strings "$kernfile" | sed -n "s/$KERNEL_RE/\\1/p"
70
	what -qs "$kernfile" | sed -n "s/$KERNEL_RE/\\1/p"
71
}
71
}
72
72
73
#
73
#
74
# Print the version of the currently running kernel.
75
#
76
running_version() {
77
	sysctl -n kern.osrelease
78
}
79
80
#
74
# Print the hardcoded userland version.
81
# Print the hardcoded userland version.
75
#
82
#
76
userland_version() {
83
userland_version() {
Lines 81-87 Link Here
81
# Print a usage string and exit.
88
# Print a usage string and exit.
82
#
89
#
83
usage() {
90
usage() {
84
	echo "usage: $progname [-ku]" >&2
91
	echo "usage: $progname [-kru]" >&2
85
	exit 1
92
	exit 1
86
}
93
}
87
94
Lines 90-100 Link Here
90
#
97
#
91
main() {
98
main() {
92
	# parse command-line arguments
99
	# parse command-line arguments
93
	while getopts "ku" option ; do
100
	while getopts "kru" option ; do
94
		case $option in
101
		case $option in
95
		k)
102
		k)
96
			opt_k=1
103
			opt_k=1
97
			;;
104
			;;
105
		r)
106
			opt_r=1
107
			;;
98
		u)
108
		u)
99
			opt_u=1
109
			opt_u=1
100
			;;
110
			;;
Lines 108-122 Link Here
108
	fi
118
	fi
109
119
110
	# default is -u
120
	# default is -u
111
	if [ $((opt_k + opt_u)) -eq 0 ] ; then
121
	if [ $((opt_k + opt_r + opt_u)) -eq 0 ] ; then
112
		opt_u=1
122
		opt_u=1
113
	fi
123
	fi
114
124
115
	# print kernel version
125
	# print installed kernel version
116
	if [ $opt_k ] ; then
126
	if [ $opt_k ] ; then
117
		kernel_version
127
		kernel_version
118
	fi
128
	fi
119
129
130
	# print running kernel version
131
	if [ $opt_r ] ; then
132
		running_version
133
	fi
134
120
	# print userland version
135
	# print userland version
121
	if [ $opt_u ] ; then
136
	if [ $opt_u ] ; then
122
		userland_version
137
		userland_version

Return to bug 213665