2023-04-10 01:31:44 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eux
|
|
|
|
|
|
|
|
PACKER_VERSION=1.8.6
|
|
|
|
INSTALL_DIR=/usr/local/bin
|
|
|
|
ARCH=amd64
|
|
|
|
PACKER_FILE=packer_${PACKER_VERSION}_linux_${ARCH}
|
|
|
|
UPSTREAM="https://github.com/mkaczanowski/packer-builder-arm"
|
|
|
|
UPGRADE="false"
|
2023-04-11 06:02:14 +00:00
|
|
|
BUILD_DIR="$(pwd)/build"
|
2023-04-12 06:44:19 +00:00
|
|
|
FORCE_DEPENDENCY_INSTALL="no"
|
2023-04-10 01:31:44 +00:00
|
|
|
|
|
|
|
prep () {
|
2023-04-12 06:44:19 +00:00
|
|
|
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
|
|
|
|
fi
|
2023-04-11 06:02:14 +00:00
|
|
|
mkdir -p ${BUILD_DIR}
|
|
|
|
pushd ${BUILD_DIR}
|
2023-04-10 01:31:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
install_packer () {
|
|
|
|
if [ -x ${INSTALL_DIR}/packer ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
curl -LO https://releases.hashicorp.com/packer/${PACKER_VERSION}/${PACKER_FILE}.zip
|
|
|
|
unzip ${PACKER_FILE}
|
|
|
|
sudo mv packer ${INSTALL_DIR}/
|
|
|
|
rm ${PACKER_FILE}.zip
|
|
|
|
}
|
|
|
|
|
|
|
|
install_packer_builder_arm () {
|
|
|
|
if [ -x "${INSTALL_DIR}/packer-builder-arm" -a -z "${UPGRADE}" ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
git clone "${UPSTREAM}"
|
|
|
|
pushd "${UPSTREAM##*/}"
|
|
|
|
go mod download
|
|
|
|
go build
|
|
|
|
sudo mv packer-builder-arm ${INSTALL_DIR}/
|
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
2023-04-10 22:34:38 +00:00
|
|
|
cleanup () {
|
2023-04-10 01:31:44 +00:00
|
|
|
popd
|
|
|
|
}
|
|
|
|
|
|
|
|
prep
|
|
|
|
install_packer
|
|
|
|
install_packer_builder_arm
|
|
|
|
cleanup
|