[yocto] Making /etc/os-release loadable by shell script

Craig McQueen craig.mcqueen at innerrange.com
Thu Jul 2 01:00:43 PDT 2015


It would be good if the /etc/os-release file (created by the core os-release package) could be loadable by a shell script. That is, a shell script can do:

    source /etc/os-release
or
    . /etc/os-release

But it's currently not possible, because the file lacks double-quotes around values that would make it valid shell assignment syntax.

Compare to a Debian or Ubuntu /etc/os-release, which has double-quotes around values, so it _can_ be loaded by a shell script.

To achieve this, I am using the following in an os-release.bbappend. It just adds double-quotes around the {1} in the 2nd-last line.

    # Ensure all variables' data are in quotes
    python do_compile () {
        with open(d.expand('${B}/os-release'), 'w') as f:
            for field in d.getVar('OS_RELEASE_FIELDS', True).split():
                value = d.getVar(field, True)
                if value:
                    f.write('{0}="{1}"\n'.format(field, value))
    }

-- 
Craig McQueen




More information about the yocto mailing list