blob: 464baac0e1e1fe38696e7a43a109047ad7e11e08 [file] [log] [blame]
#!/bin/bash
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Script to take an archived build result and prepare a hwqual release.
SCRIPT_ROOT=$(dirname $(readlink -f "$0"))
SRC_DIR=$(realpath "${SCRIPT_ROOT}/../../")
SCRIPTS_DIR="${SRC_DIR}/scripts"
CHROMITE_DIR=$(realpath "${SRC_DIR}/../chromite")
. "${SCRIPTS_DIR}/lib/shflags/shflags" || die "Couldn't find shflags"
DEFAULT_PRIVATE_KEY="${SCRIPTS_DIR}/mod_for_test_scripts/ssh_keys/testing_rsa"
# Flags
DEFINE_string from "" "Directory with autotest tarball"
DEFINE_string to "" "Directory to receive packaged hwqual"
DEFINE_string output_tag "chromeos-hwqual" "Name used in tar"
DEFINE_string image_dir "" "Directory containing test image."
DEFINE_string image "chromiumos_test_image.bin" "Name of image file to use."
DEFINE_string ssh_private_key "${DEFAULT_PRIVATE_KEY}" \
"Path to the private ssh key to use for testing"
TMP=$(mktemp -d "/tmp/image.XXXX")
# Detect whether we're inside a chroot or not.
if [[ -e /etc/cros_chroot_version ]]; then
INSIDE_CHROOT=1
else
INSIDE_CHROOT=0
fi
cleanup() {
rm -rf "${TMP}"
}
main() {
# Assert outside chroot.
if [[ ${INSIDE_CHROOT} -ne 0 ]]; then
echo "This script must be run outside the chroot"
exit 1
fi
# Assert not root user.
if [[ ${UID:-$(id -u)} == 0 ]]; then
echo "This script must be run as a non-root user."
exit 1
fi
# Parse command line
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
switch_to_strict_mode
if [[ -z "${FLAGS_from}" ]]; then
die "Please specify --from directory"
fi
if [[ -z "${FLAGS_image_dir}" ]]; then
die "Please specify --image_dir directory"
fi
FLAGS_from=$(readlink -f "${FLAGS_from}")
if [[ -z "${FLAGS_to}" ]]; then
FLAGS_to="${FLAGS_from}"
fi
local script_dir=${SCRIPT_ROOT}
script_dir=$(readlink -f "${script_dir}")
trap cleanup EXIT
cd "${TMP}"
echo "Extracting build artifacts..."
mkdir -p "tarball/${FLAGS_output_tag}"
if which pbzip2 >/dev/null 2>/dev/null; then
TAR_BZIP2="tar --use-compress-program=pbzip2"
else
TAR_BZIP2="tar --bzip2"
fi
echo "Extracting autotest from archived autotest tarball..."
${TAR_BZIP2} -xf "${FLAGS_from}/autotest.tar.bz2"
cd "${TMP}"
echo "Copying image..."
cp "${FLAGS_image_dir}/${FLAGS_image}" \
"tarball/${FLAGS_output_tag}/chromeos-hwqual-usb.img"
echo "Inserting documentation and autotest to tarball..."
ln -s \
"${FLAGS_output_tag}/autotest/client/site_tests/suite_HWQual/README.txt" \
tarball
ln -s autotest/client/site_tests/suite_HWQual/manual \
"tarball/${FLAGS_output_tag}"
cp $(readlink -f "${FLAGS_ssh_private_key}") \
"tarball/${FLAGS_output_tag}/testing_rsa"
chmod 0400 "tarball/${FLAGS_output_tag}/testing_rsa"
mv autotest "tarball/${FLAGS_output_tag}"
# Copy call_autoserv.py to tarball.
cp "${script_dir}/call_autoserv.py" "tarball/${FLAGS_output_tag}/."
cp "${SRC_DIR}/third_party/autotest/files/site_utils/generate_test_report" \
"tarball/${FLAGS_output_tag}/generate_test_report"
# Copy python lib used in generate_test_report.
cp -a "${CHROMITE_DIR}" "tarball/${FLAGS_output_tag}"
echo "Creating ${FLAGS_to}/${FLAGS_output_tag}.tar.bz2..."
mkdir -p "${FLAGS_to}"
cd tarball
${TAR_BZIP2} -cf "${FLAGS_to}/${FLAGS_output_tag}.tar.bz2" .
trap - EXIT
cleanup
echo "Done."
cd "${script_dir}"
}
main "$@"