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 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 11 | # Loads script libraries. |
| 12 | CONTRIB_DIR=$(dirname "$(readlink -f "$0")") |
| 13 | . "${CONTRIB_DIR}/common.sh" || exit 1 |
| 14 | |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 15 | STATEFUL_PARTITION="/mnt/stateful_partition/" |
| 16 | RUN_PATH="/run/imageloader/cros-termina/99999.0.0" |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 17 | TEST_SSH_KEY="${GCLIENT_ROOT}/chromite/ssh_keys/testing_rsa" |
Daniel Verkamp | 6e062f7 | 2019-04-24 13:18:13 -0700 | [diff] [blame] | 18 | SSH_OPTS=( |
| 19 | "-i" "${TEST_SSH_KEY}" |
| 20 | "-o" "ConnectTimeout=10" |
| 21 | "-o" "StrictHostKeyChecking=no" |
| 22 | "-o" "UserKnownHostsFile=/dev/null" |
| 23 | ) |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 24 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 25 | # Define flags. |
| 26 | DEFINE_string 'board' 'tatl' 'Specify the board to build for.' 'b' |
| 27 | DEFINE_boolean 'build_packages' false 'Builds packages.' 'p' |
| 28 | DEFINE_boolean 'build_image' false 'Builds the image.' 'i' |
Fergus Dall | 80dfa8e | 2019-11-05 21:37:47 +1100 | [diff] [blame] | 29 | DEFINE_boolean 'test_image' true 'Use a testing termina image instead of a base image.' 't' |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 30 | DEFINE_string 'device_ip_addr' '' 'The ip of the device to deploy to.' 'd' |
Allen Webb | b510e25 | 2020-03-31 15:18:07 -0700 | [diff] [blame] | 31 | DEFINE_integer 'device_port' 22 'The ssh port number of the device to deploy to.' 'P' |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 32 | DEFINE_boolean 'verbose' false 'Turns on verbose logging.' 'v' |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 33 | |
| 34 | main() { |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 35 | local install_script="" |
| 36 | local out_dir="" |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 37 | |
| 38 | # The script will only work inside the chroot. |
| 39 | assert_inside_chroot |
| 40 | |
Daniel Verkamp | 6e062f7 | 2019-04-24 13:18:13 -0700 | [diff] [blame] | 41 | if [[ -n "${FLAGS_device_ip_addr}" ]]; then |
| 42 | # Remove '=' if the user typed -d=<ip> rather than -d <ip>. |
| 43 | FLAGS_device_ip_addr=$(echo "${FLAGS_device_ip_addr}" | sed "s/=//g") |
| 44 | |
| 45 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 46 | echo "Detecting device architecture..." >&2 |
| 47 | fi |
Allen Webb | b510e25 | 2020-03-31 15:18:07 -0700 | [diff] [blame] | 48 | uname_m=$(ssh "${SSH_OPTS[@]}" "-p" "${FLAGS_device_port}" \ |
| 49 | "root@${FLAGS_device_ip_addr}" "uname -m") |
Daniel Verkamp | 6e062f7 | 2019-04-24 13:18:13 -0700 | [diff] [blame] | 50 | case "${uname_m}" in |
| 51 | x86_64) FLAGS_board='tatl' ;; |
| 52 | aarch64) FLAGS_board='tael' ;; |
| 53 | *) die "Unknown target uname -m ${uname_m}" ;; |
| 54 | esac |
| 55 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 56 | echo "Using board ${FLAGS_board} based on device architecture ${uname_m}." >&2 |
| 57 | fi |
| 58 | fi |
| 59 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 60 | if [[ ${FLAGS_build_packages} -eq ${FLAGS_TRUE} ]]; then |
| 61 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 62 | echo "Building packages..." >&2 |
| 63 | fi |
| 64 | ./build_packages --board="${FLAGS_board}" --nowithautotest || |
| 65 | die "Failed to build packages." |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 66 | fi |
| 67 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 68 | if [[ ${FLAGS_build_image} -eq ${FLAGS_TRUE} ]]; then |
| 69 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 70 | echo "Building image..." >&2 |
| 71 | fi |
| 72 | ./build_image --board="${FLAGS_board}" test || |
| 73 | die "Failed to build image" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 74 | fi |
| 75 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 76 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 77 | echo "Repacking the termina image..." >&2 |
| 78 | fi |
| 79 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 80 | out_dir="$(mktemp -d)/${FLAGS_board}" |
| 81 | image_dir="${GCLIENT_ROOT}/src/build/images/${FLAGS_board}/" |
Fergus Dall | 80dfa8e | 2019-11-05 21:37:47 +1100 | [diff] [blame] | 82 | if [[ ${FLAGS_test_image} -eq ${FLAGS_TRUE} ]]; then |
| 83 | image="${image_dir}/latest/chromiumos_test_image.bin" |
| 84 | else |
| 85 | image="${image_dir}/latest/chromiumos_base_image.bin" |
| 86 | fi |
Daniel Verkamp | e933cfe | 2019-08-30 17:21:18 -0700 | [diff] [blame] | 87 | termina_build_image="${GCLIENT_ROOT}/src/platform/container-guest-tools/termina/termina_build_image.py" |
| 88 | sudo "${termina_build_image}" "${image}" "${out_dir}" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 89 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 90 | if [[ -n "${FLAGS_device_ip_addr}" ]]; then |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 91 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 92 | echo "Copying image to device:" >&2 |
| 93 | fi |
Allen Webb | b510e25 | 2020-03-31 15:18:07 -0700 | [diff] [blame] | 94 | rsync -a "${out_dir}" -e "ssh ${SSH_OPTS[*]} -p ${FLAGS_device_port} " \ |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 95 | "root@${FLAGS_device_ip_addr}:${STATEFUL_PARTITION}" \ |
| 96 | || die "Failed to copy to device." |
Daniel Verkamp | e933cfe | 2019-08-30 17:21:18 -0700 | [diff] [blame] | 97 | sudo rm -rf "${out_dir}" |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 98 | |
| 99 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 100 | echo "Install image onto to device:" >&2 |
| 101 | fi |
| 102 | read -r -d '' install_script <<EOF |
| 103 | dbus-send --system --type=method_call --print-reply \ |
| 104 | --dest=org.chromium.ComponentUpdaterService \ |
| 105 | /org/chromium/ComponentUpdaterService \ |
| 106 | org.chromium.ComponentUpdaterService.LoadComponent \ |
| 107 | 'string:cros-termina' && |
| 108 | mkdir -p "${RUN_PATH}" && |
| 109 | mount --bind "${STATEFUL_PARTITION}/${FLAGS_board}" "${RUN_PATH}" && |
| 110 | restart vm_cicerone |
| 111 | restart vm_concierge |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 112 | EOF |
Allen Webb | b510e25 | 2020-03-31 15:18:07 -0700 | [diff] [blame] | 113 | ssh "${SSH_OPTS[@]}" "-p" "${FLAGS_device_port}" \ |
| 114 | "root@${FLAGS_device_ip_addr}" "${install_script}" \ |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 115 | || die "Failed to deploy to device." |
| 116 | fi |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 117 | } |
| 118 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 119 | # Parse the command-line. |
| 120 | FLAGS "$@" || exit $? |
| 121 | eval set -- "${FLAGS_ARGV}" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 122 | main "$@" |