| #!/bin/bash |
| # Copyright 2017 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 |
| ### check if packages are in base and update the device if needed |
| ## usage: fx update-if-in-base PACKAGE_NAME [PACKAGE_NAME]* |
| ## |
| ## This command is to be used primarily by other commands, such as `fx test`. |
| ## |
| ## NOTE: once the incremental workflow lands, `fx ota` should always |
| ## execute, and this command won't be needed anymore. |
| |
| set -e |
| |
| 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/updates.sh || exit $? |
| fx-config-read |
| |
| # Determine if the given package name is in the base package list |
| function is-in-base { |
| grep "^$1$" "${FUCHSIA_BUILD_DIR}/base_packages.list" > /dev/null |
| } |
| |
| function main { |
| if [[ $# -lt 1 ]]; then |
| fx-command-help |
| exit 1 |
| fi |
| |
| local requires_update=0 |
| while [[ $# -gt 0 ]]; do |
| if [[ "$1" == "-h" || "$1" == "--help" ]]; then |
| fx-command-help |
| exit 0 |
| fi |
| local target="$1" |
| shift |
| if is-in-base "${target}"; then |
| requires_update=1 |
| break |
| fi |
| done |
| if (( requires_update )); then |
| check-for-package-server || return 1 |
| |
| echo >&2 "Package ${target} is in 'base', performing system update..." |
| fx-command-run ota |
| echo >&2 "System update complete, waiting for device to return" |
| fx-command-run wait |
| fi |
| } |
| |
| main "$@" |