| #!/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 | |
| ### register a repository package server as a device's update source | |
| ## usage: fx add-update-source [--repo-name NAME] [--persist] | |
| ## | |
| ## Configure target device to use a new update source. | |
| ## | |
| ## --repo-name NAME Name of the repository package server to use as the update source. | |
| ## --persist Enable persistence of repo metadata. Disabled by default. | |
| ## | |
| ## | |
| ## NAME: | |
| ## If no name is supplied, the name defaults to configured default repository. | |
| ## | |
| ## Note: | |
| ## This is a wrapper for `ffx target repository register` | |
| 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 | |
| function usage { | |
| fx-command-help add-update-source | |
| } | |
| function main { | |
| fx-standard-switches "$@" | |
| set -- "${FX_ARGV[@]}" | |
| local repo_name="" | |
| local storage_type="" | |
| while [[ $# -ne 0 ]]; do | |
| case "$1" in | |
| --repo-name) | |
| repo_name="$2" | |
| shift | |
| ;; | |
| --persist) | |
| storage_type="persistent" | |
| ;; | |
| *) | |
| fx-error "Unrecognized option: $1" | |
| usage | |
| exit 1 | |
| esac | |
| shift | |
| done | |
| register_args=( target repository register ) | |
| if [[ -n "${storage_type}" ]]; then | |
| register_args+=( --storage-type "${storage_type}" ) | |
| fi | |
| if [[ -n "${repo_name}" ]]; then | |
| register_args+=( --repository "${repo_name}" ) | |
| fi | |
| # When alias conflict detected, replace with what is being registered here. | |
| register_args+=( --alias-conflict-mode replace ) | |
| fx-command-run ffx --target "$(get-device-name)" "${register_args[@]}" || return $? | |
| if [[ -n "${repo_name}" ]]; then | |
| fx-command-run shell update channel set "${repo_name}" | |
| err=$? | |
| if [[ $err -ne 0 ]]; then | |
| fx-error "Failed to change the update channel to '${repo_name}'" | |
| return "$err" | |
| fi | |
| fi | |
| } | |
| main "$@" |