2023-04-11 20:41:16 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -euxo pipefail
|
|
|
|
|
|
|
|
IMAGE_TYPE="${1:-ubuntu}"
|
2023-04-12 04:55:00 +00:00
|
|
|
PACKER_BUILD_FILE="${2:-}"
|
2023-04-11 20:41:16 +00:00
|
|
|
|
|
|
|
errmsg () {
|
|
|
|
echo "$@" > /dev/stderr
|
|
|
|
}
|
|
|
|
|
|
|
|
preflight () {
|
2023-04-12 00:01:56 +00:00
|
|
|
case "${IMAGE_TYPE}" in
|
2023-04-12 05:15:34 +00:00
|
|
|
ubuntu) PACKER_BUILD_FILE="boards/cm4-cluster-ubuntu-22.04.2.json" ;;
|
2023-04-12 00:01:56 +00:00
|
|
|
raspbian) PACKER_BUILD_FILE="boards/raspberry-pi/raspios-lite-arm.json" ;;
|
|
|
|
custom)
|
|
|
|
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"
|
2023-04-11 20:41:16 +00:00
|
|
|
exit 1
|
2023-04-12 00:01:56 +00:00
|
|
|
;;
|
2023-04-11 20:41:16 +00:00
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
|
|
|
build_image () {
|
2023-04-12 00:01:56 +00:00
|
|
|
sudo packer build ${PACKER_BUILD_FILE}
|
|
|
|
}
|
|
|
|
|
|
|
|
preflight
|
|
|
|
build_image
|
|
|
|
|