blob: 0f4ed21203ec6fc4356c9aaae70057cbabe6d249 [file] [log] [blame]
Bertrand SIMONNET013f7ad2014-10-06 12:14:17 -07001# 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
Bertrand SIMONNET28354c42014-10-02 13:26:47 -07006inherit eutils
7
Bertrand SIMONNET013f7ad2014-10-06 12:14:17 -07008# @ECLASS: osreleased.eclass
9# @MAINTAINER:
10# Chromium OS build team;
11# @BUGREPORTS:
12# Please report bugs via http://crbug.com/new (with label Build)
13# @VCSURL: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/eclass/@ECLASS@
14# @BLURB: Eclass for setting fields in /etc/os-release.d/
15
16# @FUNCTION: do_osrelease_field
17# @USAGE: <field_name> <field_value>
18# @DESCRIPTION:
19# Creates a file named /etc/os-release.d/<file_name> containing <field_value>.
20# All files in os-release.d will be combined to create /etc/os-release when
21# building the image.
22do_osrelease_field() {
23 [[ $# -eq 2 && -n $1 && -n $2 ]] || die "Usage: ${FUNCNAME} <field_name> <field_value>"
24 local namevalidregex="[_A-Z]+"
25 local valuevalidregex="[^\n]+"
26
27 local field_name="$1"
28 local field_value="$2"
29
30 local filtered_name=$(echo "${field_name}" |\
31 LC_ALL=C sed -r "s:${namevalidregex}::")
32 local number_lines=$(echo "${field_value}" | wc -l)
33 if [[ -n "${filtered_name}" ]]; then
34 die "Invalid input. Field name must satisfy: ${validregex}"
35 fi
36 if [[ "${number_lines}" != "1" ]]; then
37 die "Invalid input. Field value must not contain new lines."
38 fi
39 dodir /etc/os-release.d
40
41 local field_file="${D}/etc/os-release.d/${field_name}"
42 [[ -e ${field_file} ]] && die "The field ${field_name} has already been set!"
43 echo "${field_value}" > "${field_file}" || \
44 die "creating ${os_release} failed!"
45}
Bertrand SIMONNET28354c42014-10-02 13:26:47 -070046
47# @FUNCTION: dometricsproductid
48# @USAGE: <product_id>
49# @DESCRIPTION:
50# Sets the GOOGLE_METRICS_PRODUCT_ID field in /etc/os-release.d/;
51# GOOGLE_METRICS_PRODUCT_ID should be a positive integer, matching the product
52# id defined by the UMA backend protobuf (chrome_user_metrics_extension.proto).
53# This product id will be used by chromeos-base/metrics to report metrics when
54# the metrics_uploader USE flag is set.
55# @CODE
56# dometricsproductid 12
57# @CODE
58# will write 12 in /etc/os-release.d/GOOGLE_METRICS_PRODUCT_ID.
59dometricsproductid() {
60 [[ $# -eq 1 && -n $1 ]] || die "Usage: ${FUNCNAME} <product_id>"
61 local product_id="$1"
62 isdigit "${product_id}" || die "The product id must be a number."
63
64 do_osrelease_field "GOOGLE_METRICS_PRODUCT_ID" "${product_id}"
65}