• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2#
3# Copyright 2020 The ChromiumOS Authors
4# Use of this source code is governed by a BSD-style license that can be
5# found in the LICENSE file.
6#
7# This script ensures absence of a <!-- tainted --> tag in image's license.
8
9# Abort on error.
10set -e
11
12# Load common constants and variables.
13. "$(dirname "$0")/common.sh"
14
15usage() {
16  echo "Usage ${PROG} image"
17}
18
19main() {
20  if [[ $# -ne 1 ]]; then
21    usage
22    exit 1
23  fi
24
25  local image="$1"
26
27  local loopdev rootfs
28  if [[ -d "${image}" ]]; then
29    rootfs="${image}"
30  else
31    rootfs=$(make_temp_dir)
32    loopdev=$(loopback_partscan "${image}")
33    mount_loop_image_partition_ro "${loopdev}" 3 "${rootfs}"
34  fi
35
36  local license_dir license license_gz tainted_tag tainted_status
37  license_dir="${rootfs}/opt/google/chrome/"
38  if [[ ! -d "${license_dir}" ]]; then
39    echo "Directory ${license_dir} does not exist. Skipping the tainted check."
40    exit 0
41  fi
42
43  license=$(find "${license_dir}" -name about_os_credits.html 2>/dev/null)
44  license_gz=$(find "${license_dir}" -name about_os_credits.html.gz 2>/dev/null)
45  if [[ -n "${license_gz}" ]]; then
46    local tmpfile
47    tmpfile=$(make_temp_file)
48    gunzip --stdout "${license_gz}" > "${tmpfile}"
49    license="${tmpfile}"
50  fi
51  if [[ -z "${license}" ]]; then
52    echo "License file about_os_credits.html not found in ${license_dir}."
53    echo "Skipping the check of tainted license."
54    exit 0
55  fi
56
57  tainted_tag="<!-- tainted -->"
58  # Add "|| :" to the grep command to prevent it from returning error code 1 if
59  # no match is found, which would cause the script to exit immediately with
60  # error code 1 due to set -e.
61  tainted_status=$(grep "${tainted_tag}" "${license}") || :
62  if [[ -n "${tainted_status}" ]]; then
63    echo "${license}:"
64    echo "License file contains packages with LICENSE=TAINTED."
65    echo "Remove those packages or modify their license to allow signing."
66    # Print the list of tainted packages.
67    sed -n '/Image is TAINTED/,/<\/ul>/{
68      # Strip out HTML tags.
69      s/<[^>]*>//g
70      # Delete any empty lines.
71      /^[[:space:]]*$/d
72      p
73    }' "${license}"
74    exit 1
75  fi
76  exit 0
77}
78main "$@"
79