blob: 9a9c3d647e3df0f5f7f9ce47672aa709d4be23fc [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"
Daniel Verkamp6e062f72019-04-24 13:18:13 -070018SSH_OPTS=(
19 "-i" "${TEST_SSH_KEY}"
20 "-o" "ConnectTimeout=10"
21 "-o" "StrictHostKeyChecking=no"
22 "-o" "UserKnownHostsFile=/dev/null"
23)
Josh Pratt01aae1f2018-08-06 11:19:21 +100024
Josh Prattda1cebd2018-08-21 11:20:54 +100025# Define flags.
26DEFINE_string 'board' 'tatl' 'Specify the board to build for.' 'b'
27DEFINE_boolean 'build_packages' false 'Builds packages.' 'p'
28DEFINE_boolean 'build_image' false 'Builds the image.' 'i'
Fergus Dall80dfa8e2019-11-05 21:37:47 +110029DEFINE_boolean 'test_image' true 'Use a testing termina image instead of a base image.' 't'
Josh Prattda1cebd2018-08-21 11:20:54 +100030DEFINE_string 'device_ip_addr' '' 'The ip of the device to deploy to.' 'd'
31DEFINE_boolean 'verbose' false 'Turns on verbose logging.' 'v'
Josh Pratt01aae1f2018-08-06 11:19:21 +100032
33main() {
Josh Pratt01aae1f2018-08-06 11:19:21 +100034 local install_script=""
35 local out_dir=""
Josh Prattda1cebd2018-08-21 11:20:54 +100036
37 # The script will only work inside the chroot.
38 assert_inside_chroot
39
Daniel Verkamp6e062f72019-04-24 13:18:13 -070040 if [[ -n "${FLAGS_device_ip_addr}" ]]; then
41 # Remove '=' if the user typed -d=<ip> rather than -d <ip>.
42 FLAGS_device_ip_addr=$(echo "${FLAGS_device_ip_addr}" | sed "s/=//g")
43
44 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
45 echo "Detecting device architecture..." >&2
46 fi
47 uname_m=$(ssh "${SSH_OPTS[@]}" "root@${FLAGS_device_ip_addr}" "uname -m")
48 case "${uname_m}" in
49 x86_64) FLAGS_board='tatl' ;;
50 aarch64) FLAGS_board='tael' ;;
51 *) die "Unknown target uname -m ${uname_m}" ;;
52 esac
53 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
54 echo "Using board ${FLAGS_board} based on device architecture ${uname_m}." >&2
55 fi
56 fi
57
Josh Prattda1cebd2018-08-21 11:20:54 +100058 if [[ ${FLAGS_build_packages} -eq ${FLAGS_TRUE} ]]; then
59 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
60 echo "Building packages..." >&2
61 fi
62 ./build_packages --board="${FLAGS_board}" --nowithautotest ||
63 die "Failed to build packages."
Josh Pratt01aae1f2018-08-06 11:19:21 +100064 fi
65
Josh Prattda1cebd2018-08-21 11:20:54 +100066 if [[ ${FLAGS_build_image} -eq ${FLAGS_TRUE} ]]; then
67 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
68 echo "Building image..." >&2
69 fi
70 ./build_image --board="${FLAGS_board}" test ||
71 die "Failed to build image"
Josh Pratt01aae1f2018-08-06 11:19:21 +100072 fi
73
Josh Prattda1cebd2018-08-21 11:20:54 +100074 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
Josh Pratt01aae1f2018-08-06 11:19:21 +100075 echo "Repacking the termina image..." >&2
76 fi
77
Josh Prattda1cebd2018-08-21 11:20:54 +100078 out_dir="$(mktemp -d)/${FLAGS_board}"
79 image_dir="${GCLIENT_ROOT}/src/build/images/${FLAGS_board}/"
Fergus Dall80dfa8e2019-11-05 21:37:47 +110080 if [[ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ]]; then
81 image="${image_dir}/latest/chromiumos_test_image.bin"
82 else
83 image="${image_dir}/latest/chromiumos_base_image.bin"
84 fi
Daniel Verkampe933cfe2019-08-30 17:21:18 -070085 termina_build_image="${GCLIENT_ROOT}/src/platform/container-guest-tools/termina/termina_build_image.py"
86 sudo "${termina_build_image}" "${image}" "${out_dir}"
Josh Pratt01aae1f2018-08-06 11:19:21 +100087
Josh Prattda1cebd2018-08-21 11:20:54 +100088 if [[ -n "${FLAGS_device_ip_addr}" ]]; then
Josh Prattda1cebd2018-08-21 11:20:54 +100089 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
90 echo "Copying image to device:" >&2
91 fi
Daniel Verkamp6e062f72019-04-24 13:18:13 -070092 rsync -a "${out_dir}" -e "ssh ${SSH_OPTS[*]}" \
Josh Prattda1cebd2018-08-21 11:20:54 +100093 "root@${FLAGS_device_ip_addr}:${STATEFUL_PARTITION}" \
94 || die "Failed to copy to device."
Daniel Verkampe933cfe2019-08-30 17:21:18 -070095 sudo rm -rf "${out_dir}"
Josh Prattda1cebd2018-08-21 11:20:54 +100096
97 if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then
98 echo "Install image onto to device:" >&2
99 fi
100 read -r -d '' install_script <<EOF
101 dbus-send --system --type=method_call --print-reply \
102 --dest=org.chromium.ComponentUpdaterService \
103 /org/chromium/ComponentUpdaterService \
104 org.chromium.ComponentUpdaterService.LoadComponent \
105 'string:cros-termina' &&
106 mkdir -p "${RUN_PATH}" &&
107 mount --bind "${STATEFUL_PARTITION}/${FLAGS_board}" "${RUN_PATH}" &&
108 restart vm_cicerone
109 restart vm_concierge
Josh Pratt01aae1f2018-08-06 11:19:21 +1000110EOF
Daniel Verkamp6e062f72019-04-24 13:18:13 -0700111 ssh "${SSH_OPTS[@]}" "root@${FLAGS_device_ip_addr}" \
Josh Prattda1cebd2018-08-21 11:20:54 +1000112 "${install_script}" \
113 || die "Failed to deploy to device."
114 fi
Josh Pratt01aae1f2018-08-06 11:19:21 +1000115}
116
Josh Prattda1cebd2018-08-21 11:20:54 +1000117# Parse the command-line.
118FLAGS "$@" || exit $?
119eval set -- "${FLAGS_ARGV}"
Josh Pratt01aae1f2018-08-06 11:19:21 +1000120main "$@"