Make sure the required packages are installed for build_rootfs

Signed-off-by: Henry Speiser <henry@speiser.net>
Change-Id: I6c4cfc361fd4a7271abf106dcb44c37ebfc8af85
diff --git a/frc971/rockpi/build_rootfs.sh b/frc971/rockpi/build_rootfs.sh
index a9ee64c..5625127 100755
--- a/frc971/rockpi/build_rootfs.sh
+++ b/frc971/rockpi/build_rootfs.sh
@@ -9,9 +9,31 @@
 KERNEL_VERSION=6.0.8-rt14-rockpi4b
 PARTITION="${IMAGE}.partition"
 
-# TODO(austin): Make sure flex, bison, gcc-aarch64-linux-gnu,
-# gcc-arm-none-eabi, device-tree-compiler, swig are installed
-# rather than let the user figure this out on their own the hard way.
+# Check if dependencies are missing.
+missing_deps=()
+REQUIRED_DEPS=(
+    flex
+    bison
+    gcc-arm-none-eabi
+    gcc-aarch64-linux-gnu
+    device-tree-compiler
+    swig
+)
+for dep in "${REQUIRED_DEPS[@]}"; do
+    if ! dpkg-query -W -f='${Status}' "${dep}" | grep -q "install ok installed"; then
+        missing_deps+=("${dep}")
+    fi
+done
+
+# Print missing dependencies
+if ((${#missing_deps[@]} != 0 )); then
+    echo "Missing dependencies, please install:"
+    echo apt install "${missing_deps[@]}"
+    exit 1
+else
+    echo -e "\033[32mAll dependencies are already installed\033[0m"
+fi
+
 export CC=aarch64-linux-gnu-
 
 # Reset any existing mounts.