Alex Klein | 871392c | 2018-10-26 13:28:56 -0600 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 | # Use of this source code is governed by a BSD-style license that can be |
| 5 | # found in the LICENSE file. |
| 6 | |
| 7 | # Script to take an archived build result and prepare a hwqual release. |
| 8 | |
| 9 | SCRIPT_ROOT=$(dirname $(readlink -f "$0")) |
Alex Klein | 0ca5a93 | 2018-10-30 10:30:18 -0600 | [diff] [blame] | 10 | SRC_DIR=$(realpath "${SCRIPT_ROOT}/../../") |
| 11 | SCRIPTS_DIR="${SRC_DIR}/scripts" |
| 12 | CHROMITE_DIR=$(realpath "${SRC_DIR}/../chromite") |
| 13 | |
| 14 | . "${SCRIPTS_DIR}/lib/shflags/shflags" || die "Couldn't find shflags" |
Alex Klein | 871392c | 2018-10-26 13:28:56 -0600 | [diff] [blame] | 15 | |
| 16 | DEFAULT_PRIVATE_KEY="${SCRIPTS_DIR}/mod_for_test_scripts/ssh_keys/testing_rsa" |
| 17 | |
| 18 | # Flags |
| 19 | DEFINE_string from "" "Directory with autotest tarball" |
| 20 | DEFINE_string to "" "Directory to receive packaged hwqual" |
| 21 | DEFINE_string output_tag "chromeos-hwqual" "Name used in tar" |
| 22 | DEFINE_string image_dir "" "Directory containing test image." |
Alex Klein | 0ca5a93 | 2018-10-30 10:30:18 -0600 | [diff] [blame] | 23 | DEFINE_string image "chromiumos_test_image.bin" "Name of image file to use." |
Alex Klein | 871392c | 2018-10-26 13:28:56 -0600 | [diff] [blame] | 24 | DEFINE_string ssh_private_key "${DEFAULT_PRIVATE_KEY}" \ |
| 25 | "Path to the private ssh key to use for testing" |
| 26 | |
| 27 | TMP=$(mktemp -d "/tmp/image.XXXX") |
| 28 | |
Alex Klein | 0ca5a93 | 2018-10-30 10:30:18 -0600 | [diff] [blame] | 29 | # Detect whether we're inside a chroot or not. |
| 30 | if [[ -e /etc/cros_chroot_version ]]; then |
| 31 | INSIDE_CHROOT=1 |
| 32 | else |
| 33 | INSIDE_CHROOT=0 |
| 34 | fi |
| 35 | |
Alex Klein | 871392c | 2018-10-26 13:28:56 -0600 | [diff] [blame] | 36 | cleanup() { |
| 37 | rm -rf "${TMP}" |
| 38 | } |
| 39 | |
| 40 | main() { |
Alex Klein | 0ca5a93 | 2018-10-30 10:30:18 -0600 | [diff] [blame] | 41 | # Assert outside chroot. |
| 42 | if [[ ${INSIDE_CHROOT} -ne 0 ]]; then |
| 43 | echo "This script must be run outside the chroot" |
| 44 | exit 1 |
| 45 | fi |
| 46 | |
| 47 | # Assert not root user. |
| 48 | if [[ ${UID:-$(id -u)} == 0 ]]; then |
| 49 | echo "This script must be run as a non-root user." |
| 50 | exit 1 |
| 51 | fi |
Alex Klein | 871392c | 2018-10-26 13:28:56 -0600 | [diff] [blame] | 52 | |
| 53 | # Parse command line |
| 54 | FLAGS "$@" || exit 1 |
| 55 | eval set -- "${FLAGS_ARGV}" |
| 56 | switch_to_strict_mode |
| 57 | |
| 58 | if [[ -z "${FLAGS_from}" ]]; then |
| 59 | die "Please specify --from directory" |
| 60 | fi |
| 61 | |
| 62 | if [[ -z "${FLAGS_image_dir}" ]]; then |
| 63 | die "Please specify --image_dir directory" |
| 64 | fi |
| 65 | |
| 66 | FLAGS_from=$(readlink -f "${FLAGS_from}") |
| 67 | |
| 68 | if [[ -z "${FLAGS_to}" ]]; then |
| 69 | FLAGS_to="${FLAGS_from}" |
| 70 | fi |
| 71 | |
Alex Klein | 0ca5a93 | 2018-10-30 10:30:18 -0600 | [diff] [blame] | 72 | local script_dir=${SCRIPT_ROOT} |
Alex Klein | 871392c | 2018-10-26 13:28:56 -0600 | [diff] [blame] | 73 | |
| 74 | script_dir=$(readlink -f "${script_dir}") |
| 75 | |
| 76 | trap cleanup EXIT |
| 77 | |
| 78 | cd "${TMP}" |
| 79 | |
| 80 | echo "Extracting build artifacts..." |
| 81 | mkdir -p "tarball/${FLAGS_output_tag}" |
| 82 | |
| 83 | if which pbzip2 >/dev/null 2>/dev/null; then |
| 84 | TAR_BZIP2="tar --use-compress-program=pbzip2" |
| 85 | else |
| 86 | TAR_BZIP2="tar --bzip2" |
| 87 | fi |
| 88 | |
| 89 | echo "Extracting autotest from archived autotest tarball..." |
| 90 | ${TAR_BZIP2} -xf "${FLAGS_from}/autotest.tar.bz2" |
| 91 | |
| 92 | cd "${TMP}" |
| 93 | |
| 94 | echo "Copying image..." |
| 95 | cp "${FLAGS_image_dir}/${FLAGS_image}" \ |
| 96 | "tarball/${FLAGS_output_tag}/chromeos-hwqual-usb.img" |
| 97 | |
| 98 | echo "Inserting documentation and autotest to tarball..." |
| 99 | ln -s \ |
| 100 | "${FLAGS_output_tag}/autotest/client/site_tests/suite_HWQual/README.txt" \ |
| 101 | tarball |
| 102 | ln -s autotest/client/site_tests/suite_HWQual/manual \ |
| 103 | "tarball/${FLAGS_output_tag}" |
| 104 | cp $(readlink -f "${FLAGS_ssh_private_key}") \ |
| 105 | "tarball/${FLAGS_output_tag}/testing_rsa" |
| 106 | chmod 0400 "tarball/${FLAGS_output_tag}/testing_rsa" |
| 107 | mv autotest "tarball/${FLAGS_output_tag}" |
| 108 | # Copy call_autoserv.py to tarball. |
| 109 | cp "${script_dir}/call_autoserv.py" "tarball/${FLAGS_output_tag}/." |
Alex Klein | 0ca5a93 | 2018-10-30 10:30:18 -0600 | [diff] [blame] | 110 | cp "${SRC_DIR}/third_party/autotest/files/site_utils/generate_test_report" \ |
Alex Klein | 871392c | 2018-10-26 13:28:56 -0600 | [diff] [blame] | 111 | "tarball/${FLAGS_output_tag}/generate_test_report" |
| 112 | # Copy python lib used in generate_test_report. |
Alex Klein | 0ca5a93 | 2018-10-30 10:30:18 -0600 | [diff] [blame] | 113 | cp -a "${CHROMITE_DIR}" "tarball/${FLAGS_output_tag}" |
Alex Klein | 871392c | 2018-10-26 13:28:56 -0600 | [diff] [blame] | 114 | echo "Creating ${FLAGS_to}/${FLAGS_output_tag}.tar.bz2..." |
| 115 | mkdir -p "${FLAGS_to}" |
| 116 | cd tarball |
| 117 | ${TAR_BZIP2} -cf "${FLAGS_to}/${FLAGS_output_tag}.tar.bz2" . |
| 118 | |
| 119 | trap - EXIT |
| 120 | cleanup |
| 121 | |
| 122 | echo "Done." |
| 123 | cd "${script_dir}" |
| 124 | } |
| 125 | |
| 126 | main "$@" |