| #!/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/image_build_vars.sh || exit $? |
| |
| 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 "${IMAGE_NETBOOT_ZBI}" netboot.sh |
| 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 |
| |
| # The script uses the ${IMAGE_NETBOOT_ZBI} relative path, relative to its own |
| # location. So copy the script into a temporary location next to the location |
| # where we'll write the temporary copy of ${IMAGE_NETBOOT_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. fxbug.dev/43305 for more info. |
| fx-zbi-default-compression \ |
| -o "${tmpdir}/${IMAGE_NETBOOT_ZBI}" \ |
| "${FUCHSIA_BUILD_DIR}/${IMAGE_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 "$@" |