blob: 7a69b703cbf0324428e91a0ab6f177e1f75bb04d [file] [log] [blame]
Josh Pratt01aae1f2018-08-06 11:19:21 +10001#!/bin/bash
2# Copyright 2018 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5#
6# Based on http://go/termina-care-and-feeding
7#
8# Pushes the lastest local build of tatl to your test device.
9# Usage: ./deploy_termina.sh device_ip
10
Josh Prattda1cebd2018-08-21 11:20:54 +100011# Loads script libraries.
12CONTRIB_DIR=$(dirname "$(readlink -f "$0")")
13. "${CONTRIB_DIR}/common.sh" || exit 1
14
Josh Pratt01aae1f2018-08-06 11:19:21 +100015STATEFUL_PARTITION="/mnt/stateful_partition/"
16RUN_PATH="/run/imageloader/cros-termina/99999.0.0"
Josh Prattda1cebd2018-08-21 11:20:54 +100017TEST_SSH_KEY="${GCLIENT_ROOT}/chromite/ssh_keys/testing_rsa"
Josh Pratt01aae1f2018-08-06 11:19:21 +100018
Josh Prattda1cebd2018-08-21 11:20:54 +100019# Define flags.
20DEFINE_string 'board' 'tatl' 'Specify the board to build for.' 'b'
21DEFINE_boolean 'build_packages' false 'Builds packages.' 'p'
22DEFINE_boolean 'build_image' false 'Builds the image.' 'i'
23DEFINE_string 'device_ip_addr' '' 'The ip of the device to deploy to.' 'd'
24DEFINE_boolean 'verbose' false 'Turns on verbose logging.' 'v'
Josh Pratt01aae1f2018-08-06 11:19:21 +100025
26main() {
Josh Pratt01aae1f2018-08-06 11:19:21 +100027 local install_script=""
28 local out_dir=""
Josh Prattda1cebd2018-08-21 11:20:54 +100029
30 # The script will only work inside the chroot.
31 assert_inside_chroot
32
33 if [[ ${FLAGS_build_packages} -eq ${FLAGS_TRUE} ]]; then
34 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
35 echo "Building packages..." >&2
36 fi
37 ./build_packages --board="${FLAGS_board}" --nowithautotest ||
38 die "Failed to build packages."
Josh Pratt01aae1f2018-08-06 11:19:21 +100039 fi
40
Josh Prattda1cebd2018-08-21 11:20:54 +100041 if [[ ${FLAGS_build_image} -eq ${FLAGS_TRUE} ]]; then
42 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
43 echo "Building image..." >&2
44 fi
45 ./build_image --board="${FLAGS_board}" test ||
46 die "Failed to build image"
Josh Pratt01aae1f2018-08-06 11:19:21 +100047 fi
48
Josh Prattda1cebd2018-08-21 11:20:54 +100049 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
Josh Pratt01aae1f2018-08-06 11:19:21 +100050 echo "Repacking the termina image..." >&2
51 fi
52
Josh Prattda1cebd2018-08-21 11:20:54 +100053 out_dir="$(mktemp -d)/${FLAGS_board}"
54 image_dir="${GCLIENT_ROOT}/src/build/images/${FLAGS_board}/"
55 image="${image_dir}/latest/chromiumos_test_image.bin"
56 ./termina_build_image --image "${image}" -t --output "${out_dir}"
Josh Pratt01aae1f2018-08-06 11:19:21 +100057
Josh Prattda1cebd2018-08-21 11:20:54 +100058 if [[ -n "${FLAGS_device_ip_addr}" ]]; then
59 # Remove '=' if the user typed -d=<ip> rather than -d <ip>.
60 FLAGS_device_ip_addr=$(echo "${FLAGS_device_ip_addr}" | sed "s/=//g")
Josh Pratt01aae1f2018-08-06 11:19:21 +100061
Josh Prattda1cebd2018-08-21 11:20:54 +100062 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
63 echo "Copying image to device:" >&2
64 fi
65 rsync -a "${out_dir}" -e "ssh -i ${TEST_SSH_KEY}" \
66 "root@${FLAGS_device_ip_addr}:${STATEFUL_PARTITION}" \
67 || die "Failed to copy to device."
68 rm -rf "${out_dir}"
69
70 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
71 echo "Install image onto to device:" >&2
72 fi
73 read -r -d '' install_script <<EOF
74 dbus-send --system --type=method_call --print-reply \
75 --dest=org.chromium.ComponentUpdaterService \
76 /org/chromium/ComponentUpdaterService \
77 org.chromium.ComponentUpdaterService.LoadComponent \
78 'string:cros-termina' &&
79 mkdir -p "${RUN_PATH}" &&
80 mount --bind "${STATEFUL_PARTITION}/${FLAGS_board}" "${RUN_PATH}" &&
81 restart vm_cicerone
82 restart vm_concierge
Josh Pratt01aae1f2018-08-06 11:19:21 +100083EOF
Josh Prattda1cebd2018-08-21 11:20:54 +100084 ssh -i "${TEST_SSH_KEY}" "root@${FLAGS_device_ip_addr}" \
85 "${install_script}" \
86 || die "Failed to deploy to device."
87 fi
Josh Pratt01aae1f2018-08-06 11:19:21 +100088}
89
Josh Prattda1cebd2018-08-21 11:20:54 +100090# Parse the command-line.
91FLAGS "$@" || exit $?
92eval set -- "${FLAGS_ARGV}"
Josh Pratt01aae1f2018-08-06 11:19:21 +100093main "$@"