| #!/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=Device discovery | |
| ### unset the default device to interact with | |
| ## usage: fx unset-device | |
| ## | |
| ## Unset the default device to work with for the active build directory. See "fx set-device" | |
| ## for more information. | |
| set -e -o pipefail | |
| source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $? | |
| fx-standard-switches "$@" | |
| fx-config-read | |
| fx-fail-if-device-specified | |
| if [[ -z "${FUCHSIA_BUILD_DIR}" ]]; then | |
| # This codepath should be unreachable after `fx-config-read`, but we're | |
| # leaving it in as a health check. | |
| fx-error 'BUG: $FUCHSIA_BUILD_DIR is not defined in `unset-device`!' | |
| exit 1 | |
| fi | |
| echo "The default device has been unset for '${FUCHSIA_BUILD_DIR}'" | |
| rm -f "${FUCHSIA_BUILD_DIR}.device" | |
| # Ensure the below checks will report the correct error message. | |
| unset FUCHSIA_NODENAME | |
| # Check if the user has set a default target via environment variable(s) which | |
| # can override the effectiveness of this command. | |
| function overridden-env-var-error { | |
| # This line is executed after echoing `The default device has been unset for ...`. | |
| fx-error "However, you've overriden this by setting ${ENV_VARS}." | |
| fx-error "If you want to clear the default device, please unset the ${ENV_VAR_NAMES} environment variable." | |
| exit 1 | |
| } | |
| fx-if-target-set-by-env overridden-env-var-error |