-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Aditional files to the debian package #12
base: main
Are you sure you want to change the base?
Conversation
Can you add some descriptions about the practical impact of this? What will the impact be on the CANBus drivers we occasionally have hiccups with? |
GITHUB_WORKSPACE="$PWD" greenzie-dkms mkdeb -d | ||
cd /tmp/debians/ && tar cvf /tmp/debians/alldebs.tar *.deb | ||
ls -lah | ||
bash -x "$PWD/build_dmks.sh" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New build script that can be readed to understand how the process works.
echo "==> Checking for the module name and version in $DRIVER_CODE_DIR/dkms.conf" | ||
# Define module name and version based on dkms.conf | ||
MODULE_NAME=$(grep '^PACKAGE_NAME' "$DRIVER_CODE_DIR/dkms.conf" | awk -F'=' '{print $2}' | tr -d ' ') | ||
VERSION=$(grep '^PACKAGE_VERSION' "$DRIVER_CODE_DIR/dkms.conf" | awk -F'=' '{print $2}' | tr -d ' ') | ||
|
||
if [ -z "$MODULE_NAME" ] || [ -z "$VERSION" ]; then | ||
echo "Error: Module name or version not found in dkms.conf" | ||
exit 1 | ||
fi | ||
|
||
echo "==> Module name: $MODULE_NAME" | ||
echo "==> Version: $VERSION" | ||
|
||
echo "==> Checking for required tools and dependencies..." | ||
# Check if dkms is installed, install if missing | ||
if ! command -v dkms &> /dev/null; then | ||
echo "dkms command not found. Installing dkms..." | ||
sudo apt update && sudo apt install -y dkms | ||
fi | ||
|
||
# Check if debhelper is installed, install if missing | ||
if ! dpkg-query -W -f='${Status}' debhelper 2>/dev/null | grep -q "install ok installed"; then | ||
echo "debhelper not found. Installing debhelper..." | ||
sudo apt install -y debhelper | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check that everything that is needed is installed or it installs it.
# Add the module | ||
if dkms status -m "$MODULE_NAME" -v "$VERSION" | grep -q "$VERSION"; then | ||
echo "Module '$MODULE_NAME' already exists" | ||
else | ||
sudo dkms add -m "$MODULE_NAME" -v "$VERSION" | ||
fi | ||
|
||
# Create Debian package | ||
sudo dkms mkdeb -m "$MODULE_NAME" -v "$VERSION" --kernelsourcedir="$DKMS_KERNEL_SOURCE_DIR" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use dkms to create a debian package with the source code of the module/driver.
echo "==> We have found the .deb package at $DEB_FILE" | ||
# Unpack the .deb package | ||
if [ -f "$DEB_FILE" ]; then | ||
echo "==> Unpacking $DEB_FILE for modification..." | ||
mkdir -p "$UNPACK_DIR" | ||
dpkg-deb -R "$DEB_FILE" "$UNPACK_DIR" | ||
else | ||
echo "ERROR: .deb file not found in $DST_DIR." | ||
exit 1 | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unpack the created Debian file
echo "==> We have unpacked the .deb package to $UNPACK_DIR" | ||
echo "==> Before adding files, the unpacked package structure is as follows:" | ||
ls "$UNPACK_DIR" | ||
echo "==> Now we will add the necessary files to the unpacked package." | ||
|
||
# Create necessary directories in unpacked package | ||
mkdir -p "$UNPACK_DIR/lib/systemd/system" | ||
mkdir -p "$UNPACK_DIR/lib/udev/rules.d" | ||
mkdir -p "$UNPACK_DIR/etc/modules-load.d" | ||
mkdir -p "$UNPACK_DIR/etc/default" | ||
|
||
# Copy files into the unpacked structure | ||
ls "$PROJECT_DIR" | ||
cp "$PROJECT_DIR/emuccan.service" "$UNPACK_DIR/lib/systemd/system/emuccan.service" | ||
cp "$PROJECT_DIR/emuccan.udev" "$UNPACK_DIR/lib/udev/rules.d/60-emuccan.rules" | ||
cp "$PROJECT_DIR/emuccan.conf" "$UNPACK_DIR/etc/modules-load.d/emuccan.conf" | ||
cp "$PROJECT_DIR/emuccan.default" "$UNPACK_DIR/etc/default/emuccan" | ||
|
||
echo "==> We added the files to the unpacked package." | ||
rm -rf "$UNPACK_DIR/usr/src/${MODULE_NAME}-${VERSION}/debian" | ||
echo "==> After adding files, the unpacked package structure is as follows:" | ||
ls "$UNPACK_DIR" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add the missing files
# Rebuild the .deb package with the added files | ||
echo "==> Now we will rebuild the .deb package with the added files." | ||
echo "==> Repacking the modified .deb package..." | ||
dpkg-deb -b "$UNPACK_DIR" "$DST_DIR/modified_${MODULE_NAME}_${VERSION}.deb" | ||
|
||
# Clean up | ||
rm -rf "$UNPACK_DIR" | ||
echo "==> Repackaging complete. Modified package located at $DST_DIR/modified_${MODULE_NAME}_${VERSION}.deb" | ||
echo "==> Replacing the original package with the modified package." | ||
mv "$DST_DIR/modified_${MODULE_NAME}_${VERSION}.deb" "$DEB_FILE" | ||
echo "==> Done. Final modified package is located at $DEB_FILE" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pack again and replace the generated one.
driver/Makefile
Outdated
KVERSION ?= $(ls /lib/modules | tail -n 1) | ||
KERNEL_SRC ?= $(DKMS_KERNEL_SOURCE_DIR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build for the installed kernel sources instead of the reported by uname -r.
This resolves problems on containers and in the mowers we always have a fixed version of the kernel.
PACKAGE_NAME=emuccan | ||
PACKAGE_VERSION=2.6.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra quotes that generate a malfunction when parsed by shell scripts.
Yeah, sorry as it's a fix for something reported by Evan I missed adding more context (I thought you were also in the loop).
I'm also wondering if we have been using the dkms version of the module during the last few months. I think we have not as this is the first time that we realized that the service is not installed with the new deb package. |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all looks reasonable to me.
Ok. We have a problem:
|
Tested in GZDEV9. @edavies64 can we test this on a real mower and get it reviewed and merged? |
The 2 key things to verify after the package is installed.
I'm not sure if we have any mowers with an emuccan module at the office (they're fairly rare these days) |
Testing in GZDEV25.
Checks:
|
Same results for GZ25! |
asciinema recording of both tests. |
https://app.shortcut.com/greenzie/story/41781/fix-emuccan-installation-to-include-services-rules-etc
The main reason for these modifications is to add to the generated debian dkms package the files that were previously distributed with the package and that were lost when moving to the dkms version.
@edavies64 noticed that with the installation of the new package the emuccan.service file was missing. Reviewing the process, not only that file was missing, but also the udev rules and the default for bash.
This PR is created to try to solve that problem.
After searching for hours, with no luck, how to add extra files to a Debian package generated with
dkms
, we have proceeded with a different approach. The deb file is created withdkms
, decompressed, the extra files are added, and then compressed again. It is not the most orthodox, but it seems to work and it avoids the other possible solution which is to create a new Debian package only with the extra packages that are not the module code.In this PR we have also taken the opportunity to change the old CI and create a shell script that can be used both locally and in the CI, making this process clearer for any developer.
Changes
Makefile
to specify kernel headers dynamically.build_dmks.sh
script for streamlined DKMS build and packaging..circleci/config.yml
to align with the new artifact storage structure.build_dmks.sh
.Testing
It needs to be tested on a real mower, and everything that is required must be installed now.