| #!/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 | 
 |  | 
 | readonly base_packages_file="${FUCHSIA_BUILD_DIR}/base_packages.list" | 
 | # Determine if the given package name is in the base package list | 
 | function is-in-base { | 
 |   grep "^$1$" "${base_packages_file}" > /dev/null | 
 | } | 
 |  | 
 | function main { | 
 |   if [[ $# -lt 1 ]]; then | 
 |     fx-command-help | 
 |     exit 1 | 
 |   fi | 
 |  | 
 |   if [[ ! -f "${base_packages_file}" ]]; then | 
 |     echo >&2 "Base packages file not found, please update your build: ${base_packages_file}" | 
 |     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-amber-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 "$@" |