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