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 | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 5 | LICENSE = "MIT" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | INHIBIT_DEFAULT_DEPS = "1" |
| 7 | |
| 8 | do_fetch[noexec] = "1" |
| 9 | do_unpack[noexec] = "1" |
| 10 | do_patch[noexec] = "1" |
| 11 | do_configure[noexec] = "1" |
| 12 | |
| 13 | # Other valid fields: BUILD_ID ID_LIKE ANSI_COLOR CPE_NAME |
| 14 | # HOME_URL SUPPORT_URL BUG_REPORT_URL |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 15 | OS_RELEASE_FIELDS = "\ |
| 16 | ID ID_LIKE NAME VERSION VERSION_ID PRETTY_NAME DISTRO_CODENAME \ |
| 17 | " |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 18 | OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | |
| 20 | ID = "${DISTRO}" |
| 21 | NAME = "${DISTRO_NAME}" |
| 22 | VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if 'DISTRO_CODENAME' in d else ''}" |
| 23 | VERSION_ID = "${DISTRO_VERSION}" |
| 24 | PRETTY_NAME = "${DISTRO_NAME} ${VERSION}" |
| 25 | BUILD_ID ?= "${DATETIME}" |
| 26 | BUILD_ID[vardepsexclude] = "DATETIME" |
| 27 | |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 28 | def sanitise_value(ver): |
| 29 | # unquoted fields like VERSION_ID should be (from os-release(5)): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 30 | # lower-case string (mostly numeric, no spaces or other characters |
| 31 | # outside of 0-9, a-z, ".", "_" and "-") |
| 32 | ret = ver.replace('+', '-').replace(' ','_') |
| 33 | return ret.lower() |
| 34 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 35 | python do_compile () { |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 36 | with open(d.expand('${B}/os-release'), 'w') as f: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 37 | for field in d.getVar('OS_RELEASE_FIELDS').split(): |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 38 | unquotedFields = d.getVar('OS_RELEASE_UNQUOTED_FIELDS').split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | value = d.getVar(field) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | if value: |
Andrew Geissler | 4b740dc | 2020-05-05 08:54:39 -0500 | [diff] [blame] | 41 | if field in unquotedFields: |
| 42 | value = sanitise_value(value) |
| 43 | f.write('{0}={1}\n'.format(field, value)) |
| 44 | else: |
| 45 | f.write('{0}="{1}"\n'.format(field, value)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | } |
| 47 | do_compile[vardeps] += "${OS_RELEASE_FIELDS}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | |
| 49 | do_install () { |
Brad Bishop | 6f8dcde | 2018-10-16 10:47:12 +0800 | [diff] [blame] | 50 | install -d ${D}${nonarch_libdir} ${D}${sysconfdir} |
| 51 | install -m 0644 os-release ${D}${nonarch_libdir}/ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 52 | ln -rs ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/os-release |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 53 | ln -rs ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/initrd-release |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 54 | } |
Brad Bishop | bba38f3 | 2018-08-23 16:11:46 +0800 | [diff] [blame] | 55 | |
Patrick Williams | de0582f | 2022-04-08 10:23:27 -0500 | [diff] [blame] | 56 | FILES:${PN} = "${sysconfdir}/os-release ${nonarch_libdir}/os-release" |
| 57 | |
| 58 | PACKAGES += "${PN}-initrd" |
| 59 | FILES:${PN}-initrd = "${sysconfdir}/initrd-release" |
| 60 | RDEPENDS:${PN}-initrd += "${PN}" |