1inherit allarch
2
3SUMMARY = "Operating system identification"
4DESCRIPTION = "The /usr/lib/os-release file contains operating system identification data."
5LICENSE = "MIT"
6INHIBIT_DEFAULT_DEPS = "1"
7
8do_fetch[noexec] = "1"
9do_unpack[noexec] = "1"
10do_patch[noexec] = "1"
11do_configure[noexec] = "1"
12
13# Other valid fields: BUILD_ID ID_LIKE ANSI_COLOR CPE_NAME
14#                     HOME_URL SUPPORT_URL BUG_REPORT_URL
15OS_RELEASE_FIELDS = "\
16    ID ID_LIKE NAME VERSION VERSION_ID PRETTY_NAME DISTRO_CODENAME \
17"
18OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID"
19
20ID = "${DISTRO}"
21NAME = "${DISTRO_NAME}"
22VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if 'DISTRO_CODENAME' in d else ''}"
23VERSION_ID = "${DISTRO_VERSION}"
24PRETTY_NAME = "${DISTRO_NAME} ${VERSION}"
25BUILD_ID ?= "${DATETIME}"
26BUILD_ID[vardepsexclude] = "DATETIME"
27
28def sanitise_value(ver):
29    # unquoted fields like VERSION_ID should be (from os-release(5)):
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
35python do_compile () {
36    with open(d.expand('${B}/os-release'), 'w') as f:
37        for field in d.getVar('OS_RELEASE_FIELDS').split():
38            unquotedFields = d.getVar('OS_RELEASE_UNQUOTED_FIELDS').split()
39            value = d.getVar(field)
40            if value:
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))
46}
47do_compile[vardeps] += "${OS_RELEASE_FIELDS}"
48
49do_install () {
50    install -d ${D}${nonarch_libdir} ${D}${sysconfdir}
51    install -m 0644 os-release ${D}${nonarch_libdir}/
52    ln -rs ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/os-release
53    ln -rs ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/initrd-release
54}
55
56FILES:${PN} = "${sysconfdir}/os-release ${nonarch_libdir}/os-release"
57
58PACKAGES += "${PN}-initrd"
59FILES:${PN}-initrd = "${sysconfdir}/initrd-release"
60RDEPENDS:${PN}-initrd += "${PN}"
61