From bfd2bcd4916160e440c22643a8826fc8048cc82c Mon Sep 17 00:00:00 2001 From: Eric Katzfey Date: Wed, 23 Oct 2024 00:40:04 -0700 Subject: [PATCH] AP_HAL_QURT: Add Debian packaging script and support files --- libraries/AP_HAL_QURT/packaging/.gitignore | 5 + .../AP_HAL_QURT/packaging/make_package.sh | 149 ++++++++++++++++++ .../packaging/pkg/control/control.in | 8 + .../packaging/pkg/control/postinst | 39 +++++ 4 files changed, 201 insertions(+) create mode 100644 libraries/AP_HAL_QURT/packaging/.gitignore create mode 100755 libraries/AP_HAL_QURT/packaging/make_package.sh create mode 100644 libraries/AP_HAL_QURT/packaging/pkg/control/control.in create mode 100755 libraries/AP_HAL_QURT/packaging/pkg/control/postinst diff --git a/libraries/AP_HAL_QURT/packaging/.gitignore b/libraries/AP_HAL_QURT/packaging/.gitignore new file mode 100644 index 00000000000000..eaa90ca25d79ca --- /dev/null +++ b/libraries/AP_HAL_QURT/packaging/.gitignore @@ -0,0 +1,5 @@ +*.deb +pkg/DEB +pkg/data +pkg/control/control + diff --git a/libraries/AP_HAL_QURT/packaging/make_package.sh b/libraries/AP_HAL_QURT/packaging/make_package.sh new file mode 100755 index 00000000000000..d673361deb7f20 --- /dev/null +++ b/libraries/AP_HAL_QURT/packaging/make_package.sh @@ -0,0 +1,149 @@ +#!/bin/bash + +set -e # exit on error to prevent bad ipk from being generated + +# get version numbers +FW_MAJOR=$(grep FW_MAJOR ArduCopter/version.h | cut -d' ' -f3) +FW_MINOR=$(grep FW_MINOR ArduCopter/version.h | cut -d' ' -f3) +FW_PATCH=$(grep FW_PATCH ArduCopter/version.h | cut -d' ' -f3) +GIT_VERSION=$(git rev-parse HEAD | cut -c1-8) + +VERSION="${FW_MAJOR}.${FW_MINOR}.${FW_PATCH}-${GIT_VERSION}" + +echo "Package Name: " $PACKAGE +echo "version Number: " $VERSION + +cd libraries/AP_HAL_QURT/packaging + +cat pkg/control/control.in | sed "s/FW_VERSION/$VERSION/g" > pkg/control/control + +################################################################################ +# Check arguments +################################################################################ + +USETIMESTAMP=false + +print_usage(){ + echo "" + echo " Package the current project into a deb package." + echo " You must build first to produce the binaries" + echo "" + echo " Usage:" + echo " ./make_package.sh" + echo " Build a DEB package" + echo "" + echo " ./make_package.sh timestamp" + echo " Build a DEB package with the current timestamp as a" + echo " suffix in both the package name and deb filename." + echo "" + echo "" +} + +process_argument () { + + if [ "$#" -ne 1 ]; then + echo "ERROR process_argument expected 1 argument" + exit 1 + fi + + ## convert argument to lower case for robustness + arg=$(echo "$1" | tr '[:upper:]' '[:lower:]') + case ${arg} in + "") + ;; + "-t"|"timestamp"|"--timestamp") + echo "using timestamp suffix" + USETIMESTAMP=true + ;; + *) + echo "invalid option" + print_usage + exit 1 + esac +} + +## parse all arguments or run wizard +for var in "$@" +do + process_argument $var +done + +################################################################################ +# variables +################################################################################ +PACKAGE=$(cat pkg/control/control | grep "Package" | cut -d' ' -f 2) + +DATA_DIR=pkg/data +CONTROL_DIR=pkg/control +DEB_DIR=pkg/DEB + +################################################################################ +# start with a little cleanup to remove old files +################################################################################ +# remove data directory where 'make install' installed to +sudo rm -rf $DATA_DIR +mkdir $DATA_DIR + +# remove deb packaging folders +rm -rf $DEB_DIR + +# remove old deb packages +rm -f *.deb + +################################################################################ +## install compiled stuff into data directory +################################################################################ + +if [ -f ../../../build/QURT/ardupilot ] && \ + [ -f ../../../build/QURT/bin/arducopter ]; then + + # Copy the SLPI DSP AP library + sudo mkdir -p $DATA_DIR/usr/lib/rfsa/adsp + sudo cp ../../../build/QURT/bin/arducopter $DATA_DIR/usr/lib/rfsa/adsp/ArduPilot.so + + # Install executables + sudo mkdir -p $DATA_DIR/usr/bin + sudo cp ../../../build/QURT/ardupilot $DATA_DIR/usr/bin + sudo cp ../ap_host/service/voxl-ardupilot $DATA_DIR/usr/bin + sudo chmod a+x $DATA_DIR/usr/bin/ardupilot + sudo chmod a+x $DATA_DIR/usr/bin/voxl-ardupilot + + # Create necessary directories for ArduPilot operation + sudo mkdir -p $DATA_DIR/data/APM + + # Install default parameter files + sudo cp ../../../Tools/Frame_params/ModalAI/*.parm $DATA_DIR/data/APM + + sudo mkdir -p $DATA_DIR/etc/systemd/system/ + sudo cp ../ap_host/service/voxl-ardupilot.service $DATA_DIR/etc/systemd/system/ + +else + echo "Error: Build artifacts not found" + exit 1 +fi + +################################################################################ +# make a DEB package +################################################################################ + +echo "starting building Debian Package" + +## make a folder dedicated to Deb building and copy the requires debian-binary file in +mkdir $DEB_DIR + +## copy the control stuff in +cp -rf $CONTROL_DIR/ $DEB_DIR/DEBIAN +cp -rf $DATA_DIR/* $DEB_DIR + +## update version with timestamp if enabled +if $USETIMESTAMP; then + dts=$(date +"%Y%m%d%H%M") + sed -E -i "s/Version.*/&-$dts/" $DEB_DIR/DEBIAN/control + VERSION="${VERSION}-${dts}" + echo "new version with timestamp: $VERSION" +fi + +DEB_NAME="${PACKAGE}_${VERSION}_arm64.deb" +dpkg-deb --build "${DEB_DIR}" "${DEB_NAME}" + +echo "DONE" diff --git a/libraries/AP_HAL_QURT/packaging/pkg/control/control.in b/libraries/AP_HAL_QURT/packaging/pkg/control/control.in new file mode 100644 index 00000000000000..1ad0196bdf57b2 --- /dev/null +++ b/libraries/AP_HAL_QURT/packaging/pkg/control/control.in @@ -0,0 +1,8 @@ +Package: voxl-ardupilot +Version: FW_VERSION +Section: devel +Priority: optional +Architecture: arm64 +Depends: modalai-slpi(>=1.1.19), libslpi-link +Maintainer: Eric Katzfey +Description: ModalAI ArduPilot flight controller diff --git a/libraries/AP_HAL_QURT/packaging/pkg/control/postinst b/libraries/AP_HAL_QURT/packaging/pkg/control/postinst new file mode 100755 index 00000000000000..04f668085e805a --- /dev/null +++ b/libraries/AP_HAL_QURT/packaging/pkg/control/postinst @@ -0,0 +1,39 @@ +#!/bin/bash + +# Create directory for APM use +cd /data +mkdir -p APM +chown system:system APM + +# Make sure the run scripts are executable +cd /usr/bin +chmod a+x voxl-ardupilot + +# Check to see if a DSP test signature exists +if /bin/ls /usr/lib/rfsa/adsp/testsig-*.so &> /dev/null; then + /bin/echo "Found DSP signature file" +else + /bin/echo "Could not find DSP signature file" + # Look for the DSP signature generation script + if [ -f /share/modalai/qrb5165-slpi-test-sig/generate-test-sig.sh ]; then + /bin/echo "Attempting to generate the DSP signature file" + # Automatically generate the test signature so that px4 can run on SLPI DSP + /share/modalai/qrb5165-slpi-test-sig/generate-test-sig.sh + else + /bin/echo "Could not find the DSP signature file generation script" + fi +fi + +# Always flush all changes to disk +/bin/sync + +cd - + +# try to reload services, but don't fail if it can't +set +e +if [ -f /bin/systemctl ]; then + systemctl daemon-reload +fi + +# exit 0 even if systemctl failed +exit 0