Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inherit allarch |
| 2 | |
| 3 | SUMMARY = "Operating system identification" |
Brad Bishop | bba38f3 | 2018-08-23 16:11:46 +0800 | [diff] [blame] | 4 | DESCRIPTION = "The /usr/lib/os-release file contains operating system identification data." |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 5 | HOMEPAGE = "https://www.freedesktop.org/software/systemd/man/os-release.html" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | LICENSE = "MIT" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | INHIBIT_DEFAULT_DEPS = "1" |
| 8 | |
| 9 | do_fetch[noexec] = "1" |
| 10 | do_unpack[noexec] = "1" |
| 11 | do_patch[noexec] = "1" |
| 12 | do_configure[noexec] = "1" |
| 13 | |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 14 | # See: https://www.freedesktop.org/software/systemd/man/os-release.html |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | # Other valid fields: BUILD_ID ID_LIKE ANSI_COLOR CPE_NAME |
| 16 | # HOME_URL SUPPORT_URL BUG_REPORT_URL |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 17 | OS_RELEASE_FIELDS = "\ |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 18 | ID ID_LIKE NAME VERSION VERSION_ID VERSION_CODENAME PRETTY_NAME \ |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 19 | CPE_NAME \ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 20 | " |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 21 | OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 22 | |
| 23 | ID = "${DISTRO}" |
| 24 | NAME = "${DISTRO_NAME}" |
| 25 | VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if 'DISTRO_CODENAME' in d else ''}" |
| 26 | VERSION_ID = "${DISTRO_VERSION}" |
Patrick Williams | 2390b1b | 2022-11-03 13:47:49 -0500 | [diff] [blame] | 27 | VERSION_CODENAME = "${DISTRO_CODENAME}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 28 | PRETTY_NAME = "${DISTRO_NAME} ${VERSION}" |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 29 | |
| 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 | |
| 40 | CPE_DISTRO ??= "${DISTRO}" |
| 41 | CPE_NAME="cpe:/o:openembedded:${CPE_DISTRO}:${VERSION_ID}" |
| 42 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | BUILD_ID ?= "${DATETIME}" |
| 44 | BUILD_ID[vardepsexclude] = "DATETIME" |
| 45 | |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 46 | def sanitise_value(ver): |
| 47 | # unquoted fields like VERSION_ID should be (from os-release(5)): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 48 | # 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | python do_compile () { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | with open(d.expand('${B}/os-release'), 'w') as f: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 55 | for field in d.getVar('OS_RELEASE_FIELDS').split(): |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 56 | unquotedFields = d.getVar('OS_RELEASE_UNQUOTED_FIELDS').split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 57 | value = d.getVar(field) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 58 | if value: |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 59 | 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 64 | } |
| 65 | do_compile[vardeps] += "${OS_RELEASE_FIELDS}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 66 | |
| 67 | do_install () { |
Brad Bishop | 6f8dcde | 2018-10-16 10:47:12 +0800 | [diff] [blame] | 68 | install -d ${D}${nonarch_libdir} ${D}${sysconfdir} |
| 69 | install -m 0644 os-release ${D}${nonarch_libdir}/ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 70 | ln -rs ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/os-release |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 71 | ln -rs ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/initrd-release |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | } |
Brad Bishop | bba38f3 | 2018-08-23 16:11:46 +0800 | [diff] [blame] | 73 | |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 74 | FILES:${PN} = "${sysconfdir}/os-release ${nonarch_libdir}/os-release" |
| 75 | |
| 76 | PACKAGES += "${PN}-initrd" |
| 77 | FILES:${PN}-initrd = "${sysconfdir}/initrd-release" |
| 78 | RDEPENDS:${PN}-initrd += "${PN}" |