Skip to content

Commit a60c4d9

Browse files
build-kernel-deb.sh: add optional build_id argument for package versioning
Add support for an optional second argument `build_id` to the build-kernel-deb.sh script. When provided, the build_id is appended to the detected kernel version and used in the Debian package name and control metadata. This enables tagging kernel builds with unique identifiers for traceability without altering installed paths or module versioning. Example usage: ./build-kernel-deb.sh /path/to/out 19085636185-1 → produces linux-kernel-<version>-19085636185-1-arm64.deb Default behavior remains unchanged when build_id is omitted. Signed-off-by: Bjordis Collaku <[email protected]>
1 parent e966f5e commit a60c4d9

File tree

1 file changed

+48
-26
lines changed

1 file changed

+48
-26
lines changed

kernel/scripts/build-kernel-deb.sh

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
# - Verifies that the .deb was created successfully
2525
#
2626
# Usage:
27-
# ./build-kernel-deb.sh <path_to_kernel_out_dir>
27+
# ./build-kernel-deb.sh <path_to_kernel_out_dir> [build_id]
2828
#
2929
# Example:
30-
# ./build-kernel-deb.sh /path/to/kernel/out/
30+
# ./build-kernel-deb.sh /path/to/kernel/out/ 19085636185-1
3131
#
3232
# Author: Bjordis Collaku <[email protected]>
3333
# ===================================================
@@ -46,17 +46,39 @@ echo "Ensuring necessary dependencies are installed..."
4646
# Ensure the first argument is passed
4747
if [ -z "$1" ]; then
4848
echo "Please enter path to kernel products"
49+
echo "Usage: $0 <path_to_kernel_out_dir> [build_id]"
4950
exit 1
5051
fi
5152

