From 29b3c766a8bab920d19fc91e16787d6a42a511da Mon Sep 17 00:00:00 2001
From: Johannes Schauer Marin Rodrigues <josch@mister-muffin.de>
Date: Wed, 16 Feb 2022 14:08:18 +0100
Subject: [PATCH] check whether all required packages are installed

---
 reform2-imx8mq/mkimage.sh | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)

diff --git a/reform2-imx8mq/mkimage.sh b/reform2-imx8mq/mkimage.sh
index c078b51..07bbf83 100755
--- a/reform2-imx8mq/mkimage.sh
+++ b/reform2-imx8mq/mkimage.sh
@@ -4,8 +4,22 @@ set -x
 set -e
 
 # make sure build tools are installed
-# FIXME: replace this by a check that everything is installed
-#sudo apt-get -y install parted multistrap udisks2 gcc-aarch64-linux-gnu make device-tree-compiler qemu-user-static binfmt-support build-essential bison flex libssl-dev mmdebstrap
+DEPS="mmdebstrap genext2fs e2fsprogs binfmt-support git mount arch-test qemu-user-static parted"
+if [ "$(dpkg-query --showformat '${db:Status-Status}\n' --show $DEPS | sort -u)" != "installed" ]; then
+	echo "Not all dependencies of this script are installed."
+	echo "Run the following command to install them:"
+	echo
+	echo "    sudo apt install $DEPS"
+	exit 1
+fi
+if dpkg --compare-versions "$(dpkg-query --showformat='${Version}\n' --show mmdebstrap)" lt "0.8.4-1"; then
+	echo "mmdebstrap version must be >= 0.8.4-1"
+	exit 1
+fi
+if dpkg --compare-versions "$(dpkg-query --showformat='${Version}\n' --show genext2fs)" lt "1.5.0-2"; then
+	echo "genext2fs version must be >= 1.5.0-2"
+	exit 1
+fi
 
 # if we are in a git repository and if SOURCE_DATE_EPOCH is not set, use the
 # timestamp of the latest git commit
-- 
GitLab