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