blob: f9b95c71840a7006802ea8a72c1ffc18b7b6d476 [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.
4# $Header: $
5
6# @ECLASS: crashid.eclass
7# @MAINTAINER:
8# Chromium OS crash reporter maintainers; see src/platform/crash-reporter/OWNERS
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 up GOOGLE_CRASH_ID and GOOGLE_CRASH_VERSION_ID in /etc/os-release
13#
14# @FUNCTION: docrashid
15# @USAGE: <crash_id> <crash_version_id>
16# @DESCRIPTION:
17# Initializes /etc/os-release with the crash id and crash version. Both
18# parameters are required to simplify the logic.
19# The inputs are restricted to [a-zA-Z.-_].
20# @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() {
30 [[ $# -eq 2 && -n $1 && -n $2 ]] || die "Usage: ${FUNCNAME} <crash_id> <crash_version_id"
31 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
41 dodir /etc
42
43 local os_release="${D}/etc/os-release"
44 [[ -e ${os_release} ]] && die "${os_release} already exists!"
45 cat <<-EOF > "${os_release}" || die "creating ${os_release} failed!"
46 GOOGLE_CRASH_ID=${crash_id}
47 GOOGLE_CRASH_VERSION_ID=${crash_version_id}
48 EOF
49}