svn commit: r354922 - in head: etc libexec/rc libexec/rc/rc.d share/man/man5 sys/sys

Warner Losh imp at FreeBSD.org
Wed Nov 20 23:45:33 UTC 2019


Author: imp
Date: Wed Nov 20 23:45:31 2019
New Revision: 354922
URL: https://svnweb.freebsd.org/changeset/base/354922

Log:
  Create /etc/os-release file.
  
  Each boot, regenerate /var/run/os-release based on the currently running
  system. Create a /etc/os-release symlink pointing to this file (so that this
  doesn't create a new reason /etc can not be mounted read-only).
  
  This is compatible with what other systems do and is what the sysutil/os-release
  port attempted to do, but in an incomplete way. Linux, Solaris and DragonFly all
  implement this natively as well. The complete standard can be found at
  https://www.freedesktop.org/software/systemd/man/os-release.html
  
  Moving this to the base solves both the non-standard location problem with the
  port, as well as the lack of update of this file on system update.
  
  Bump __FreeBSD_version to 1300060
  
  PR: 238953
  Differential Revision:  https://reviews.freebsd.org/D22271

Added:
  head/libexec/rc/rc.d/os-release   (contents, props changed)
  head/share/man/man5/os-release.5   (contents, props changed)
Modified:
  head/etc/Makefile
  head/libexec/rc/rc.conf
  head/libexec/rc/rc.d/Makefile
  head/share/man/man5/Makefile
  head/sys/sys/param.h

Modified: head/etc/Makefile
==============================================================================
--- head/etc/Makefile	Wed Nov 20 23:09:21 2019	(r354921)
+++ head/etc/Makefile	Wed Nov 20 23:45:31 2019	(r354922)
@@ -57,6 +57,8 @@ distribution:
 	${_+_}cd ${.CURDIR}/mtree; ${MAKE} install
 	${_+_}cd ${SRCTOP}/share/termcap; ${MAKE} etc-termcap
 	${_+_}cd ${SRCTOP}/usr.sbin/rmt; ${MAKE} etc-rmt
+	${INSTALL_SYMLINK} ../var/run/os-release \
+		${DESTDIR}/etc/os-release
 .if ${MK_UNBOUND} != "no"
 	if [ ! -e ${DESTDIR}/etc/unbound ]; then \
 		${INSTALL_SYMLINK} -T "package=unbound" \

Modified: head/libexec/rc/rc.conf
==============================================================================
--- head/libexec/rc/rc.conf	Wed Nov 20 23:09:21 2019	(r354921)
+++ head/libexec/rc/rc.conf	Wed Nov 20 23:45:31 2019	(r354922)
@@ -678,6 +678,9 @@ entropy_save_sz="4096"	# Size of the entropy cache fil
 entropy_save_num="8"	# Number of entropy cache files to save.
 harvest_mask="511"	# Entropy device harvests all but the very invasive sources.
 			# (See 'sysctl kern.random.harvest' and random(4))
+osrelease_enable="YES"	# Update /var/run/os-release on boot (or NO).
+osrelease_file="/var/run/os-release" # File to update for os-release.
+osrelease_perms="444"	# Default permission for os-release file.
 dmesg_enable="YES"	# Save dmesg(8) to /var/run/dmesg.boot
 watchdogd_enable="NO"	# Start the software watchdog daemon
 watchdogd_flags=""	# Flags to watchdogd (if enabled)

Modified: head/libexec/rc/rc.d/Makefile
==============================================================================
--- head/libexec/rc/rc.d/Makefile	Wed Nov 20 23:09:21 2019	(r354921)
+++ head/libexec/rc/rc.d/Makefile	Wed Nov 20 23:45:31 2019	(r354922)
@@ -77,6 +77,7 @@ CONFS=	DAEMON \
 	nsswitch \
 	ntpdate \
 	${_opensm} \
+	os-release \
 	pf \
 	pflog \
 	pfsync \

Added: head/libexec/rc/rc.d/os-release
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/libexec/rc/rc.d/os-release	Wed Nov 20 23:45:31 2019	(r354922)
@@ -0,0 +1,44 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+
+# PROVIDE: os-release
+# REQUIRE: mountcritremote FILESYSTEMS
+# BEFORE:  LOGIN
+
+. /etc/rc.subr
+
+: ${osrelease_file:=/var/run/os-release}
+: ${osrelease_perms:=444}
+name="osrelease"
+desc="Update ${osrelease_file}"
+start_cmd="osrelease_start"
+stop_cmd=":"
+
+osrelease_start()
+{
+	local _version _version_id
+
+	check_startmsgs && echo -n "Updating ${osrelease_file} "
+	_version=$(freebsd-version -u)
+	_version_id=${_version%%[^0-9.]*}
+	t=$(mktemp -t os-release)
+	cat > "$t" <<-__EOF__
+		NAME=FreeBSD
+		VERSION=$_version
+		VERSION_ID=$_version_id
+		ID=freebsd
+		ANSI_COLOR="0;31"
+		PRETTY_NAME="FreeBSD $_version"
+		CPE_NAME=cpe:/o:freebsd:freebsd:$_version_id
+		HOME_URL=https://FreeBSD.org/
+		BUG_REPORT_URL=https://bugs.FreeBSD.org/
+__EOF__
+	install -C -o root -g wheel -m ${osrelease_perms} "$t" "${osrelease_file}"
+	rm -f "$t"
+	check_startmsgs && echo 'done.'
+}
+
+load_rc_config $name
+run_rc_command "$1"

Modified: head/share/man/man5/Makefile
==============================================================================
--- head/share/man/man5/Makefile	Wed Nov 20 23:09:21 2019	(r354921)
+++ head/share/man/man5/Makefile	Wed Nov 20 23:45:31 2019	(r354922)
@@ -46,6 +46,7 @@ MAN=	acct.5 \
 	nsmb.conf.5 \
 	nsswitch.conf.5 \
 	nullfs.5 \
+	os-release.5 \
 	passwd.5 \
 	pbm.5 \
 	periodic.conf.5 \

Added: head/share/man/man5/os-release.5
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/share/man/man5/os-release.5	Wed Nov 20 23:45:31 2019	(r354922)
@@ -0,0 +1,130 @@
+.\" Copyright (c) 2019 M. Warner Losh.
+.\"
+.\" 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 9, 2019
+.Dt OS-RELEASE 5
+.Os
+.Sh NAME
+.Nm os-release
+.Nd file describing the current OS and some of its attributes
+.Sh DESCRIPTION
+The
+.Nm
+file is a new-line separated list of key value pairs.
+The syntax of this file is a reduced
+.Xr sh 1
+variable assignment with the
+following restrictions:
+.Bl -bullet
+.It
+Strings cannot be concatenated together
+.It
+No variable expansion is done
+.It
+All shell special characters must be quoted as documented in
+.Xr sh 1
+.It
+Variable assignments must be included inside of double quotes
+if they contain characters outside of A-Z, a-z and 0-9
+.It
+All strings should be UTF-8 format
+.It
+Non-printable characters should not be used in the strings
+.El
+.Pp
+Lines starting with the character
+.Ql #
+are ignored as comments.
+.Sh VARIABLES
+The following variables are defined by the standard.
+.Bl -tag -width XXXXXXXXXX -compact
+.It Dv NAME
+A string describing the preferred OS name.
+.It Dv VERSION
+Version string for the OS, in its usual and customary format.
+.It Dv ID
+Lower case version of the name with only a-z, 0-9,
+.Ql . ,
+.Ql - ,
+and
+.Ql _ .
+.It Dv VERSION_ID
+Lower case version of the version with only a-z, 0-9,
+.Ql . ,
+.Ql - ,
+and
+.Ql _ .
+.It Dv PRETTY_NAME
+A pretty version of the name presented to the user.
+May contain release information.
+.It Dv ANSI_COLOR
+Suggested color presentation for the OS.
+This string should be suitable for inclusion within an ESC [ m ANSI/ECMA-48
+escape sequence to render the OS in its preferred color.
+This variable is optional.
+.It Dv CPE_NAME
+A CPE name for the operating system.
+This field shall follow the NIST Common Platform Enumeration specification.
+.It Dv HOME_URL
+.It Dv SUPPORT_URL
+.It Dv BUG_REPORT_URL
+.It Dv PRIVACY_POLICY_URL
+Links on the internet, in RFC 3986 format for different aspects of this OS.
+These variables are optional.
+.It Dv BUILD_ID
+A string identifying the build.
+This variable is optional.
+.It Dv VARIANT
+A string describing the variant of this operating system.
+This variable is optional.
+.It Dv VARIANT_ID
+Lower case version of the variant with only a-z, 0-9,
+.Ql . ,
+.Ql - ,
+and
+.Ql _ .
+This variable is optional.
+.El
+.Pp
+All other variables have no standard-defined meaning.
+.Sh FILES
+.Bl -tag -width XXXXXXXXXX -compact
+.It Pa /etc/os-release
+Symbolic link to actual
+.Pa os-release
+file.
+.It Pa /var/run/os-release
+Generated os-release file describing the currently running system.
+.Sh SEE ALSO
+.Bl -tag -width XXXXXXXXXX -compact
+.It CPE Specification
+.Lk https://csrc.nist.gov/projects/security-content-automation-protocol/scap-specifications/cpe
+.It RFC 3986
+.Lk https://tools.ietf.org/html/rfc3986
+.It os-release Specification
+.Lk https://www.linux.org/docs/man5/os-release.html
+.Sh HISTORY
+This file first appeared in
+.Fx 13.0 .

Modified: head/sys/sys/param.h
==============================================================================
--- head/sys/sys/param.h	Wed Nov 20 23:09:21 2019	(r354921)
+++ head/sys/sys/param.h	Wed Nov 20 23:45:31 2019	(r354922)
@@ -60,7 +60,7 @@
  *		in the range 5 to 9.
  */
 #undef __FreeBSD_version
-#define __FreeBSD_version 1300059	/* Master, propagated to newvers */
+#define __FreeBSD_version 1300060	/* Master, propagated to newvers */
 
 /*
  * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,


More information about the svn-src-all mailing list