Skip to content
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

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ root_directory: &root_directory

load_artifacts: &load_artifacts
attach_workspace:
at: /tmp/debians
at: $PWD/artifacts/

jobs:
debian_dkms_build:
Expand All @@ -26,19 +26,16 @@ jobs:
- run:
name: "Package debs (debuild)"
command: |
# build is going to fail but it's needed to generate the debs
ls -lah
pwd
echo "$PWD"
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"
Copy link
Contributor Author

@orensbruli orensbruli Nov 3, 2024

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.

- store_artifacts:
path: /tmp/debians
destination: pciusb381-debian-package
path: artifacts/
destination: emuccan-debian-package
- persist_to_workspace:
# Must be an absolute path, or relative path from working_directory. This is a directory in the execution
# environment which is taken to be the root directory of the workspace.
root: /tmp/debians
root: artifacts/
# Must be relative path from root
paths:
- '*'
Expand Down
123 changes: 123 additions & 0 deletions build_dmks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash
set -e

PROJECT_DIR=${2:-$PWD}
DRIVER_CODE_DIR=${1:-"$PROJECT_DIR/driver"}

echo "==> Project directory: $PROJECT_DIR"
echo "==> Driver code directory: $DRIVER_CODE_DIR"

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
Comment on lines +10 to +34
Copy link
Contributor Author

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.


echo "==> Preparing to use dkms to package the module..."
# Ensure the module directory exists in /usr/src
WORKSPACE="/usr/src/${MODULE_NAME}-${VERSION}"
sudo rm -rf "$WORKSPACE" # Remove if it exists
sudo mkdir -p "$WORKSPACE"
sudo cp -r "$DRIVER_CODE_DIR"/* "$WORKSPACE"


# 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"
Comment on lines +44 to +52
Copy link
Contributor Author

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.



SRC_DIR="/var/lib/dkms/${MODULE_NAME}/${VERSION}/deb/"
DST_DIR="$PROJECT_DIR/artifacts"
if [ -d "$SRC_DIR" ]; then
rm -rf "$DST_DIR" || true
sudo mkdir -p "$DST_DIR"
cp -r "$SRC_DIR"/*.deb "$DST_DIR"
else
echo "==> ERROR: Source directory $SRC_DIR does not exist; skipping artifact creation."
exit 1
fi

echo "==> Ok, now we will modify the .deb package to include additional files."
echo "==> We are doing this because we have not found a way to include additional files in the dkms package."
echo "==> This is a workaround to include the systemd service file, udev rules, and other configuration files."

echo "==> First, we will unpack the .deb package"
# Define paths for the unpack and repack process
DEB_FILE=$(find "$DST_DIR" -name "*.deb" | head -n 1)
UNPACK_DIR="unpacked_deb"

rm -rf "$UNPACK_DIR" || true

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
Comment on lines +77 to +86
Copy link
Contributor Author

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"
Comment on lines +88 to +109
Copy link
Contributor Author

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"

Comment on lines +112 to +123
Copy link
Contributor Author

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.

4 changes: 2 additions & 2 deletions driver/dkms.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PACKAGE_NAME="emuccan"
PACKAGE_VERSION="2.6.1"
PACKAGE_NAME=emuccan
PACKAGE_VERSION=2.6.1
Comment on lines +1 to +2
Copy link
Contributor Author

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.

CLEAN="make clean KVERSION=$kernelver"
MAKE[0]="make KVERSION=$kernelver"
BUILT_MODULE_NAME[0]="emuc2socketcan"
Expand Down
2 changes: 1 addition & 1 deletion driver/emuccan-dkms-mkdeb/debian/compat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7
9
5 changes: 4 additions & 1 deletion driver/emuccan-dkms-mkdeb/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ Source: DEBIAN_PACKAGE-dkms
Section: misc
Priority: optional
Maintainer: Greenzie Developers <[email protected]>
Build-Depends: debhelper (>= 7), dkms
Build-Depends: debhelper (>= 9), dkms
Standards-Version: 3.8.1

Package: DEBIAN_PACKAGE-dkms
Architecture: DEBIAN_BUILD_ARCH
Provides: DEBIAN_PACKAGE-modules (= MODULE_VERSION)
Depends: dkms (>= 1.95), ${misc:Depends}
Replaces: emuccan-b202-5.4.0-96-generic
Breaks: emuccan-b202-5.4.0-96-generic
Conflicts: emuccan-b202-5.4.0-96-generic
Description: DEBIAN_PACKAGE driver in DKMS format.
1 change: 0 additions & 1 deletion driver/emuccan-dkms-mkdeb/debian/dirs

This file was deleted.

9 changes: 9 additions & 0 deletions driver/post_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ echo "${MODULE_NAME}" | sudo tee /etc/modules-load.d/${MODULE_NAME}.conf

depmod -a

# Reload udev rules (from postinst)
udevadm control --reload-rules && udevadm trigger

# Reload systemd manager configuration as those has been changed
systemctl daemon-reload

# enable emuccan.service
systemctl enable emuccan

modprobe ${MODULE_NAME} || true
3 changes: 1 addition & 2 deletions postinst
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ case "$1" in
# reload udev rules, may have to reboot, sadly:
udevadm control --reload-rules && udevadm trigger

# enable emuccan.service
systemctl enable emuccan

;;

abort-upgrade|abort-remove|abort-deconfigure)
Expand Down