blob: 1607ddf2142d52aea8c556b48b7300c90ef47e21 [file] [log] [blame] [edit]
#!/bin/bash
# Copyright 2020 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.
# Populates a directory with everything necessary to build a remote test driver
# container.
readonly script_dir="$(dirname "$(realpath -e "${BASH_SOURCE[0]}")")"
. "${script_dir}/common.sh" || exit 1
# Script must run inside the chroot
assert_inside_chroot "$@"
# Do not run as root
assert_not_root_user
DEFINE_string output_dir "" "Dir in which to put Dockerfile and dependencies"
# Parse command line flags
FLAGS "$@" || exit 1
eval set -- "${FLAGS_ARGV}"
# Only now can we die on error. shflags functions leak non-zero error codes,
# so will die prematurely if 'switch_to_strict_mode' is specified before now.
switch_to_strict_mode
output_dir="${FLAGS_output_dir}"
if [[ -z "${FLAGS_output_dir}" ]]; then
info "No --output_dir provided. Using temp dir instead"
output_dir=$(mktemp -d)
fi
if [[ ! -d "${output_dir}" ]]; then
error "output_dir ${output_dir} must exist as a directory"
exit 1
fi
if [[ -n "$(ls -A "${output_dir}")" ]]; then
error "output_dir ${output_dir} must be empty"
exit 1
fi
# Write out a simple Dockerfile.
cat > "${output_dir}/Dockerfile" <<- EOF
FROM ubuntu:bionic
WORKDIR /usr/src/rtd/
COPY rtd/ .
EOF
# Create the remote test driver folder and copy test content into it.
rtd_dir="${output_dir}/rtd"
mkdir "${rtd_dir}"
# Build and copy the tnull (fake) RTD.
sudo emerge tnull
cp /usr/bin/tnull "${rtd_dir}/"
# tast and tauto entries will eventually go here.
command_completed
info "Done. Wrote output to ${output_dir}"