blob: bf26f30df6a811c2e91884cc22153afb2b579b4e [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.
### run bootserver for netbooting
## usage: fx netboot [extra bootserver arguments]
set -e
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/image_build_vars.sh || exit $?
name_args=()
name="$(get-device-name)"
if [[ -n "$name" ]]; then
name_args+=("-n" "${name}")
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
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}"
# Make a temporary image that adds in the .ssh/authorized_keys file.
fx-zbi \
-o "${tmpdir}/${IMAGE_NETBOOT_ZBI}" \
"${FUCHSIA_BUILD_DIR}/${IMAGE_NETBOOT_ZBI}" \
"--entry=data/ssh/authorized_keys=${FUCHSIA_DIR}/.ssh/authorized_keys"
# Now run the copied script, which will use the temporary ZBI.
"${tmpdir}/netboot.sh" "${name_args[@]}" "$@"