Commit | Line | Data |
---|---|---|
72e6c528 | 1 | #!/bin/sh |
b7cdc182 | 2 | # SPDX-License-Identifier: (GPL-2.0-only OR LGPL-2.1-only) |
61baff6e | 3 | # SPDX-FileCopyrightText: 2015-2024 EfficiOS Inc. |
72e6c528 MD |
4 | |
5 | # First argument is the path to the kernel headers. | |
8a71de6c | 6 | KPATH="$1" |
72e6c528 | 7 | |
8a71de6c | 8 | if [ ! -f "${KPATH}/include/generated/package.h" ]; then |
72e6c528 MD |
9 | echo 0 |
10 | exit 0 | |
11 | fi | |
12 | ||
13 | # Debian snippet courtesy of Ben Hutchings | |
14 | ||
15 | # Assuming KPATH is the target kernel headers directory | |
8a71de6c | 16 | DEB_PACKAGE_VERSION=$(sed -rn 's/^#define LINUX_PACKAGE_ID " Debian (.*)"/\1/p' "${KPATH}/include/generated/package.h") |
be5d6764 | 17 | |
72e6c528 | 18 | # Ignore backports part |
8a71de6c | 19 | DEB_PACKAGE_VERSION=$(echo "${DEB_PACKAGE_VERSION}" | sed -r 's/~(bpo|deb).*//') |
be5d6764 | 20 | |
72e6c528 | 21 | # Get package revision |
8a71de6c | 22 | DEB_PACKAGE_REVISION=$(echo "${DEB_PACKAGE_VERSION}" | sed -r 's/.*-([^-]+)$/\1/') |
72e6c528 | 23 | # Get non-sec update number |
8a71de6c | 24 | DEB_PACKAGE_REVISION_BASE=$(echo "${DEB_PACKAGE_REVISION}" | sed -r 's/^([0-9]+).*/\1/') |
72e6c528 | 25 | # Get security update number, if present |
8a71de6c | 26 | DEB_PACKAGE_REVISION_SECURITY=$(echo "${DEB_PACKAGE_REVISION}" | sed -rn 's/.*\+(squeeze|deb[0-9]+)+u([0-9]+)$/\2/p') |
72e6c528 MD |
27 | test -n "${DEB_PACKAGE_REVISION_SECURITY}" || DEB_PACKAGE_REVISION_SECURITY=0 |
28 | # Combine all update numbers into one | |
1c56bda8 | 29 | DEB_API_VERSION=$((DEB_PACKAGE_REVISION_BASE * 100 + DEB_PACKAGE_REVISION_SECURITY)) |
72e6c528 MD |
30 | |
31 | echo ${DEB_API_VERSION} |