52-
# Assign the first argument to OUT_DIR
53+
# Arguments
5354
OUT_DIR="$1"
54-
KERNEL_VERSION=$(basename $OUT_DIR/modules/lib/modules/*)
55-
DEB_DIR="linux-kernel-$KERNEL_VERSION-arm64"
55+
BUILD_ID="${2:-}"
56+
57+
# Detect base kernel version from modules directory
58+
BASE_KERNEL_VERSION=$(basename "$OUT_DIR"/modules/lib/modules/* 2>/dev/null)
59+
60+
if [ -z "$BASE_KERNEL_VERSION" ] || [ ! -d "$OUT_DIR/modules/lib/modules/$BASE_KERNEL_VERSION" ]; then
61+
echo "Unable to detect kernel version under: $OUT_DIR/modules/lib/modules/"
62+
exit 1
63+
fi
64+
65+
# Package kernel version: append -BUILD_ID if provided (safe: package-only)
66+
PKG_KERNEL_VERSION="$BASE_KERNEL_VERSION"
67+
if [ -n "$BUILD_ID" ]; then
68+
PKG_KERNEL_VERSION="${BASE_KERNEL_VERSION}-${BUILD_ID}"
69+
fi
70+
71+
# If you actually built the kernel with the suffix and want files/paths to match,
72+
# uncomment the next line to switch all installed paths to the suffixed version.
73+
# NOTE: Do this ONLY if uname -r for this kernel will also include the suffix.
74+
#BASE_KERNEL_VERSION="$PKG_KERNEL_VERSION"
75+
76+
DEB_DIR="linux-kernel-$PKG_KERNEL_VERSION-arm64"
5677
DEB_PACKAGE="$DEB_DIR.deb"
78+
5779
IMAGE="$OUT_DIR/Image"
5880
CONFIG="$OUT_DIR/.config"
59-
MODULES="$OUT_DIR/modules/lib/modules/$KERNEL_VERSION"
81+
MODULES="$OUT_DIR/modules/lib/modules/$BASE_KERNEL_VERSION"
6082
DTB="$OUT_DIR/*.dtb"
6183

6284
# Print required kernel products
@@ -65,7 +87,7 @@ echo "Required kernel products in kernel/out/ dir:"
6587
echo " - Image"
6688
echo " - .config"
6789
echo " - Device Tree Blob (DTB) files"
68-
echo " - modules/lib/modules/$KERNEL_VERSION"
90+
echo " - modules/lib/modules/$BASE_KERNEL_VERSION"
6991
echo "============================================================"
7092

7193
echo "Checking for the existence of each kernel product..."
@@ -92,41 +114,41 @@ fi
92114

93115
echo "Creating directory structure for Debian package..."
94116
# Create directory structure for Debian package
95-
mkdir -p $DEB_DIR/DEBIAN
96-
mkdir -p $DEB_DIR/boot
97-
mkdir -p $DEB_DIR/lib/firmware/$KERNEL_VERSION/device-tree
98-
mkdir -p $DEB_DIR/lib/modules/$KERNEL_VERSION
117+
mkdir -p "$DEB_DIR/DEBIAN"
118+
mkdir -p "$DEB_DIR/boot"
119+
mkdir -p "$DEB_DIR/lib/firmware/$BASE_KERNEL_VERSION/device-tree"
120+
mkdir -p "$DEB_DIR/lib/modules/$BASE_KERNEL_VERSION"
99121

100122
echo "Setting correct permissions for DEBIAN directory..."
101123
# Set correct permissions for DEBIAN directory
102-
chmod 0755 $DEB_DIR/DEBIAN
103-
chmod -R g-s $DEB_DIR/DEBIAN
124+
chmod 0755 "$DEB_DIR/DEBIAN"
125+
chmod -R g-s "$DEB_DIR/DEBIAN"
104126

105127
echo "Integrating kernel products into the Debian package..."
106128
# Copy files to the package directory
107129
echo "Copying kernel image to /boot..."
108-
cp $IMAGE $DEB_DIR/boot/vmlinuz-$KERNEL_VERSION
130+
cp "$IMAGE" "$DEB_DIR/boot/vmlinuz-$BASE_KERNEL_VERSION"
109131

110132
echo "Copying kernel config to /boot..."
111-
cp $CONFIG $DEB_DIR/boot/config-$KERNEL_VERSION
133+
cp "$CONFIG" "$DEB_DIR/boot/config-$BASE_KERNEL_VERSION"
112134

113135
echo "Copying kernel modules to /lib/modules..."
114-
cp -rap $MODULES $DEB_DIR/lib/modules/
136+
cp -rap "$MODULES" "$DEB_DIR/lib/modules/"
115137

116138
echo "Copying device tree blobs to /boot/dtbs..."
117-
cp $OUT_DIR/*.dtb $DEB_DIR/lib/firmware/$KERNEL_VERSION/device-tree/
139+
cp "$OUT_DIR"/*.dtb "$DEB_DIR/lib/firmware/$BASE_KERNEL_VERSION/device-tree/"
118140

119141
echo "Creating control file..."
120142
# Create control file
121-
cat <<EOF > $DEB_DIR/DEBIAN/control
122-
Package: linux-kernel-$KERNEL_VERSION
143+
cat <<EOF > "$DEB_DIR/DEBIAN/control"
144+
Package: linux-kernel-$PKG_KERNEL_VERSION
123145
Source: x1e80100
124-
Version: $KERNEL_VERSION
146+
Version: $PKG_KERNEL_VERSION
125147
Architecture: arm64
126148
Maintainer: Bjordis Collaku <[email protected]>
127149
Section: kernel
128150
Priority: optional
129-
Description: Linux kernel Image, dtb and modules for $KERNEL_VERSION
151+
Description: Linux kernel Image, dtb and modules for $BASE_KERNEL_VERSION (package build $PKG_KERNEL_VERSION)
130152
EOF
131153

132154
echo "Creating preinst script..."
@@ -135,7 +157,7 @@ cat <<EOF > $DEB_DIR/DEBIAN/preinst
135157
#!/bin/sh
136158
set -e
137159
138-
kernel_version=$KERNEL_VERSION
160+
kernel_version=$BASE_KERNEL_VERSION
139161
current_kernel_version=\$(uname -r)
140162
141163
echo "Starting cleanup of existing kernel products matching version \$kernel_version..."
@@ -191,7 +213,7 @@ cat <<EOF > $DEB_DIR/DEBIAN/postinst
191213
#!/bin/sh
192214
set -e
193215
194-
kernel_version=$KERNEL_VERSION
216+
kernel_version=$BASE_KERNEL_VERSION
195217
196218
echo "Starting post-installation procedure for Linux kernel package version \$kernel_version..."
197219
@@ -227,7 +249,7 @@ cat <<EOF > $DEB_DIR/DEBIAN/postrm
227249
#!/bin/sh
228250
set -e
229251
230-
kernel_version=$KERNEL_VERSION
252+
kernel_version=$BASE_KERNEL_VERSION
231253
232254
echo "Starting post-removal procedure for Linux kernel package version \$kernel_version..."
233255
@@ -251,9 +273,9 @@ dpkg-deb --build $DEB_DIR
251273

252274
# Check if the .deb package was created successfully
253275
if [ -f "$DEB_PACKAGE" ]; then
254-
echo "Debian package for kernel version $KERNEL_VERSION created successfully."
276+
echo "Debian package for kernel version $BASE_KERNEL_VERSION created successfully."
255277
else
256-
echo "Failed to create Debian package for kernel version $KERNEL_VERSION."
278+
echo "Failed to create Debian package for kernel version $BASE_KERNEL_VERSION."
257279
fi
258280

259281
# Clean up

0 commit comments

Comments
 (0)