fix: dkms build adjusted to the new(old) build system

This commit is contained in:
Yaroslav Gurov
2025-10-03 16:09:37 +02:00
committed by Yaroslav Gurov
parent 591f50af05
commit b0db37dd17
4 changed files with 4 additions and 118 deletions

View File

@@ -1,8 +0,0 @@
#!/bin/bash
AWG_TEMP_DIR="$(cat /var/lib/amnezia/amneziawg/.tempdir 2>/dev/null)"
PREFIX=${AWG_TEMP_DIR:-/tmp}
WORKDIR="${PREFIX}/amneziawg"
[ -e kernel ] && rm -f kernel
[ -d "${WORKDIR}" ] && rm -rf "${WORKDIR}"

View File

@@ -1,99 +0,0 @@
#!/bin/bash
KERNEL_VERSION=$1
is_modern_kernel() {
local modern=$(echo $KERNEL_VERSION | awk 'BEGIN{ FS="."};
{ if ($1 < 5) { print "N"; }
else if ($1 == 5) {
if ($2 <= 5) { print "N"; }
else { print "Y"; }
}
else { print "Y"; }
}')
if [ "$modern" = "N" ]; then
return 1
fi
}
cd_first () {
local prefix=$1
local first=$(find ./${prefix}* -maxdepth 0 -type d 2>/dev/null | sort | head -n 1)
[ "${first}" != "" ] && cd "${first}" || exit 255
}
if ! is_modern_kernel; then
echo "Legacy kernel - using the compat sources"
exit 0
fi
if [ -e kernel/drivers/net/wireguard/main.c ] && [ -e kernel/include/uapi/linux/wireguard.h ]; then
echo "Kernel sources are already prepared, skipping"
exit 0
fi
if ! which apt-get > /dev/null 2>&1 && \
! which dnf > /dev/null 2>&1 && \
! which yum > /dev/null 2>&1; then
echo "You need to download sources on your own and make a symbolic link to /usr/src/amneziawg-1.0.0/kernel:"
echo ""
echo " ln -s /path/to/kernel/source /usr/src/amneziawg-1.0.0/kernel"
echo ""
echo "Otherwise it is not possible to obtain kernel sources on your system automatically"
exit 1
fi
DISTRO_FLAVOR=$(cat /etc/*-release 2>/dev/null | grep -E ^ID_LIKE= | sed 's/ID_LIKE=//' | sed 's/"//g')
DISTRO_FLAVOR=${DISTRO_FLAVOR:-$(cat /etc/*-release 2>/dev/null | grep -E ^ID= | sed 's/ID=//' | sed 's/"//g')}
if [ "${AWG_TEMP_DIR}" != "" ]; then
mkdir -p /var/lib/amnezia/amneziawg
echo "${AWG_TEMP_DIR}" > /var/lib/amnezia/amneziawg/.tempdir
elif [ -f /var/lib/amnezia/amneziawg/.tempdir ]; then
AWG_TEMP_DIR="$(cat /var/lib/amnezia/amneziawg/.tempdir)"
fi
PREFIX=${AWG_TEMP_DIR:-/tmp}
WORKDIR="${PREFIX}/amneziawg"
[ -d "${WORKDIR}" ] && rm -rf "${WORKDIR}"
mkdir -p "${WORKDIR}"
pushd "${WORKDIR}" > /dev/null 2>&1 || exit 1
echo "Downloading source for Linux kernel version ${KERNEL_VERSION}"
if [[ "${DISTRO_FLAVOR}" =~ debian ]]; then
export DEBIAN_FRONTEND=noninteractive
VERSION_MAIN="${KERNEL_VERSION%+*}"
VERSION_SUFFIX="${KERNEL_VERSION#*+}"
ac=$(apt-cache search --names-only linux-image "${VERSION_MAIN}" "${VERSION_SUFFIX}" unsigned 2>/dev/null|head -n 1)
[ "${ac}" == "" ] && ac=$(apt-cache search --names-only linux-image "${VERSION_MAIN}" "${VERSION_SUFFIX}" 2>/dev/null|head -n 1)
if [ "${ac}" == "" ]; then
echo "Could not find suitable image for your Linux distribution!"
exit 255
fi
PACKAGE_NAME="${ac% - *}"
PACKAGE_VERSION=$(apt-cache madison "${PACKAGE_NAME}"|grep Sources|head -n 1|awk '{ print $3; }')
echo "Downloading as $(whoami)"
apt-get -yq -o APT::Sandbox::User="$(whoami)" source "${PACKAGE_NAME}=${PACKAGE_VERSION}"
cd_first
else
yumdownloader --source kernel
[ -f "${HOME}/.rpmmacros" ] && mv "${HOME}/.rpmmacros" "${HOME}/.rpmmacros.orig"
echo "%_topdir $(pwd)" > "${HOME}/.rpmmacros"
rpm -ivh "$(ls *.rpm)"
cd SPECS || exit 255
rpmbuild -bp --target="$(uname -m)" --nodeps kernel.spec
rm -rf "${HOME}/.rpmmacros"
[ -f "${HOME}/.rpmmacros.orig" ] && mv "${HOME}/.rpmmacros.orig" "${HOME}/.rpmmacros"
cd ../BUILD || exit 255
cd_first
cd_first linux
fi
KERNEL_PATH="$(pwd)"
popd > /dev/null 2>&1 || exit 1
[ -e kernel ] && rm -f kernel
ln -s "${KERNEL_PATH}" kernel

View File

@@ -38,12 +38,10 @@ module-install:
install: module-install
DKMS_SOURCES := Makefile Kbuild Kconfig dkms.conf $(call rwildcard,,*.c *.h *.S *.pl *.include *.patch,amneziawg.mod.c kernel/% tests/%)
rwildcard=$(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2) $(filter $(subst *,%,$2),$d))
DKMS_SOURCES := version.h Makefile Kbuild Kconfig dkms.conf $(filter-out version.h wireguard.mod.c tests/%,$(call rwildcard,,*.c *.h *.S *.pl *.include))
dkms-install: $(DKMS_SOURCES)
@$(foreach f,$(DKMS_SOURCES),install -v -m0644 -D $(f) $(DESTDIR)$(DKMSDIR)/$(f);)
@install -v -m 0755 ../kernel-tree-scripts/prepare-sources.sh "$(DESTDIR)$(DKMSDIR)/prepare-sources.sh"
@install -v -m 0755 ../kernel-tree-scripts/cleanup-sources.sh "$(DESTDIR)$(DKMSDIR)/cleanup-sources.sh"
[ "$(realpath $(WG_SOURCE_DIR))" != "" ] && ln -s "$(KERNEL_SOURCE_DIR)" "$(DESTDIR)$(DKMSDIR)/kernel" || true
style:
$(KERNELDIR)/scripts/checkpatch.pl -f --max-line-length=4000 --codespell --color=always $(filter-out wireguard.mod.c,$(wildcard *.c)) $(wildcard *.h) $(wildcard selftest/*.c)

View File

@@ -1,12 +1,7 @@
PACKAGE_NAME="amneziawg"
PACKAGE_VERSION="1.0.0"
PACKAGE_VERSION="2.0.0"
AUTOINSTALL=yes
REMAKE_INITRD=yes
PRE_BUILD="prepare-sources.sh $kernelver"
POST_BUILD="cleanup-sources.sh"
MAKE[0]="make -C /var/lib/dkms/amneziawg/${PACKAGE_VERSION}/build"
BUILT_MODULE_NAME="amneziawg"
DEST_MODULE_LOCATION="/kernel/net"
DEST_MODULE_LOCATION="/kernel/net"