#!/bin/bash -x : ${TOPDIR:=/usr/src/packages} container="buildcont" set -e # Only run the post build check for aarch64 [ "$(uname -m)" == "aarch64" ] || exit 0 # Build service provides the container image as a .tar file img=$(ls ${TOPDIR}/DOCKER/*.tar) echo "Found image '" ${img} "'" [ -f "${img}" ] || exit 1 # Only consider images with 'iso' as part of the name echo "${img}" | grep -q iso || exit 0 # import .tar with buildah buildah from --name "${container}" "docker-archive:${img}" # mount container to access its content mnt=$(buildah mount "${container}") # there must be an .iso file within iso=$(ls "${mnt}"/elemental-iso/*.iso) echo "Found ISO '" ${iso} "'" # exit here if not [ -f "${iso}" ] || exit 1 # something like sl-micro-6.0-base.aarch64-2.2.0-Build14.2 basename=$(basename ${iso} .iso) # split at '.' into DOTS[] IFS='.' read -ra DOTS <<< "${basename}" # split "0-base" at '-' into DASHES[] IFS='-' read -ra DASHES <<< "${DOTS[1]}" # extract the flavor (base, rt, kvm, ...) flavor="${DASHES[1]}" # prepend dash if flavor is non-empty # covers rpi.raw (for empty flavor) vs rpi-${flavor}.raw (for non-empty) [ -n "$flavor" ] && flavor="-${flavor}" mkdir -p "${TOPDIR}/OTHER/image" # create a mountpoint and mount the iso mkdir iso mount -o loop "${iso}" iso # create a mountpoint and mount the rootfs.squashfs that's inside the iso mkdir rootfs mount -o loop iso/rootfs.squashfs rootfs # extract the image size from the "build config" img_size=$(grep -m 1 "%img_size" ~/.rpmmacros | tr -d "\n" | cut -d " " -f 2) # extract two last project path elements ({Stable,Staging,Dev}:TealXX) # replace colon with dash project=$(grep -m 1 "%_project" ~/.rpmmacros | tr -d "\n" | rev | cut -d ":" -f 1,2 | rev | tr ":" "-") # create an empty image file and a respective loop device truncate -s $((${img_size}*1024*1024)) rpi.img # create a primary FAT partition with 256MB (for kernel + firmware) # create a primary Linux partition covering the remainder sfdisk rpi.img < img/iso-config/01_rpi-install-hook.yaml name: "Raspberry Pi after install hook" stages: after-install: - ©firmware name: "Copy firmware to EFI partition" commands: - cp -a /run/elemental/workingtree/boot/vc/* /run/elemental/efi after-reset: - <<: *copyfirmware HOOK else cat << HOOK > img/iso-config/01_rpi-install-hook.yaml name: "Raspberry Pi after install hook" stages: after-install: - ©firmware name: "Copy firmware to EFI partition" commands: - cp /run/elemental/workingtree/boot/*.fd /run/elemental/efi - cp /run/elemental/workingtree/boot/*.dtb /run/elemental/efi - cp /run/elemental/workingtree/boot/config.txt /run/elemental/efi - cp /run/elemental/workingtree/boot/fixup4.dat /run/elemental/efi - cp /run/elemental/workingtree/boot/start4.elf /run/elemental/efi - cp -a /run/elemental/workingtree/boot/firmware /run/elemental/efi - cp -a /run/elemental/workingtree/boot/overlays /run/elemental/efi after-reset: - <<: *copyfirmware HOOK fi # undo all mounts, loopback devices, etc. umount img rmdir img umount rootfs rmdir rootfs losetup -d ${loop} umount iso rmdir iso # copy the image as rpi.raw (buildservice checks extensions) mkdir -p "${TOPDIR}/OTHER" rawname="rpi${flavor}.raw" mv rpi.img ${rawname} sha256sum ${rawname} > "${TOPDIR}/OTHER/${rawname}.sha256" mv ${rawname} "${TOPDIR}/OTHER" ln "${TOPDIR}/OTHER/${rawname}" "${TOPDIR}/OTHER/rpi${flavor}-${project}-`date +'%Y%m%d%H%M%S'`.raw" # release the container buildah umount "${container}" buildah rm "${container}"