Sean Abraham | 12ebc39 | 2020-11-19 15:45:30 -0700 | [diff] [blame] | 1 | #!/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 | |
| 10 | readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")" |
| 11 | . "${script_dir}/common.sh" || exit 1 |
| 12 | |
| 13 | # Script must run inside the chroot |
| 14 | assert_inside_chroot "$@" |
| 15 | |
| 16 | # Do not run as root |
| 17 | assert_not_root_user |
| 18 | |
| 19 | DEFINE_string output_dir "" "Dir in which to put Dockerfile and dependencies" |
| 20 | |
| 21 | # Parse command line flags |
| 22 | FLAGS "$@" || exit 1 |
| 23 | eval set -- "${FLAGS_ARGV}" |
| 24 | |
| 25 | # Only now can we die on error. shflags functions leak non-zero error codes, |
| 26 | # so will die prematurely if 'switch_to_strict_mode' is specified before now. |
| 27 | switch_to_strict_mode |
| 28 | |
| 29 | output_dir="${FLAGS_output_dir}" |
| 30 | if [[ -z "${FLAGS_output_dir}" ]]; then |
| 31 | info "No --output_dir provided. Using temp dir instead" |
| 32 | output_dir=$(mktemp -d) |
| 33 | fi |
| 34 | |
| 35 | if [[ ! -d "${output_dir}" ]]; then |
| 36 | error "output_dir ${output_dir} must exist as a directory" |
| 37 | exit 1 |
| 38 | fi |
| 39 | |
| 40 | if [[ -n "$(ls -A "${output_dir}")" ]]; then |
| 41 | error "output_dir ${output_dir} must be empty" |
| 42 | exit 1 |
| 43 | fi |
| 44 | |
| 45 | # Write out a simple Dockerfile. |
| 46 | cat > "${output_dir}/Dockerfile" <<- EOF |
| 47 | FROM ubuntu:bionic |
| 48 | WORKDIR /usr/src/rtd/ |
| 49 | COPY rtd/ . |
| 50 | EOF |
| 51 | |
| 52 | # Create the remote test driver folder and copy test content into it. |
| 53 | rtd_dir="${output_dir}/rtd" |
| 54 | mkdir "${rtd_dir}" |
| 55 | # Build and copy the tnull (fake) RTD. |
| 56 | sudo emerge tnull |
| 57 | cp /usr/bin/tnull "${rtd_dir}/" |
| 58 | # tast and tauto entries will eventually go here. |
| 59 | |
| 60 | command_completed |
| 61 | info "Done. Wrote output to ${output_dir}" |