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 = "ID ID_LIKE NAME VERSION VERSION_ID PRETTY_NAME"
16OS_RELEASE_UNQUOTED_FIELDS = "ID VERSION_ID VARIANT_ID"
17
18ID = "${DISTRO}"
19NAME = "${DISTRO_NAME}"
20VERSION = "${DISTRO_VERSION}${@' (%s)' % DISTRO_CODENAME if 'DISTRO_CODENAME' in d else ''}"
21VERSION_ID = "${DISTRO_VERSION}"
22PRETTY_NAME = "${DISTRO_NAME} ${VERSION}"
23BUILD_ID ?= "${DATETIME}"
24BUILD_ID[vardepsexclude] = "DATETIME"
25
26def sanitise_value(ver):
27    # unquoted fields like VERSION_ID should be (from os-release(5)):
28    #    lower-case string (mostly numeric, no spaces or other characters
29    #    outside of 0-9, a-z, ".", "_" and "-")
30    ret = ver.replace('+', '-').replace(' ','_')
31    return ret.lower()
32
33python do_compile () {
34    with open(d.expand('${B}/os-release'), 'w') as f:
35        for field in d.getVar('OS_RELEASE_FIELDS').split():
36            unquotedFields = d.getVar('OS_RELEASE_UNQUOTED_FIELDS').split()
37            value = d.getVar(field)
38            if value:
39                if field in unquotedFields:
40                    value = sanitise_value(value)
41                    f.write('{0}={1}\n'.format(field, value))
42                else:
43                    f.write('{0}="{1}"\n'.format(field, value))
44}
45do_compile[vardeps] += "${OS_RELEASE_FIELDS}"
46
47do_install () {
48    install -d ${D}${nonarch_libdir} ${D}${sysconfdir}
49    install -m 0644 os-release ${D}${nonarch_libdir}/
50    lnr ${D}${nonarch_libdir}/os-release ${D}${sysconfdir}/os-release
51}
52
53FILES:${PN} += "${nonarch_libdir}/os-release"
54