blob: d459fc9b496798ebae2215ef3a20f020533c3837 [file] [log] [blame]
B. simonnetacc11eb2014-02-18 16:55:38 -08001# Copyright (c) 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.
Andrey Ulanov75d14a02016-04-27 15:39:07 -07004
5inherit osreleased
B. simonnetacc11eb2014-02-18 16:55:38 -08006
7# @ECLASS: crashid.eclass
8# @MAINTAINER:
9# Chromium OS crash reporter maintainers; see src/platform/crash-reporter/OWNERS
10# @BUGREPORTS:
11# Please report bugs via http://crbug.com/new (with label Build)
12# @VCSURL: https://chromium.googlesource.com/chromiumos/overlays/chromiumos-overlay/+/master/eclass/@ECLASS@
13# @BLURB: Eclass for setting up GOOGLE_CRASH_ID and GOOGLE_CRASH_VERSION_ID in /etc/os-release
14#
15# @FUNCTION: docrashid
Bertrand SIMONNETc404bbb2015-02-18 17:43:09 -080016# @USAGE: <crash_id> [<crash_version_id>]
B. simonnetacc11eb2014-02-18 16:55:38 -080017# @DESCRIPTION:
Bertrand SIMONNETc404bbb2015-02-18 17:43:09 -080018# Initializes /etc/os-release with the crash id and crash version (optional).
19# Both the crash id and version are restricted to [a-zA-Z.-_].
B. simonnetacc11eb2014-02-18 16:55:38 -080020# @CODE
21# docrashid chromeos first_version
22# @CODE
23# will add
24# @CODE
25# GOOGLE_CRASH_ID=chromeos
26# GOOGLE_CRASH_VERSION_ID=first_version
27# @CODE
28# to /etc/os-release.
29docrashid() {
Bertrand SIMONNETc404bbb2015-02-18 17:43:09 -080030 [[ $# -lt 3 && $# -gt 0 && -n $1 ]] || die "Usage: ${FUNCNAME} <crash_id> [<crash_version_id>]"
B. simonnetacc11eb2014-02-18 16:55:38 -080031 local validregex="[-._a-zA-Z]+"
Bertrand SIMONNET9b715702014-10-06 12:10:42 -070032 local crash_id="$1"
33 local crash_version_id="$2"
34 local filtered_id=$(echo "${crash_id}" | \
35 LC_ALL=C sed -r "s:${validregex}::")
36 local filtered_version_id=$(echo "${crash_version_id}" | \
37 LC_ALL=C sed -r "s:${validregex}::")
38 if [[ -n ${filtered_id} || -n ${filtered_version_id} ]]; then
B. simonnetacc11eb2014-02-18 16:55:38 -080039 die "Invalid input. Must satisfy: ${validregex}"
40 fi
B. simonnetacc11eb2014-02-18 16:55:38 -080041
Andrey Ulanov75d14a02016-04-27 15:39:07 -070042 do_osrelease_field GOOGLE_CRASH_ID "${crash_id}"
Bertrand SIMONNETc404bbb2015-02-18 17:43:09 -080043 if [[ -n "${crash_version_id}" ]]; then
Andrey Ulanov75d14a02016-04-27 15:39:07 -070044 do_osrelease_field GOOGLE_CRASH_VERSION_ID "${crash_version_id}"
Bertrand SIMONNETc404bbb2015-02-18 17:43:09 -080045 fi
B. simonnetacc11eb2014-02-18 16:55:38 -080046}