blob: 8eb83061ec0cee0036a5af8832fd7fb0d99755cb [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=""
Daniel Verkamp2a76af02018-09-21 13:47:57 -070029 local arch=""
Josh Prattda1cebd2018-08-21 11:20:54 +100030
31 # The script will only work inside the chroot.
32 assert_inside_chroot
33
Daniel Verkamp2a76af02018-09-21 13:47:57 -070034 case "${FLAGS_board}" in
35 tatl) arch='amd64' ;;
36 tael) arch='arm' ;;
37 *) die "Unknown board ${FLAGS_board}" ;;
38 esac
39
Josh Prattda1cebd2018-08-21 11:20:54 +100040 if [[ ${FLAGS_build_packages} -eq ${FLAGS_TRUE} ]]; then
41 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
42 echo "Building packages..." >&2
43 fi
44 ./build_packages --board="${FLAGS_board}" --nowithautotest ||
45 die "Failed to build packages."
Josh Pratt01aae1f2018-08-06 11:19:21 +100046 fi
47
Josh Prattda1cebd2018-08-21 11:20:54 +100048 if [[ ${FLAGS_build_image} -eq ${FLAGS_TRUE} ]]; then
49 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
50 echo "Building image..." >&2
51 fi
52 ./build_image --board="${FLAGS_board}" test ||
53 die "Failed to build image"
Josh Pratt01aae1f2018-08-06 11:19:21 +100054 fi
55
Josh Prattda1cebd2018-08-21 11:20:54 +100056 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
Josh Pratt01aae1f2018-08-06 11:19:21 +100057 echo "Repacking the termina image..." >&2
58 fi
59
Josh Prattda1cebd2018-08-21 11:20:54 +100060 out_dir="$(mktemp -d)/${FLAGS_board}"
61 image_dir="${GCLIENT_ROOT}/src/build/images/${FLAGS_board}/"
62 image="${image_dir}/latest/chromiumos_test_image.bin"
Daniel Verkamp7c08b1b2019-04-24 12:52:53 -070063 ./termina_build_image --image "${image}" --output "${out_dir}" \
Daniel Verkamp2a76af02018-09-21 13:47:57 -070064 --arch "${arch}"
Josh Pratt01aae1f2018-08-06 11:19:21 +100065
Josh Prattda1cebd2018-08-21 11:20:54 +100066 if [[ -n "${FLAGS_device_ip_addr}" ]]; then
67 # Remove '=' if the user typed -d=<ip> rather than -d <ip>.
68 FLAGS_device_ip_addr=$(echo "${FLAGS_device_ip_addr}" | sed "s/=//g")
Josh Pratt01aae1f2018-08-06 11:19:21 +100069
Josh Prattda1cebd2018-08-21 11:20:54 +100070 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
71 echo "Copying image to device:" >&2
72 fi
73 rsync -a "${out_dir}" -e "ssh -i ${TEST_SSH_KEY}" \
74 "root@${FLAGS_device_ip_addr}:${STATEFUL_PARTITION}" \
75 || die "Failed to copy to device."
76 rm -rf "${out_dir}"
77
78 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
79 echo "Install image onto to device:" >&2
80 fi
81 read -r -d '' install_script <<EOF
82 dbus-send --system --type=method_call --print-reply \
83 --dest=org.chromium.ComponentUpdaterService \
84 /org/chromium/ComponentUpdaterService \
85 org.chromium.ComponentUpdaterService.LoadComponent \
86 'string:cros-termina' &&
87 mkdir -p "${RUN_PATH}" &&
88 mount --bind "${STATEFUL_PARTITION}/${FLAGS_board}" "${RUN_PATH}" &&
89 restart vm_cicerone
90 restart vm_concierge
Josh Pratt01aae1f2018-08-06 11:19:21 +100091EOF
Josh Prattda1cebd2018-08-21 11:20:54 +100092 ssh -i "${TEST_SSH_KEY}" "root@${FLAGS_device_ip_addr}" \
93 "${install_script}" \
94 || die "Failed to deploy to device."
95 fi
Josh Pratt01aae1f2018-08-06 11:19:21 +100096}
97
Josh Prattda1cebd2018-08-21 11:20:54 +100098# Parse the command-line.
99FLAGS "$@" || exit $?
100eval set -- "${FLAGS_ARGV}"
Josh Pratt01aae1f2018-08-06 11:19:21 +1000101main "$@"