| #!/bin/bash |
| # Copyright 2020 The Fuchsia Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| #### CATEGORY=Other |
| ### Remotely build, fetch and pave |
| |
| ## usage: fx pave-remote HOST [DIR] [--no-pave] [--no-build] |
| ## [--no-check-ssh-keys] [-- PAVE_ARGS] |
| ## |
| ## Connect to HOST, run a build using fx from DIR, fetch the artifacts and |
| ## start the paver. |
| ## |
| ## --no-build do not build, just pull artifacts already present. Defaults to build |
| ## --no-pave do not start the paver, just pull the artifacts. Defaults to pave |
| ## --no-check-ssh-keys do not verify that the default SSH credentials are the |
| ## same before paving. Defaults to check ssh keys |
| ## --run-once | --keep-running perform a single pave and exit or keep the bootserver |
| ## running after the first paving. defaults to --run-once |
| ## -- pass any arguments after the -- to the fx pave command |
| ## |
| ## HOST the hostname to connect to |
| ## DIR defaults to ~/fuchsia, the path to the FUCHSIA_DIR on HOST |
| ## PAVE_ARGS arguments for the fx pave command |
| ## |
| ## HOST and DIR are persisted in the file //.fx-remote-config and are reused as |
| ## defaults in future invocations of any 'fx *-remote' tools. |
| |
| set -o errexit |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/fx-remote.sh || exit $? |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/verify-default-keys.sh || exit $? |
| fx-config-read |
| |
| fx-warn "DEPRECATION WARNING" |
| fx-warn "\`fx pave-remote\` is deprecated and will be removed soon, please use \`fx flash-remote\`." |
| fx-warn "See https://fxbug.dev/42081363.\n" |
| |
| build=true |
| pave=true |
| check_ssh_keys=true |
| single_run=true |
| host="" |
| dir="" |
| pave_args=() |
| while [[ $# -ne 0 ]]; do |
| case "$1" in |
| --help|-h) |
| fx-command-help |
| exit 0 |
| ;; |
| --no-build) |
| build=false |
| ;; |
| --no-pave) |
| pave=false |
| ;; |
| --no-check-ssh-keys) |
| check_ssh_keys=false |
| ;; |
| # -1 is here for backward compatibility. |
| --run-once | -1) |
| single_run=true |
| ;; |
| --keep-running) |
| single_run=false |
| ;; |
| --) |
| shift |
| pave_args+=("$@") |
| break |
| ;; |
| -*) |
| fx-error "Unknown flag: $1" |
| fx-command-help |
| exit 1 |
| ;; |
| *) |
| if [[ -z "${host}" ]]; then |
| host="$1" |
| elif [[ -z "${dir}" ]]; then |
| dir="$1" |
| else |
| fx-error "unexpected argument: '$1'" |
| exit 1 |
| fi |
| ;; |
| esac |
| shift |
| done |
| |
| if $single_run; then |
| pave_args+=( "-1" ) |
| fi |
| |
| if cached=( $(load_remote_info "$host") ); then |
| host="${cached[0]}" |
| dir="${cached[1]}" |
| fi |
| |
| if [[ -z "${host}" ]]; then |
| fx-error "HOST must be specified" |
| fx-command-help |
| exit 1 |
| fi |
| |
| if [[ -z "${dir}" ]]; then |
| if ssh "$host" ls \~/fuchsia/.jiri_root/bin/fx > /dev/null; then |
| dir="~/fuchsia" |
| else |
| fx-error "failed to find ~/fuchsia on $host, please specify DIR" |
| fx-command-help |
| exit 1 |
| fi |
| fi |
| |
| # Verify that keys match. |
| if "${check_ssh_keys}"; then |
| verify_default_keys "${FUCHSIA_DIR}" "${host}" "${dir}" || exit $? |
| fi |
| |
| save_remote_info "$host" "$dir" |
| |
| authkeys_path="$(get-ssh-authkeys)" || { |
| fx-error "Cannot continue without a valid authorized keys file." |
| exit 1 |
| } |
| |
| artifact_dir="${FUCHSIA_DIR}/out/fetched" |
| flash_source=$(fetch_remote_flash_source "${host}" "${dir}" "${build}") |
| case "${flash_source}" in |
| flash-manifest:*) |
| flash_manifest="${flash_source#flash-manifest:}" |
| product_bundle="" |
| paving_script="./pave.sh" |
| ;; |
| product-bundle:*) |
| flash_manifest="" |
| product_bundle="${flash_source#product-bundle:}" |
| paving_script="$(dirname "${product_bundle}")/pave.sh" |
| ;; |
| *) |
| fx-error "failed to find a flash manifest or product bundle on $host." |
| exit 1 |
| esac |
| |
| fx-info "Fetching artifacts from remote host: ${host}" |
| if [[ -n "${flash_manifest}" ]]; then |
| fetch_remote_build_artifacts "${host}" "${dir}" "${artifact_dir}" pave $build |
| else |
| fetch_remote_artifacts "${host}" "${dir}" "${artifact_dir}" "${product_bundle}" "${paving_script}" |
| fi |
| |
| if "${pave}"; then |
| if [[ -n "$(get-device-name)" ]]; then |
| pave_args+=(-n $(get-device-name)) |
| fi |
| |
| if [[ -n "${flash_manifest}" ]]; then |
| fetch_or_build_tool "${host}" "${dir}" "${artifact_dir}" bootserver |
| fi |
| cd "${artifact_dir}" |
| "${paving_script}" --authorized-keys "${authkeys_path}" "${pave_args[@]}" |
| fi |