blob: b9edbff2879c75f8d168974373ded61d46537fca [file] [log] [blame]
#!/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 {
# In base_packages.list, content.manifests is an array of paths. This query returns the string
# "true" if the final segment of any of the paths is equal to $1, otherwise it returns the string
# "false".
local query=".content .manifests | map(. / \"/\" | .[-1]) | index(\"$1\") != null"
local present=$(fx-command-run jq "$query" "${FUCHSIA_BUILD_DIR}/base_packages.list")
local err=$?
if [[ $err -ne 0 ]]; then
fx-error "Unable to parse the base package list: ${FUCHSIA_BUILD_DIR}/base_packages.list"
return err
fi
case "$present" in
"true") return 0 ;;
"false") return 1 ;;
*)
fx-error "Unexpected output parsing base package list: $present"
return 2
esac
}
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 "$@"