bffh/debian/create-packages.sh
2025-03-11 02:02:47 +01:00

92 lines
3.2 KiB
Bash
Executable File

#!/bin/bash
#the dir containing our debian source data
SRCDIR=$(pwd)
REPODIR="$(dirname "$SRCDIR")"
#target dir where to put build packages
DOWNLOAD=$HOME/bffh-debian/
mkdir -p ${DOWNLOAD}
# architecture mapping array linux <-> rust
declare -A ARCHES_LR=(
["armv7"]=armv7-unknown-linux-gnueabihf
["aarch64"]=aarch64-unknown-linux-gnu
["amd64"]=x86_64-unknown-linux-gnu
)
#architecture mapping array linux <-> docker ubuntu:noble
# - https://hub.docker.com/_/ubuntu
# - https://github.com/docker-library/official-images#architectures-other-than-amd64
declare -A ARCHES_LD=(
["armv7"]=arm/v7 #it's NOT arm32/v7
["aarch64"]=arm64/v8
["amd64"]=NATIVE #just some pseudo
)
echo SRCDIR: $SRCDIR
BFFHV=$(grep "Standards-Version: " fabaccess-bffh-src/debian/control | awk -F ' ' '{print $2}')
echo BFFH target build version: ${BFFHV}
# https://www.cyberciti.biz/faq/bash-for-loop-array/
for ARCH_L in "${!ARCHES_LR[@]}"; do
ARCH_R=${ARCHES_LR[$ARCH_L]}
ARCH_D=${ARCHES_LD[$ARCH_L]}
echo -e "\n+++++++++++++++++++++++++++++++++++++++++++"
echo -e "ARCH_L (Linux) : $ARCH_L"
echo -e "ARCH_R (Rust) : $ARCH_R"
echo -e "ARCH_D (Docker) : $ARCH_D"
echo -e "+++++++++++++++++++++++++++++++++++++++++++\n"
# remove existing target dir if exists (from possible previous builds)
if [ -f fabaccess-bffh-${BFFHV}/ ]; then
rm -rf fabaccess-bffh-${BFFHV}/
fi
# Create a working dir copy which has the correct name (required by dpkg-buildpackage command)
cp -R fabaccess-bffh-src/ fabaccess-bffh-${BFFHV}/
# Replace target architecture in control file
sed "s/Architecture: {{REPLACE_ME}}/Architecture: any/" -i fabaccess-bffh-${BFFHV}/debian/control
# declare required compiled binaries and check for existence
BIN_BFFHD=${REPODIR}/target/${ARCH_R}/release/bffhd
BIN_FABFIRE_PROVISION=${REPODIR}/target/${ARCH_R}/release/fabfire_provision
if [ -f ${BIN_BFFHD} ]; then
cp ${BIN_BFFHD} fabaccess-bffh-${BFFHV}/usr/bin/
else
echo "Error: ${BIN_BFFHD} does not exist!"
exit 1
fi
if [ -f ${BIN_FABFIRE_PROVISION} ]; then
cp ${BIN_FABFIRE_PROVISION} fabaccess-bffh-${BFFHV}/usr/bin/
else
echo "Error: ${BIN_FABFIRE_PROVISION} does not exist!"
exit 1
fi
if [[ "$ARCH_L" == "amd64" ]]; then
echo "native architecture. no podman required"
else
echo "using podman"
#podman ps -a
# create fresh podman container with ...
# - a name using --name fabinfra_deb_arm64
# - fitting target architecture using --platform
# - starting detached (-d) to run in background (for attaching later on)
# - start to operate on it with interactive shell --interactive --tty (or short: -it)
# - overwrite existing container if existent by using --replace
# - adding the src directory to pass it into container by -v <host_dir>:<container_dir>
# - some environment vars (ARCH_LINUX, ARCH_RUST, required by the debian packager)
echo podman run --replace -d --tty --interactive -v ${SRCDIR}:/work -e ARCH_LINUX=${ARCH_L} -e ARCH_RUST=${ARCH_R} --name fabinfra_deb_${ARCH_L} --platform linux/${ARCH_D} localhost/fabinfra/debianpackage_${ARCH_D}
# now attach to that container and start building the packages
echo podman exec -u 0 --tty --interactive fabinfra_deb_${ARCH_L} bash
fi
done