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="" |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 29 | |
| 30 | # The script will only work inside the chroot. |
| 31 | assert_inside_chroot |
| 32 | |
| 33 | if [[ ${FLAGS_build_packages} -eq ${FLAGS_TRUE} ]]; then |
| 34 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 35 | echo "Building packages..." >&2 |
| 36 | fi |
| 37 | ./build_packages --board="${FLAGS_board}" --nowithautotest || |
| 38 | die "Failed to build packages." |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 39 | fi |
| 40 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 41 | if [[ ${FLAGS_build_image} -eq ${FLAGS_TRUE} ]]; then |
| 42 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 43 | echo "Building image..." >&2 |
| 44 | fi |
| 45 | ./build_image --board="${FLAGS_board}" test || |
| 46 | die "Failed to build image" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 47 | fi |
| 48 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 49 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 50 | echo "Repacking the termina image..." >&2 |
| 51 | fi |
| 52 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 53 | out_dir="$(mktemp -d)/${FLAGS_board}" |
| 54 | image_dir="${GCLIENT_ROOT}/src/build/images/${FLAGS_board}/" |
| 55 | image="${image_dir}/latest/chromiumos_test_image.bin" |
| 56 | ./termina_build_image --image "${image}" -t --output "${out_dir}" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 57 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 58 | if [[ -n "${FLAGS_device_ip_addr}" ]]; then |
| 59 | # Remove '=' if the user typed -d=<ip> rather than -d <ip>. |
| 60 | FLAGS_device_ip_addr=$(echo "${FLAGS_device_ip_addr}" | sed "s/=//g") |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 61 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 62 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 63 | echo "Copying image to device:" >&2 |
| 64 | fi |
| 65 | rsync -a "${out_dir}" -e "ssh -i ${TEST_SSH_KEY}" \ |
| 66 | "root@${FLAGS_device_ip_addr}:${STATEFUL_PARTITION}" \ |
| 67 | || die "Failed to copy to device." |
| 68 | rm -rf "${out_dir}" |
| 69 | |
| 70 | if [[ ${FLAGS_verbose} -eq ${FLAGS_TRUE} ]]; then |
| 71 | echo "Install image onto to device:" >&2 |
| 72 | fi |
| 73 | read -r -d '' install_script <<EOF |
| 74 | dbus-send --system --type=method_call --print-reply \ |
| 75 | --dest=org.chromium.ComponentUpdaterService \ |
| 76 | /org/chromium/ComponentUpdaterService \ |
| 77 | org.chromium.ComponentUpdaterService.LoadComponent \ |
| 78 | 'string:cros-termina' && |
| 79 | mkdir -p "${RUN_PATH}" && |
| 80 | mount --bind "${STATEFUL_PARTITION}/${FLAGS_board}" "${RUN_PATH}" && |
| 81 | restart vm_cicerone |
| 82 | restart vm_concierge |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 83 | EOF |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 84 | ssh -i "${TEST_SSH_KEY}" "root@${FLAGS_device_ip_addr}" \ |
| 85 | "${install_script}" \ |
| 86 | || die "Failed to deploy to device." |
| 87 | fi |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 88 | } |
| 89 | |
Josh Pratt | da1cebd | 2018-08-21 11:20:54 +1000 | [diff] [blame] | 90 | # Parse the command-line. |
| 91 | FLAGS "$@" || exit $? |
| 92 | eval set -- "${FLAGS_ARGV}" |
Josh Pratt | 01aae1f | 2018-08-06 11:19:21 +1000 | [diff] [blame] | 93 | main "$@" |