lots of documentation updates

This commit is contained in:
2023-04-12 08:01:57 +00:00
parent 81e70556db
commit 792dd139ca
12 changed files with 221 additions and 49 deletions

View File

@@ -4,17 +4,30 @@ set -euxo pipefail
IMAGE_TYPE="${1:-ubuntu}"
PACKER_BUILD_FILE="${2:-}"
SKIP_LOCAL_CACHE="${SKIP_LOCAL_CACHE:-no}"
errmsg () {
echo "$@" > /dev/stderr
}
IMAGE_TYPE="${1:-ubuntu}"
preflight () {
case "${IMAGE_TYPE}" in
ubuntu) PACKER_BUILD_FILE="boards/cm4-cluster-ubuntu-22.04.2.json" ;;
## TODO(kyle): look into building a Raspbian version if needed.
# raspbian) PACKER_BUILD_FILE="boards/raspberry-pi/raspios-lite-arm.json" ;;
ubuntu)
PACKER_BUILD_FILE="boards/pi-cm4-ubuntu-22.04.2.json" ;;
if [ "${SKIP_LOCAL_CACHE}" != "yes" ]
then
REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' boards/pi-cm4-ubuntu-22.04.2.json | grep https | tr -d ' \"')"
fi
custom)
PACKER_BUILD_FILE="${2:-}"
if [ "${SKIP_LOCAL_CACHE}" != "yes" ]
then
REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' ${PACKER_BUILD_FILE} | grep https | tr -d ' \"')"
fi
if [ -z "${PACKER_BUILD_FILE}" ]
then
errmsg "[!] custom board requires a board file path"
@@ -24,7 +37,6 @@ preflight () {
*)
errmsg "[!] invalid image type ${IMAGE_TYPE}."
errmsg "[!] valid image types are"
# errmsg " - raspbian"
errmsg " - ubuntu"
errmsg " - custom path/to/board/file"
exit 1
@@ -32,10 +44,43 @@ preflight () {
esac
}
cache_remote_url () {
if [ "${SKIP_LOCAL_CACHE}" != "yes" ]
then
echo "[+] skipping fetch of remote file: SKIP_LOCAL_CACHE=yes"
return 0
fi
local CACHED_FILE="$(jq '.builders[0].file_urls' boards/pi-cm4-ubuntu-22.04.2.json | grep -v https | tr -d ' \"')"
if [ -z "${CACHED_FILE}" ]
then
echo "[+] skipping fetch of remote file: no local file provided"
return 0
fi
if [ -z "${REMOTE_URL}" ]
then
echo "[+] skipping fetch of remote file: no remote file provided"
return 0
fi
if [ -s "${CACHED_FILE}" ]
then
echo "[+] skipping fetch of remote file: file already exists. To force redownloading,"
echo " run the following:"
echo ""
echo " rm ${CACHED_FILE}"
return 0
fi
curl -fsSL -o "${CACHED_FILE}" "${REMOTE_URL}"
}
build_image () {
sudo packer build ${PACKER_BUILD_FILE}
}
preflight
cache_remote_url
build_image

View File

@@ -9,12 +9,12 @@ PACKER_FILE=packer_${PACKER_VERSION}_linux_${ARCH}
UPSTREAM="https://github.com/mkaczanowski/packer-builder-arm"
UPGRADE="false"
BUILD_DIR="$(pwd)/build"
FORCE_DEPENDENCY_INSTALL="no"
FORCE_DEPENDENCY_INSTALL="${FORCE_DEPENDENCY_INSTALL:-no}"
prep () {
if [ -z "$(command -v git)" -o "${FORCE_DEPENDENCY_INSTALL}" = "yes" ]
then
sudo apt-get update && sudo apt-get -y install git unzip qemu-user-static e2fsprogs dosfstools libarchive-tools
sudo apt-get update && sudo apt-get -y install git unzip qemu-user-static e2fsprogs dosfstools libarchive-tools xz-utils jq
fi
mkdir -p ${BUILD_DIR}
pushd ${BUILD_DIR}

View File

@@ -3,9 +3,10 @@
set -euxo pipefail
PACKER_IMAGE_NAME="bladerunner/packer:latest"
FORCE_DOCKER_BUILD="${FORCE_DOCKER_BUILD:-no}"
preflight () {
if [ -z "$(docker image ls -q ${PACKER_IMAGE_NAME})" ]
if [ "${FORCE_DOCKER_BUILD}" = "yes" -o -z "$(docker image ls -q ${PACKER_IMAGE_NAME})" ]
then
docker image build -t "${PACKER_IMAGE_NAME}" .
fi

View File

@@ -1,34 +0,0 @@
#!/usr/bin/env bash
set -euxo pipefail
IMAGE_TYPE="${1:-ubuntu}"
select_image () {
case "${IMAGE_TYPE}" in
ubuntu)
PACKER_BUILD_FILE="boards/pi-cm4-ubuntu-22.04.2.json" ;;
REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' boards/pi-cm4-ubuntu-22.04.2.json | grep https | tr -d ' \"')"
raspbian) PACKER_BUILD_FILE="boards/raspberry-pi/raspios-lite-arm.json" ;;
PACKER_BUILD_FILE="boards/pi-cm4-ubuntu-22.04.2.json" ;;
REMOTE_IMAGE_URL="$(jq '.builders[0].file_urls' boards/pi-cm4-ubuntu-22.04.2.json | grep https | tr -d ' \"')"
custom)
PACKER_BUILD_FILE="${2:-}"
if [ -z "${PACKER_BUILD_FILE}" ]
then
errmsg "[!] custom board requires a board file path"
exit 1
fi
;;
*)
errmsg "[!] invalid image type ${IMAGE_TYPE}."
errmsg "[!] valid image types are"
errmsg " - raspbian"
errmsg " - ubuntu"
errmsg " - custom path/to/board/file"
exit 1
;;
esac
}