blob: f23f96f96b779409de04b7acd421f57f2460ea8d [file] [log] [blame]
#!/bin/bash
# Copyright 2020 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=Other
### Remotely build, fetch and netboot
## usage: fx netboot-remote HOST [DIR] [--no-boot] [--no-build] [-- NETBOOT_ARGS]
##
## Connect to HOST, run a build using fx from DIR, fetch the artifacts and
## start the paver.
##
## --no-build do not build, just pull artifacts already present
## --no-boot do not start the bootserver, just pull the artifacts
## -- pass any arguments after the -- to the fx netboot command
##
## HOST the hostname to connect to
## DIR defaults to ~/fuchsia, the path to the FUCHSIA_DIR on HOST
## NETBOOT_ARGS arguments for the fx netboot command
##
## HOST and DIR are persisted in the file //.fx-remote-config and are reused as
## defaults in future invocations of any 'fx *-remote' tools.
set -o errexit
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/fx-remote.sh
fx-config-read
build=true
netboot=true
host=""
dir=""
args=()
while [[ $# -ne 0 ]]; do
case "$1" in
--help|-h)
fx-command-help
exit 0
;;
--no-build)
build=false
;;
--no-boot)
netboot=false
;;
--)
shift
args+=("$@")
break
;;
-*)
fx-error "Unknown flag: $1"
fx-command-help
exit 1
;;
*)
if [[ -z "${host}" ]]; then
host="$1"
elif [[ -z "${dir}" ]]; then
dir="$1"
else
fx-error "unexpected argument: '$1'"
exit 1
fi
;;
esac
shift
done
if cached=( $(load_remote_info "$host") ); then
host="${cached[0]}"
dir="${cached[1]}"
fi
if [[ -z "${host}" ]]; then
fx-error "HOST must be specified"
fx-command-help
exit 1
fi
if [[ -z "${dir}" ]]; then
if ssh "$host" ls \~/fuchsia/.jiri_root/bin/fx > /dev/null; then
dir="~/fuchsia"
else
fx-error "failed to find ~/fuchsia on $host, please specify DIR"
fx-command-help
exit 1
fi
fi
save_remote_info "$host" "$dir"
artifact_dir="${FUCHSIA_DIR}/out/fetched"
fetch_remote_build_artifacts "${host}" "${dir}" "${artifact_dir}" netboot $build
if "${netboot}"; then
if [[ -n "$(get-device-name)" ]]; then
args+=(-n $(get-device-name))
fi
fetch_or_build_tool "${host}" "${dir}" "${artifact_dir}" bootserver
cd "${artifact_dir}"
./netboot.sh "${args[@]}"
fi