blob: 464baac0e1e1fe38696e7a43a109047ad7e11e08 [file] [log] [blame]
Alex Klein871392c2018-10-26 13:28:56 -06001#!/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
9SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
Alex Klein0ca5a932018-10-30 10:30:18 -060010SRC_DIR=$(realpath "${SCRIPT_ROOT}/../../")
11SCRIPTS_DIR="${SRC_DIR}/scripts"
12CHROMITE_DIR=$(realpath "${SRC_DIR}/../chromite")
13
14. "${SCRIPTS_DIR}/lib/shflags/shflags" || die "Couldn't find shflags"
Alex Klein871392c2018-10-26 13:28:56 -060015
16DEFAULT_PRIVATE_KEY="${SCRIPTS_DIR}/mod_for_test_scripts/ssh_keys/testing_rsa"
17
18# Flags
19DEFINE_string from "" "Directory with autotest tarball"
20DEFINE_string to "" "Directory to receive packaged hwqual"
21DEFINE_string output_tag "chromeos-hwqual" "Name used in tar"
22DEFINE_string image_dir "" "Directory containing test image."
Alex Klein0ca5a932018-10-30 10:30:18 -060023DEFINE_string image "chromiumos_test_image.bin" "Name of image file to use."
Alex Klein871392c2018-10-26 13:28:56 -060024DEFINE_string ssh_private_key "${DEFAULT_PRIVATE_KEY}" \
25 "Path to the private ssh key to use for testing"
26
27TMP=$(mktemp -d "/tmp/image.XXXX")
28
Alex Klein0ca5a932018-10-30 10:30:18 -060029# Detect whether we're inside a chroot or not.
30if [[ -e /etc/cros_chroot_version ]]; then
31 INSIDE_CHROOT=1
32else
33 INSIDE_CHROOT=0
34fi
35
Alex Klein871392c2018-10-26 13:28:56 -060036cleanup() {
37 rm -rf "${TMP}"
38}
39
40main() {
Alex Klein0ca5a932018-10-30 10:30:18 -060041 # 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 Klein871392c2018-10-26 13:28:56 -060052
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 Klein0ca5a932018-10-30 10:30:18 -060072 local script_dir=${SCRIPT_ROOT}
Alex Klein871392c2018-10-26 13:28:56 -060073
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 Klein0ca5a932018-10-30 10:30:18 -0600110 cp "${SRC_DIR}/third_party/autotest/files/site_utils/generate_test_report" \
Alex Klein871392c2018-10-26 13:28:56 -0600111 "tarball/${FLAGS_output_tag}/generate_test_report"
112 # Copy python lib used in generate_test_report.
Alex Klein0ca5a932018-10-30 10:30:18 -0600113 cp -a "${CHROMITE_DIR}" "tarball/${FLAGS_output_tag}"
Alex Klein871392c2018-10-26 13:28:56 -0600114 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
126main "$@"