Commit | Line | Data |
---|---|---|
72e6c528 | 1 | #!/bin/sh |
6c27a5cc | 2 | # SPDX-License-Identifier: (GPL-2.0 OR LGPL-2.1) |
72e6c528 MD |
3 | |
4 | # First argument is the path to the kernel headers. | |
8a71de6c | 5 | KPATH="$1" |
72e6c528 | 6 | |
8a71de6c | 7 | if [ ! -f "${KPATH}/include/generated/package.h" ]; then |
72e6c528 MD |
8 | echo 0 |
9 | exit 0 | |
10 | fi | |
11 | ||
12 | # Debian snippet courtesy of Ben Hutchings | |
13 | ||
14 | # Assuming KPATH is the target kernel headers directory | |
8a71de6c | 15 | DEB_PACKAGE_VERSION=$(sed -rn 's/^#define LINUX_PACKAGE_ID " Debian (.*)"/\1/p' "${KPATH}/include/generated/package.h") |
be5d6764 | 16 | |
72e6c528 | 17 | # Ignore backports part |
8a71de6c | 18 | DEB_PACKAGE_VERSION=$(echo "${DEB_PACKAGE_VERSION}" | sed -r 's/~(bpo|deb).*//') |
be5d6764 MJ |
19 | |
20 | # ckt (Canonical Kernel Team) kernels were used for a while during the jessie | |
21 | # cycle, their versionning is a bit different. They track the upstream vanilla | |
22 | # stable updates but they don't update the minor version number and instead add | |
23 | # an additionnal -cktX. They were all 3.16.7-cktX and after a while the version | |
24 | # switched back to upstream style at 3.16.36. | |
25 | ||
72e6c528 | 26 | # Get -ckt update number, if present |
8a71de6c | 27 | KERNEL_CKT_UPDATE=$(echo "${DEB_PACKAGE_VERSION}" | sed -rn 's/^[0-9]+\.[0-9]+\.[0-9]+-ckt([0-9]+).*/\1/p') |
be5d6764 | 28 | test -n "${KERNEL_CKT_UPDATE}" || KERNEL_CKT_UPDATE=0 |
2a3427bf | 29 | |
72e6c528 | 30 | # Get package revision |
8a71de6c | 31 | DEB_PACKAGE_REVISION=$(echo "${DEB_PACKAGE_VERSION}" | sed -r 's/.*-([^-]+)$/\1/') |
72e6c528 | 32 | # Get non-sec update number |
8a71de6c | 33 | DEB_PACKAGE_REVISION_BASE=$(echo "${DEB_PACKAGE_REVISION}" | sed -r 's/^([0-9]+).*/\1/') |
72e6c528 | 34 | # Get security update number, if present |
8a71de6c | 35 | DEB_PACKAGE_REVISION_SECURITY=$(echo "${DEB_PACKAGE_REVISION}" | sed -rn 's/.*\+(squeeze|deb[0-9]+)+u([0-9]+)$/\2/p') |
72e6c528 MD |
36 | test -n "${DEB_PACKAGE_REVISION_SECURITY}" || DEB_PACKAGE_REVISION_SECURITY=0 |
37 | # Combine all update numbers into one | |
38 | DEB_API_VERSION=$((KERNEL_CKT_UPDATE * 10000 + DEB_PACKAGE_REVISION_BASE * 100 + DEB_PACKAGE_REVISION_SECURITY)) | |
39 | ||
40 | echo ${DEB_API_VERSION} |