blob: 0b1abd7886af3919b7b697670cc07447b14f9cf2 [file] [log] [blame]
Sean Abraham12ebc392020-11-19 15:45:30 -07001#!/bin/bash
2
3# Copyright 2020 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# Populates a directory with everything necessary to build a remote test driver
8# container.
9
Seewai Fu3f930a32020-12-29 17:27:29 -080010# BuildAndCopyTastItems builds and copies all Tast related executables
11# and data to targets.
12BuildAndCopyTastItems() {
13 # Emerge tast related executables.
14 sudo emerge tast-cmd
15 sudo emerge tast-remote-tests-cros
16 local tast_dir="$1/tast"
17 local tast_bin_dir="${tast_dir}/bin"
18 # Copy tast related items.
19 mkdir -p "${tast_bin_dir}"
20 cp /usr/bin/tast "${tast_bin_dir}"
21 cp /usr/bin/tast_rtd "${tast_bin_dir}"
22 cp /usr/bin/remote_test_runner "${tast_bin_dir}"
23 cp -pdr /usr/libexec/tast/bundles "${tast_dir}"
24 cp -pdr /usr/share/tast/data "${tast_dir}"
25 cp -pdr /etc/tast/vars "${tast_dir}"
26 cp -pdr /home/"${USER}"/trunk/chromite/ssh_keys "${tast_dir}"
27}
28
Sean Abraham12ebc392020-11-19 15:45:30 -070029readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
30. "${script_dir}/common.sh" || exit 1
31
32# Script must run inside the chroot
33assert_inside_chroot "$@"
34
35# Do not run as root
36assert_not_root_user
37
38DEFINE_string output_dir "" "Dir in which to put Dockerfile and dependencies"
39
40# Parse command line flags
41FLAGS "$@" || exit 1
42eval set -- "${FLAGS_ARGV}"
43
44# Only now can we die on error. shflags functions leak non-zero error codes,
45# so will die prematurely if 'switch_to_strict_mode' is specified before now.
46switch_to_strict_mode
47
48output_dir="${FLAGS_output_dir}"
49if [[ -z "${FLAGS_output_dir}" ]]; then
50 info "No --output_dir provided. Using temp dir instead"
51 output_dir=$(mktemp -d)
52fi
53
54if [[ ! -d "${output_dir}" ]]; then
55 error "output_dir ${output_dir} must exist as a directory"
56 exit 1
57fi
58
59if [[ -n "$(ls -A "${output_dir}")" ]]; then
60 error "output_dir ${output_dir} must be empty"
61 exit 1
62fi
63
64# Write out a simple Dockerfile.
65cat > "${output_dir}/Dockerfile" <<- EOF
66FROM ubuntu:bionic
67WORKDIR /usr/src/rtd/
68COPY rtd/ .
69EOF
70
71# Create the remote test driver folder and copy test content into it.
72rtd_dir="${output_dir}/rtd"
73mkdir "${rtd_dir}"
74# Build and copy the tnull (fake) RTD.
75sudo emerge tnull
76cp /usr/bin/tnull "${rtd_dir}/"
Seewai Fu3f930a32020-12-29 17:27:29 -080077
Sean Abraham12ebc392020-11-19 15:45:30 -070078# tast and tauto entries will eventually go here.
Seewai Fu3f930a32020-12-29 17:27:29 -080079BuildAndCopyTastItems "${rtd_dir}"
Sean Abraham12ebc392020-11-19 15:45:30 -070080
81command_completed
82info "Done. Wrote output to ${output_dir}"