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" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 18 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 19 | # Define flags. |
| 20 | DEFINE_string 'board' 'tatl' 'Specify the board to build for.' 'b' |
| 21 | DEFINE_boolean 'build_packages' false 'Builds packages.' 'p' |
| 22 | DEFINE_boolean 'build_image' false 'Builds the image.' 'i' |
| 23 | DEFINE_string 'device_ip_addr' '' 'The ip of the device to deploy to.' 'd' |
| 24 | DEFINE_boolean 'verbose' false 'Turns on verbose logging.' 'v' |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 25 | |
| 26 | main() { |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 27 | local install_script="" |
| 28 | local out_dir="" |
Daniel Verkamp | 2a76af0 | 2018-09-21 13:47:57 -0700 | [diff] [blame] | 29 | local arch="" |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 30 | |
| 31 | # The script will only work inside the chroot. |
| 32 | assert_inside_chroot |
| 33 | |
Daniel Verkamp | 2a76af0 | 2018-09-21 13:47:57 -0700 | [diff] [blame] | 34 | case "${FLAGS_board}" in |
| 35 | tatl) arch='amd64' ;; |
| 36 | tael) arch='arm' ;; |
| 37 | *) die "Unknown board ${FLAGS_board}" ;; |
| 38 | esac |
| 39 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 40 | 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 Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 46 | fi |
| 47 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 48 | 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 Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 54 | fi |
| 55 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 56 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 57 | echo "Repacking the termina image..." >&2 |
| 58 | fi |
| 59 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 60 | 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 Verkamp | 7c08b1b | 2019-04-24 12:52:53 -0700 | [diff] [blame^] | 63 | ./termina_build_image --image "${image}" --output "${out_dir}" \ |
Daniel Verkamp | 2a76af0 | 2018-09-21 13:47:57 -0700 | [diff] [blame] | 64 | --arch "${arch}" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 65 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 66 | 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 Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 69 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 70 | 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 Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 91 | EOF |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 92 | ssh -i "${TEST_SSH_KEY}" "root@${FLAGS_device_ip_addr}" \ |
| 93 | "${install_script}" \ |
| 94 | || die "Failed to deploy to device." |
| 95 | fi |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 96 | } |
| 97 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 98 | # Parse the command-line. |
| 99 | FLAGS "$@" || exit $? |
| 100 | eval set -- "${FLAGS_ARGV}" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 101 | main "$@" |