blob: 16748be88e16d15309b76bd8cf34f49d3c2f8f53 [file] [log] [blame]
#!/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.
### forward local ports to Dart VMs on the device.
## usage: fx dart-tunnel [-h|--help] [-v|--verbose] [<isolate>]
##
## Creates an SSH tunnel with the device's running Dart VM(s) and leaves it open
## until the user chooses to close it. Supplying an Isolate name will attempt to
## connect to all isolates whose name match.
##
## The verbose flag is strongly discouraged unless you are debugging.
##
## This command requires Topaz in order to run.
##
## Arguments:
## -h|--help Print out this message.
DEVSHELL_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
VERBOSE=false
source "${DEVSHELL_DIR}"/lib/vars.sh || exit $?
fx-config-read
case $1 in
-h|--help)
fx-command-help
exit 0
;;
-v|--verbose)
shift # name
VERBOSE=true
;;
esac
case "$(uname -s)" in
Linux)
PREBUILT_DART="${DEVSHELL_DIR}/../../topaz/tools/prebuilt-dart-sdk/linux-x64/bin/dart"
;;
Darwin)
PREBUILT_DART="${DEVSHELL_DIR}/../../topaz/tools/prebuilt-dart-sdk/mac-x64/bin/dart"
;;
esac
IP_ADDR_LINK_LOCAL="$(get-fuchsia-device-addr)"
# Strips the back of the string the longest match of '%' followed by
# any characters (the first two '%' characters are just the bash syntax).
IP_ADDR="${IP_ADDR_LINK_LOCAL%%%*}"
# Splits from the front of the string the longest match of any character
# followed by '%'.
IP_IFACE="${IP_ADDR_LINK_LOCAL##*%}"
SSH_CONFIG="${FUCHSIA_BUILD_DIR}/ssh-keys/ssh_config"
# Just compress the rest of the args to an array here.
ARGS="$(echo "$@")"
DART_TUNNEL_LIB_DIR="${DEVSHELL_DIR}/dart-tunnel-lib"
DART_TUNNEL_PACKAGES="${DART_TUNNEL_LIB_DIR}/dart-tunnel.packages"
DART_BIN="${DART_TUNNEL_LIB_DIR}/dart-tunnel.dart"
# Conditionally prints the --verbose flag.
function _verbose_flag() {
if [ "${VERBOSE}" = true ]; then
echo "--verbose"
fi
}
"${PREBUILT_DART}" --packages="${DART_TUNNEL_PACKAGES}" \
"${DART_BIN}" \
--ssh-config="${SSH_CONFIG}" \
--ip-address="${IP_ADDR}" \
--network-interface="${IP_IFACE}" \
--isolate="$ARGS" \
"$(_verbose_flag)"