| #!/bin/bash |
| # Copyright 2019 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| #### CATEGORY=Run, inspect and debug |
| ### generate a report of error conditions |
| |
| ## usage: fx triage [--config <config-file>] |
| ## [--bugreport <path-to-bugreport>] |
| ## Processes "fx bugreport" output looking for problems specified in a config |
| ## file. If no bugreport output is specified (no '--inspect') it runs a new |
| ## "fx bugreport" and uses its "inspect.json" file. |
| ## |
| ## --config <config-file-or-dir> Path to config file or dir |
| ## --data <bugreport-or-dir> Path to bugreport.zip or uncompressed dir |
| ## --tag <tag> Adds an action tag to include |
| ## --exclude-tag <tag> Adds an action tag to exclude |
| ## --test (deprecated) Run self-tests (only) |
| ## |
| ## 0 or more --config paths may be given. Path is relative to CWD, or absolute. |
| ## If path is a directory, path/*.triage will be loaded. |
| ## If 0 paths are given, config defaults to |
| ## /src/diagnostics/config/triage/*.triage. |
| ## |
| ## 0 or more --tag values may be given. If tags are provided, only actions with |
| ## matching tags will be included. |
| ## |
| ## 0 or more --exclude-tag values may be given. If exclude tags are provided, |
| ## actions with matching tags will be excluded. This value is ignored if |
| ## any --tag values are included. |
| ## |
| ## If no --tag values or --exclude-tag values are included then all of the |
| ## actions will be included. |
| ## |
| ## 0 or 1 --data paths may be given. |
| ## Path must point to a bugreport.zip or a directory containing an unpacked bugreport.zip. |
| ## For this path, 'fx triage' will analyze all supported filetypes. |
| ## Currently, the only supported filetype is inspect.json. |
| ## Future versions will add support for different files. |
| ## If no --data is given,`fx bugreport` will be invoked and analyzed. |
| |
| set -e |
| trap 'echo Failed: ${BASH_COMMAND}' ERR |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"\ |
| /../lib/image_build_vars.sh |
| |
| # Defaults. |
| config_paths=( ) |
| testit="" |
| data_paths=( ) |
| tags=( ) |
| exclude_tags=( ) |
| flags="" |
| |
| # Flag parsing. |
| while [[ "$1" =~ ^- ]]; do |
| case "$1" in |
| -h|--help) |
| fx-command-help |
| exit 0 |
| ;; |
| --config) |
| shift |
| config_paths+=( "$1" ) |
| ;; |
| --data) |
| shift |
| data_paths+=( "$1" ) |
| ;; |
| --tag) |
| shift |
| tags+=( "$1" ) |
| ;; |
| --exclude-tag) |
| shift |
| exclude_tags+=( "$1" ) |
| ;; |
| --test) |
| testit="yes" |
| ;; |
| *) |
| echo Bad option "$1" |
| echo |
| fx-command-help |
| exit 1 |
| esac |
| shift |
| done |
| |
| triage_exe="${HOST_OUT_DIR}/../host-tools/triage" |
| |
| if [[ -n "$testit" ]]; then |
| echo "[ERROR] fx triage --test is deprecated!" |
| echo "please use 'fx test triage_lib_test' instead" |
| exit |
| fi |
| |
| if (( !"${#config_paths[@]}" )); then |
| config_paths=( "${FUCHSIA_DIR}/src/diagnostics/config/triage/" ) |
| fi |
| |
| config_files=( ) |
| for config_path in "${config_paths[@]}"; do |
| if [[ -d "${config_path}" ]] ; then |
| config_files+=( "${config_path}"/*.triage ) |
| else |
| config_files+=( "${config_path}" ) |
| fi |
| done |
| |
| for config_file in "${config_files[@]}" |
| do |
| flags="${flags} --config ${config_file}" |
| done |
| |
| if [ -z "${data_paths}" ]; then |
| temp_dir=$(mktemp -d) |
| trap 'rm -rf "${temp_dir}"' EXIT |
| fx-command-run bugreport --output-directory "${temp_dir}" > /dev/null |
| unzip "${temp_dir}/bugreport.zip" -d "${temp_dir}" > /dev/null |
| data_paths+="${temp_dir}" |
| fi |
| |
| for data_path in "${data_paths[@]}" |
| do |
| if [[ -d "${data_path}" ]] ; then |
| # This should be an unzipped bugreport.zip; pass it to the Triage |
| # executable. |
| # Triage will complain if bugreport.zip files aren't in the directory. |
| flags="${flags} --data ${data_path}" |
| else |
| # This should be a .zip file. unzip will complain if not. Unzip it and |
| # pass its contents to the Triage executable. |
| temp_dir=$(mktemp -d) |
| trap 'rm -rf "${temp_dir}"' EXIT |
| unzip "${data_path}" -d "${temp_dir}" > /dev/null |
| flags="${flags} --data ${temp_dir}" |
| fi |
| done |
| |
| for tag in "${tags[@]}" |
| do |
| flags="${flags} --tag ${tag}" |
| done |
| |
| for tag in "${exclude_tags[@]}" |
| do |
| flags="${flags} --exclude-tag ${tag}" |
| done |
| |
| if [[ ! -f "$triage_exe" ]]; then |
| echo "Building Triage..." |
| fx-command-run build triage |
| fi |
| |
| echo "${triage_exe} ${flags}" |
| $triage_exe ${flags} |