sysdeploy/ipxe.inc

72 lines
2.3 KiB
Bash

#!/bin/bash
function download_and_verify_ipxe()
{
local ipxe_path="$1"
local ipxeshasum1='a'
local ipxeshasum2='b'
which wget && which jq && which curl || /bin/false
if [ $? -ne 0 ]; then
apt update -yq && apt -yq install wget jq curl
fi
# This gets the info for the most current release, in JSON format
release_info=$(curl "https://git.bitmessage.org/api/v1/repos/maxweiss/ipxe_scripts/releases?per_page=1&page=1&limit=1")
lkrn_url=$(echo ${release_info} | jq '.[0].assets[] | select(.name=="ipxe.lkrn")' | jq -r .browser_download_url | tr -d '\n')
shasums_url=$(echo ${release_info} | jq '.[0].assets[] | select(.name=="SHA256SUMS")' | jq -r .browser_download_url | tr -d '\n')
if [[ -z $lkrn_url ]] || [[ $lkrn_url = *[^[:space:]]* ]]; then
echo "download failed" > "$ipxe_path"
else
wget "${lkrn_url}" -O "$ipxe_path" || echo "download failed" > "$ipxe_path"
fi
if [[ -z $shasums_url ]] || [[ $shasums_url = *[^[:space:]]* ]]; then
echo "z ipxe.lkrn" > "${ipxe_path}.sha256sums"
else
wget "${shasums_url}" -O "${ipxe_path}.sha256sums" || echo "z ipxe.lkrn" > "${ipxe_path}.sha256sums"
fi
ipxeshasum1=$(cat "${ipxe_path}.sha256sums" | grep "ipxe.lkrn" | awk '{print $1}' | tr -d '\n')
ipxeshasum2=$(sha256sum "$ipxe_path" | awk '{print $1}' | tr -d '\n')
rm -f "${ipxe_path}.sha256sums"
if [ "${ipxeshasum1}" != "${ipxeshasum1}" ]; then
ipxe_dl_verify=1
fi
}
function install_ipxe()
{
local ipxe_install_path="$1"
local temp_dir="$(mktemp -d)"
local ipxe_path="${temp_dir}/ipxe.lkrn"
ipxe_dl_verify=0
download_and_verify_ipxe "$ipxe_path"
if (( ipxe_dl_verify > 0 )); then
>&2 echo ""
>&2 echo "Failed to download and verify IPXE kernel binary."
>&2 echo "In order to avoid disk partition issues, the syslinux install process"
>&2 echo "will continue. But you must manually download and copy the ipxe x86"
>&2 echo "lkrn file to ${ipxe_install_path}. If a file currently exists at that"
>&2 echo "path, it has not been touched."
>&2 echo ""
else
rm -f "${ipxe_install_path}"
cp "${ipxe_path}" "${ipxe_install_path}"
fi
unset ipxe_dl_verify
rm -f "$ipxe_path"
rm -rf "$temp_dir"
}
# vim: set ft=sh: