Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 1 | #!/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 | |
| 11 | IMAGE="/mnt/host/source/src/build/images/tatl/latest/chromiumos_test_image.bin" |
| 12 | STATEFUL_PARTITION="/mnt/stateful_partition/" |
| 13 | RUN_PATH="/run/imageloader/cros-termina/99999.0.0" |
| 14 | TEST_SSH_KEY="/mnt/host/source/chromite/ssh_keys/testing_rsa" |
| 15 | |
| 16 | die() { |
| 17 | echo "$0: error: $*" >&2 |
| 18 | exit 1 |
| 19 | } |
| 20 | |
| 21 | usage() { |
| 22 | echo "Usage: $0 -d=device_ip_addr [-v]" >&2 |
| 23 | exit 1 |
| 24 | } |
| 25 | |
| 26 | main() { |
| 27 | local device_ip_addr="" |
| 28 | local install_script="" |
| 29 | local out_dir="" |
| 30 | local verbose="false" |
| 31 | while getopts vd: name; do |
| 32 | case "${name}" in |
| 33 | d) device_ip_addr="${OPTARG}" ;; |
| 34 | v) verbose="true" ;; |
| 35 | ?) usage ;; |
| 36 | esac |
| 37 | done |
| 38 | if [[ -z "${device_ip_addr}" ]]; then |
| 39 | die "Missing -d flag" |
| 40 | fi |
| 41 | |
| 42 | if [[ ${verbose} == "true" ]]; then |
| 43 | echo "Pushing termina to '${device_ip_addr}'" >&2 |
| 44 | fi |
| 45 | |
| 46 | if [[ ${verbose} == "true" ]]; then |
| 47 | echo "Repacking the termina image..." >&2 |
| 48 | fi |
| 49 | |
| 50 | out_dir="$(mktemp -d)/tatl" |
| 51 | ./termina_build_image --image "${IMAGE}" -t --output "${out_dir}" |
| 52 | |
| 53 | if [[ ${verbose} == "true" ]]; then |
| 54 | echo "Copying image to device:" >&2 |
| 55 | fi |
| 56 | rsync -a "${out_dir}" -e "ssh -i ${TEST_SSH_KEY}" \ |
| 57 | "root@${device_ip_addr}:${STATEFUL_PARTITION}" \ |
| 58 | || die "Failed to copy to device." |
| 59 | rm -rf "${out_dir}" |
| 60 | |
| 61 | if [[ ${verbose} == "true" ]]; then |
| 62 | echo "Install image onto to device:" >&2 |
| 63 | fi |
| 64 | read -r -d '' install_script <<EOF |
| 65 | dbus-send --system --type=method_call --print-reply \ |
| 66 | --dest=org.chromium.ComponentUpdaterService \ |
| 67 | /org/chromium/ComponentUpdaterService \ |
| 68 | org.chromium.ComponentUpdaterService.LoadComponent 'string:cros-termina' && |
| 69 | mkdir -p "${RUN_PATH}" && |
| 70 | mount --bind "${STATEFUL_PARTITION}/tatl" "${RUN_PATH}" && |
| 71 | restart vm_concierge |
| 72 | EOF |
| 73 | ssh -i "${TEST_SSH_KEY}" "root@${device_ip_addr}" "${install_script}" \ |
| 74 | || die "Failed to deploy to device." |
| 75 | } |
| 76 | |
| 77 | main "$@" |