blob: 8906906bc3eb30b992ceceee4ee7e5626dffd044 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit allarch
2
3SUMMARY = "Operating system identification"
Brad Bishopbba38f32018-08-23 16:11:46 +08004DESCRIPTION = "The /usr/lib/os-release file contains operating system identification data."
Patrick Williams2390b1b2022-11-03 13:47:49 -05005HOMEPAGE = "https://www.freedesktop.org/software/systemd/man/os-release.html"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006LICENSE = "MIT"
Patrick Williamsc124f4f2015-09-15 14:41:29 -05007INHIBIT_DEFAULT_DEPS = "1"
8
9do_fetch[noexec] = "1"
10do_unpack[noexec] = "1"
11do_patch[noexec] = "1"
12do_configure[noexec] = "1"
13
Patrick Williams2390b1b2022-11-03 13:47:49 -050014# See: https://www.freedesktop.org/software/systemd/man/os-release.html
Patrick Williamsc124f4f2015-09-15 14:41:29 -050015# Other valid fields: BUILD_ID ID_LIKE ANSI_COLOR CPE_NAME
16# HOME_URL SUPPORT_URL BUG_REPORT_URL
Andrew Geissler595f6302022-01-24 19:11:47 +000017OS_RELEASE_FIELDS = "\
Patrick Williams2390b1b2022-11-03 13:47:49 -050018 ID ID_LIKE NAME VERSION VERSION_ID VERSION_CODENAME PRETTY_NAME \
Andrew Geissler028142b2023-05-05 11:29:21 -050019 CPE_NAME \
Andrew Geissler595f6302022-01-24 19:11:47 +000020"
Andrew Geissler4b740dc2020-05-05 08:54:39 -050021OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022
23ID = "${DISTRO}"
24NAME = "${DISTRO_NAME}"
25VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if 'DISTRO_CODENAME' in d else ''}"
26VERSION_ID = "${DISTRO_VERSION}"
Patrick Williams2390b1b2022-11-03 13:47:49 -050027VERSION_CODENAME = "${DISTRO_CODENAME}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050028PRETTY_NAME = "${DISTRO_NAME} ${VERSION}"
Andrew Geissler028142b2023-05-05 11:29:21 -050029
30# The vendor field is hardcoded to "openembedded" deliberately. We'd
31# advise developers leave it as this value to clearly identify the
32# underlying build environment from which the OS was constructed. We
33# understand people will want to identify themselves as the people who
34# built the image, we'd suggest using the DISTRO element to do this, so
35# that is customisable.
36# This end result combines to mean systems can be traced back to both who
37# built them and which system was used, which is ultimately the goal of
38# the CPE.
39
40CPE_DISTRO ??= "${DISTRO}"
41CPE_NAME="cpe:/o:openembedded:${CPE_DISTRO}:${VERSION_ID}"
42
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043BUILD_ID ?= "${DATETIME}"
44BUILD_ID[vardepsexclude] = "DATETIME"
45
Andrew Geissler4b740dc2020-05-05 08:54:39 -050046def sanitise_value(ver):
47 # unquoted fields like VERSION_ID should be (from os-release(5)):
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050048 # lower-case string (mostly numeric, no spaces or other characters
49 # outside of 0-9, a-z, ".", "_" and "-")
50 ret = ver.replace('+', '-').replace(' ','_')
51 return ret.lower()
52
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053python do_compile () {
Patrick Williamsc124f4f2015-09-15 14:41:29 -050054 with open(d.expand('${B}/os-release'), 'w') as f:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050055 for field in d.getVar('OS_RELEASE_FIELDS').split():
Andrew Geissler4b740dc2020-05-05 08:54:39 -050056 unquotedFields = d.getVar('OS_RELEASE_UNQUOTED_FIELDS').split()
Brad Bishop6e60e8b2018-02-01 10:27:11 -050057 value = d.getVar(field)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050058 if value:
Andrew Geissler4b740dc2020-05-05 08:54:39 -050059 if field in unquotedFields:
60 value = sanitise_value(value)
61 f.write('{0}={1}\n'.format(field, value))
62 else:
63 f.write('{0}="{1}"\n'.format(field, value))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064}
65do_compile[vardeps] += "${OS_RELEASE_FIELDS}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050066
67do_install () {
Brad Bishop6f8dcde2018-10-16 10:47:12 +080068 install -d ${D}${nonarch_libdir} ${D}${sysconfdir}
69 install -m 0644 os-release ${D}${nonarch_libdir}/
Andrew Geissler595f6302022-01-24 19:11:47 +000070 ln -rs ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/os-release
Patrick Williamsde0582f2022-04-08 10:23:27 -050071 ln -rs ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/initrd-release
Patrick Williamsc124f4f2015-09-15 14:41:29 -050072}
Brad Bishopbba38f32018-08-23 16:11:46 +080073
Patrick Williamsde0582f2022-04-08 10:23:27 -050074FILES:${PN} = "${sysconfdir}/os-release ${nonarch_libdir}/os-release"
75
76PACKAGES += "${PN}-initrd"
77FILES:${PN}-initrd = "${sysconfdir}/initrd-release"
78RDEPENDS:${PN}-initrd += "${PN}"