#!/bin/bash

# We install some required libraries for building/compiling
# This script installs podman and qemu-user-static, which is required for the following Dockerfile to work.
# It omits the error "exec container process `/bin/sh`: Exec format error"
# The Dockerfile inside THIS directory is used to create two different arches for cross-building of the *.deb and *.rpm files

sudo apt install podman gsasl libgsasl7-dev libssl-dev libclang-dev cmake clang capnproto mosquitto mosquitto-clients devscripts build-essential debhelper debtags alien libpcsclite-dev qemu-user-static

sudo systemctl daemon-reload

# Please note: we need to install these images as root user!
pack="fabinfra/debianpackage"

arch="arm64/v8"
echo -e "\n+++++++++++++++++++++++++++++++++++++++++++"
echo -e "creating local podman container registry $pack. This may take a while ..."
echo -e "+++++++++++++++++++++++++++++++++++++++++++\n"
sudo time podman build --platform=linux/${arch} -f Dockerfile -t ${pack}_${arch} #this should get ubuntu:noble

arch="arm/v7"
echo -e "\n+++++++++++++++++++++++++++++++++++++++++++"
echo -e "creating local podman container registry $pack. This may take a while ..."
echo -e "+++++++++++++++++++++++++++++++++++++++++++\n"
sudo time podman build --platform=linux/${arch} -f Dockerfile -t ${pack}_${arch} #this should get alpine:latest

echo -e "\n+++++++++++++++++++++++++++++++++++++++++++"
echo "listing installed images ..."
echo -e "+++++++++++++++++++++++++++++++++++++++++++\n"
sudo podman images | grep localhost/fabinfra/

# note: unrequired images can be removed again by:
# sudo su && podman image rm localhost/fabinfra/<name>