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
4747if [ -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
5051fi
5152
52- # Assign the first argument to OUT_DIR
53+ # Arguments
5354OUT_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"
5677DEB_PACKAGE=" $DEB_DIR .deb"
78+
5779IMAGE=" $OUT_DIR /Image"
5880CONFIG=" $OUT_DIR /.config"
59- MODULES=" $OUT_DIR /modules/lib/modules/$KERNEL_VERSION "
81+ MODULES=" $OUT_DIR /modules/lib/modules/$BASE_KERNEL_VERSION "
6082DTB=" $OUT_DIR /*.dtb"
6183
6284# Print required kernel products
@@ -65,7 +87,7 @@ echo "Required kernel products in kernel/out/ dir:"
6587echo " - Image"
6688echo " - .config"
6789echo " - Device Tree Blob (DTB) files"
68- echo " - modules/lib/modules/$KERNEL_VERSION "
90+ echo " - modules/lib/modules/$BASE_KERNEL_VERSION "
6991echo " ============================================================"
7092
7193echo " Checking for the existence of each kernel product..."
92114
93115echo " 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
100122echo " 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
105127echo " Integrating kernel products into the Debian package..."
106128# Copy files to the package directory
107129echo " 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
110132echo " 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
113135echo " Copying kernel modules to /lib/modules..."
114- cp -rap $MODULES $DEB_DIR /lib/modules/
136+ cp -rap " $MODULES " " $DEB_DIR /lib/modules/"
115137
116138echo " 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
119141echo " 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
123145Source: x1e80100
124- Version: $KERNEL_VERSION
146+ Version: $PKG_KERNEL_VERSION
125147Architecture: arm64
126148Maintainer: Bjordis Collaku <[email protected] > 127149Section: kernel
128150Priority: 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 )
130152EOF
131153
132154echo " Creating preinst script..."
@@ -135,7 +157,7 @@ cat <<EOF > $DEB_DIR/DEBIAN/preinst
135157#!/bin/sh
136158set -e
137159
138- kernel_version=$KERNEL_VERSION
160+ kernel_version=$BASE_KERNEL_VERSION
139161current_kernel_version=\$ (uname -r)
140162
141163echo "Starting cleanup of existing kernel products matching version \$ kernel_version..."
@@ -191,7 +213,7 @@ cat <<EOF > $DEB_DIR/DEBIAN/postinst
191213#!/bin/sh
192214set -e
193215
194- kernel_version=$KERNEL_VERSION
216+ kernel_version=$BASE_KERNEL_VERSION
195217
196218echo "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
228250set -e
229251
230- kernel_version=$KERNEL_VERSION
252+ kernel_version=$BASE_KERNEL_VERSION
231253
232254echo "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
253275if [ -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."
255277else
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 ."
257279fi
258280
259281# Clean up
0 commit comments