| #!/bin/bash |
| # Copyright 2018 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=Software delivery |
| ### run bootserver for paving |
| |
| ## usage: fx pave [--build|--no-build] [-1|--keep-running] [extra bootserver arguments] |
| ## |
| ## --build | --no-build build (or not) the images required to pave. defaults to --no-build |
| ## --run-once | --keep-running perform a single pave and exit or keep the bootserver |
| ## running after the first paving. defaults to --run-once |
| ## extra bootserver args arguments passed directly to bootserver |
| ## |
| ## Start a bootserver for paving a device, optionally performing a build of the |
| ## system images before. |
| ## |
| ## Defaults are defined by the "incremental" feature: |
| ## 'fx --enable=incremental pave' defaults to "--build" |
| ## 'fx --disable=incremental pave' defaults to "--no-build" |
| ## |
| ## For bootserver specific arguments, use 'fx pave --help' |
| |
| set -e |
| |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? |
| fx-config-read |
| |
| fx-warn "DEPRECATION WARNING" |
| fx-warn "\`fx pave\` is deprecated and will be removed soon, please use \`fx flash\`." |
| fx-warn "See https://fxbug.dev/42081363.\n" |
| |
| function main { |
| local single_run=true |
| local build=false |
| if is_feature_enabled "incremental"; then |
| # In incremental workflows, these defaults have changed. |
| # Keep old behavior if incremental is not enabled. |
| build=true |
| fi |
| local pave_args=() |
| local help=false |
| while (( $# )); do |
| case "$1" in |
| --help) |
| help=true |
| ;; |
| --no-build) |
| build=false |
| ;; |
| --build) |
| build=true |
| ;; |
| --keep-running) |
| single_run=false |
| ;; |
| # -1 is here for backward compatibility. |
| --run-once | -1) |
| single_run=true |
| ;; |
| *) |
| pave_args+=("$1") |
| ;; |
| esac |
| shift |
| done |
| |
| if $help; then |
| if ! $build; then |
| # bootserver options cannot be shown if depedencies cannot be built, so |
| # if --no-build flag is used, just show the simple help. |
| fx-command-help |
| exit 0 |
| fi |
| fx-command-help 2>&1 | grep -v "fx pave --help" >&2 |
| fx-info |
| fx-info "Building and executing 'pave.sh --help' to show bootserver specific options." |
| fx-info "Press Ctrl+C to interrupt." |
| fx-info |
| pave_args=(--help) |
| |
| else |
| if $single_run; then |
| pave_args+=( "-1" ) |
| fi |
| |
| name="$(get-device-name)" || exit $? |
| if [[ -n "$name" ]]; then |
| pave_args+=("-n" "${name}") |
| fi |
| |
| if ! fx-is-bringup; then |
| authkeys_path="$(get-ssh-authkeys)" || { |
| fx-error "Cannot continue without a valid authorized keys file." |
| exit 1 |
| } |
| pave_args+=(--authorized-keys "${authkeys_path}") |
| fi |
| fi |
| |
| # Find paving script. |
| flash_source=$(fx-command-run get-flash-source) |
| case "${flash_source}" in |
| flash-manifest:*) |
| paving_script="pave.sh" |
| if $build; then |
| local artifacts=($(fx-command-run list-build-artifacts pave)) || exit $? |
| fx-info "Building/refreshing targets ${artifacts[@]}" |
| fx-command-run build "${artifacts[@]}" |
| fi |
| ;; |
| product-bundle:*) |
| product_bundle="${flash_source#product-bundle:}" |
| paving_script="$(dirname "${product_bundle}")/pave.sh" |
| if $build; then |
| fx-info "Building/refreshing product bundle ${product_bundle}" |
| fx-command-run build "${paving_script}" "${product_bundle}" |
| fi |
| ;; |
| esac |
| |
| if [[ ! -f "${FUCHSIA_BUILD_DIR}/${paving_script}" ]]; then |
| fx-error "'pave.sh' script does not exist: ${paving_script}" |
| fx-error "Run 'fx pave --build' or 'fx build' to build it and" |
| fx-error "all the required artifacts to pave a device." |
| exit 1 |
| fi |
| |
| exec "${FUCHSIA_BUILD_DIR}/${paving_script}" "${pave_args[@]}" |
| } |
| |
| main "$@" |
| |