Bertrand SIMONNET | 013f7ad | 2014-10-06 12:14:17 -0700 | [diff] [blame^] | 1 | # Copyright 2014 The Chromium OS Authors. All rights reserved. |
| 2 | # Use of this source code is governed by a BSD-style license that can be |
| 3 | # found in the LICENSE file. |
| 4 | # $Header: $ |
| 5 | |
| 6 | # @ECLASS: osreleased.eclass |
| 7 | # @MAINTAINER: |
| 8 | # Chromium OS build team; |
| 9 | # @BUGREPORTS: |
| 10 | # Please report bugs via http://crbug.com/new (with label Build) |
| 11 | # @VCSURL: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/eclass/@ECLASS@ |
| 12 | # @BLURB: Eclass for setting fields in /etc/os-release.d/ |
| 13 | |
| 14 | # @FUNCTION: do_osrelease_field |
| 15 | # @USAGE: <field_name> <field_value> |
| 16 | # @DESCRIPTION: |
| 17 | # Creates a file named /etc/os-release.d/<file_name> containing <field_value>. |
| 18 | # All files in os-release.d will be combined to create /etc/os-release when |
| 19 | # building the image. |
| 20 | do_osrelease_field() { |
| 21 | [[ $# -eq 2 && -n $1 && -n $2 ]] || die "Usage: ${FUNCNAME} <field_name> <field_value>" |
| 22 | local namevalidregex="[_A-Z]+" |
| 23 | local valuevalidregex="[^\n]+" |
| 24 | |
| 25 | local field_name="$1" |
| 26 | local field_value="$2" |
| 27 | |
| 28 | local filtered_name=$(echo "${field_name}" |\ |
| 29 | LC_ALL=C sed -r "s:${namevalidregex}::") |
| 30 | local number_lines=$(echo "${field_value}" | wc -l) |
| 31 | if [[ -n "${filtered_name}" ]]; then |
| 32 | die "Invalid input. Field name must satisfy: ${validregex}" |
| 33 | fi |
| 34 | if [[ "${number_lines}" != "1" ]]; then |
| 35 | die "Invalid input. Field value must not contain new lines." |
| 36 | fi |
| 37 | dodir /etc/os-release.d |
| 38 | |
| 39 | local field_file="${D}/etc/os-release.d/${field_name}" |
| 40 | [[ -e ${field_file} ]] && die "The field ${field_name} has already been set!" |
| 41 | echo "${field_value}" > "${field_file}" || \ |
| 42 | die "creating ${os_release} failed!" |
| 43 | } |