blob: 112902e66b841f31bdc165128bee0a62b913e908 [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.
#### CATEGORY=Software delivery
### run bootserver for netbooting
## usage: fx netboot [-h|--help] [--no-build] [bootserver flags]
##
## --no-build Do not build netboot.zbi before starting server
##
## bootserver flags:
## Not all flags will be supported. Internally this script takes control over
## all positional arguments, the -1, -n and some other arguments. Configuration
## oriented flags such as -b and -w should work.
set -e
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
fx-config-read
build=true
while [[ $# -ge 1 ]]; do
case "$1" in
-h|--help)
fx-command-help
echo >&2
echo >&2 "Bootserver help follows (for bootserver flags):"
echo >&2
"${FUCHSIA_BUILD_DIR}/netboot.sh" --help
;;
--no-build)
build=false
;;
*)
break
esac
shift
done
name_args=()
name="$(get-device-name)" || exit $?
if [[ -n "$name" ]]; then
name_args+=("-n" "${name}")
fi
if "$build"; then
fx-command-run build $(fx-command-run list-build-artifacts netboot)
fi
netboot_script="${FUCHSIA_BUILD_DIR}/netboot.sh"
if [[ ! -x "${netboot_script}" ]]; then
fx-error "netboot script does not exist or is not executable: ${netboot_script}"
fx-error "Hint: try using \"--netboot\" in the \"fx set\" command."
exit 1
fi
authkeys_path="$(get-ssh-authkeys)" || {
fx-error "Cannot continue without a valid authorized keys file."
exit 1
}
tmpdir="${FUCHSIA_BUILD_DIR}.netboot.tmp"
mkdir "${tmpdir}"
trap 'rm -rf "${tmpdir}"' EXIT
# netboot.sh refers to the netboot ZBI by a relative path, so copy the script
# into a temporary location next to the location where we'll write the
# temporary copy of the ZBI.
cp "${netboot_script}" "${tmpdir}"
# XXX(raggi): the following is quite undesirable, as it takes internal
# dependencies on the build, but at present the ssh-key fixup below is hard to
# achieve otherwise.
mkdir "${tmpdir}/host_x64"
cp "${HOST_OUT_DIR}/bootserver" "${tmpdir}/host_x64/bootserver"
# Make a temporary image that adds in the ~/.ssh/fuchsia_authorized_keys file.
# Netboot doesn't require special compression. https://fxbug.dev/42119595 for more info.
netboot_zbi=$(fx-get-zbi netboot)
fx-zbi-default-compression \
-o "${tmpdir}/${netboot_zbi}" \
"${FUCHSIA_BUILD_DIR}/${netboot_zbi}" \
"--entry=data/ssh/authorized_keys=${authkeys_path}"
# Now run the copied script, which will use the temporary ZBI.
"${tmpdir}/netboot.sh" "${name_args[@]}" -1 "$@"