blob: 7a69b703cbf0324428e91a0ab6f177e1f75bb04d [file] [log] [blame]
#!/bin/bash
# Copyright 2018 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.
#
# Based on http://go/termina-care-and-feeding
#
# Pushes the lastest local build of tatl to your test device.
# Usage: ./deploy_termina.sh device_ip
# Loads script libraries.
CONTRIB_DIR=$(dirname "$(readlink -f "$0")")
. "${CONTRIB_DIR}/common.sh" || exit 1
STATEFUL_PARTITION="/mnt/stateful_partition/"
RUN_PATH="/run/imageloader/cros-termina/99999.0.0"
TEST_SSH_KEY="${GCLIENT_ROOT}/chromite/ssh_keys/testing_rsa"
# Define flags.
DEFINE_string 'board' 'tatl' 'Specify the board to build for.' 'b'
DEFINE_boolean 'build_packages' false 'Builds packages.' 'p'
DEFINE_boolean 'build_image' false 'Builds the image.' 'i'
DEFINE_string 'device_ip_addr' '' 'The ip of the device to deploy to.' 'd'
DEFINE_boolean 'verbose' false 'Turns on verbose logging.' 'v'
main() {
local install_script=""
local out_dir=""
# The script will only work inside the chroot.
assert_inside_chroot
if [[ ${FLAGS_build_packages} -eq ${FLAGS_TRUE} ]]; then
if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
echo "Building packages..." >&2
fi
./build_packages --board="${FLAGS_board}" --nowithautotest ||
die "Failed to build packages."
fi
if [[ ${FLAGS_build_image} -eq ${FLAGS_TRUE} ]]; then
if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
echo "Building image..." >&2
fi
./build_image --board="${FLAGS_board}" test ||
die "Failed to build image"
fi
if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
echo "Repacking the termina image..." >&2
fi
out_dir="$(mktemp -d)/${FLAGS_board}"
image_dir="${GCLIENT_ROOT}/src/build/images/${FLAGS_board}/"
image="${image_dir}/latest/chromiumos_test_image.bin"
./termina_build_image --image "${image}" -t --output "${out_dir}"
if [[ -n "${FLAGS_device_ip_addr}" ]]; then
# Remove '=' if the user typed -d=<ip> rather than -d <ip>.
FLAGS_device_ip_addr=$(echo "${FLAGS_device_ip_addr}" | sed "s/=//g")
if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
echo "Copying image to device:" >&2
fi
rsync -a "${out_dir}" -e "ssh -i ${TEST_SSH_KEY}" \
"root@${FLAGS_device_ip_addr}:${STATEFUL_PARTITION}" \
|| die "Failed to copy to device."
rm -rf "${out_dir}"
if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
echo "Install image onto to device:" >&2
fi
read -r -d '' install_script <<EOF
dbus-send --system --type=method_call --print-reply \
--dest=org.chromium.ComponentUpdaterService \
/org/chromium/ComponentUpdaterService \
org.chromium.ComponentUpdaterService.LoadComponent \
'string:cros-termina' &&
mkdir -p "${RUN_PATH}" &&
mount --bind "${STATEFUL_PARTITION}/${FLAGS_board}" "${RUN_PATH}" &&
restart vm_cicerone
restart vm_concierge
EOF
ssh -i "${TEST_SSH_KEY}" "root@${FLAGS_device_ip_addr}" \
"${install_script}" \
|| die "Failed to deploy to device."
fi
}
# Parse the command-line.
FLAGS "$@" || exit $?
eval set -- "${FLAGS_ARGV}"
main "$@"