#!/usr/bin/env bash set -euo pipefail ROOT=$(git rev-parse --show-toplevel) IPXE_VERSION=b41bda4413bf286d7b7a449bc05e1531da1eec2e IPXE_BIN=(bin/ipxe.pxe bin-x86_64-efi/ipxe.efi) IPXE_DIR=${ROOT}/.ipxe/ipxe-${IPXE_VERSION} function download_ipxe() { base_dir=$(dirname ${IPXE_DIR}) # Download the iPXE source if needed if [ ! -d "${IPXE_DIR}" ]; then mkdir -p "${base_dir}" curl -L https://github.com/ipxe/ipxe/archive/${IPXE_VERSION}.tar.gz | tar -xz -C "${base_dir}" fi } function patch_ipxe() { # Apply patches to iPXE source cd "${IPXE_DIR}/src" sed -i 's/^#undef[\t ]DOWNLOAD_PROTO_HTTPS.*$/#define DOWNLOAD_PROTO_HTTPS/g' config/general.h cat > embed.ipxe << EOF #!ipxe dhcp chain boot.ipxe || shell EOF cd - > /dev/null } function build_ipxe() { cd "${IPXE_DIR}/src" for bin in "${IPXE_BIN[@]}"; do path=${IPXE_DIR}/src/${bin} if [ ! -f "${path}" ]; then make -j$(nproc) ${bin} EMBED=embed.ipxe fi done cd - > /dev/null } function render() { ${ROOT}/tools/render } function host_tftp() { TFTP_DIR=$(mktemp --tmpdir -d tftp.XXX) chmod 755 ${TFTP_DIR} function cleanup() { rm -rf ${TFTP_DIR} } trap cleanup EXIT cp ${ROOT}/rendered/boot.ipxe ${TFTP_DIR} for bin in "${IPXE_BIN[@]}"; do path=${IPXE_DIR}/src/${bin} cp ${path} ${TFTP_DIR} done echo "Starting tftpd" sudo in.tftpd --verbosity 100 --permissive -L --secure ${TFTP_DIR} } download_ipxe patch_ipxe build_ipxe render host_tftp