-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-batman_adv
executable file
·129 lines (116 loc) · 3.56 KB
/
build-batman_adv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
PACKAGE="batman-adv"
REMOTE="git://git.open-mesh.org/batman-adv.git"
TAG="v2024.3"
KMOD_VERSION="2024.3"
PKG_RELEASE_PREFIX="0~tecff"
PKG_RELEASE="1"
BUILD_ROOT="/tmp/batman-adv-build"
MAINTAINER="rotanid"
PKGLICENSE="GPL2"
PKGGROUP="net"
PKGALTSRC="https://git.open-mesh.org/batman-adv.git"
PKGDESC="B.A.T.M.A.N. advanced external module"
RUNNING_DISTRO="$(lsb_release -s -i)"
RUNNING_DISTRO_VERSION="$(lsb_release -r -s)"
RUNNING_KERNEL_REL=$(uname -r)
if [[ "$RUNNING_DISTRO" = "Debian" ]]; then
if [[ "$RUNNING_KERNEL_REL" = "5.10.0-0.bpo"* ]]; then
# buster-backports
REQUIRED_KERNEL=$(dpkg -l | grep "linux-image.*bpo" | grep -v meta | tail -1 | awk '{ print $2 }')
PKG_RELEASE="${PKG_RELEASE}.bpo.1"
elif [[ "$RUNNING_KERNEL_REL" = "6.1.0"* ]]; then
# bookworm
REQUIRED_KERNEL=$(dpkg -s linux-image-amd64 | grep "^Depends" | cut -d" " -f2)
elif [[ "$RUNNING_KERNEL_REL" = "5.10.0"* ]]; then
# bullseye
REQUIRED_KERNEL=$(dpkg -s linux-image-amd64 | grep "^Depends" | cut -d" " -f2)
elif [[ "$RUNNING_KERNEL_REL" = "4.19.0"* ]]; then
# buster
REQUIRED_KERNEL=$(dpkg -s linux-image-amd64 | grep "^Depends" | sed 's/Depends:\s*//')
else
echo "the currently running kernel version ( $RUNNING_KERNEL_REL ) is not supported yet by this build script."
exit 1
fi
TARGET_KERNEL=$(echo $REQUIRED_KERNEL | sed "s/linux-image-//")
else
echo "the running distro is not supported."
exit 1
fi
REQUIRES="${REQUIRED_KERNEL}"
if [[ "$RUNNING_DISTRO_VERSION" = "10"* ]]; then
# Debian Buster
PKG_RELEASE="${PKG_RELEASE_PREFIX}~deb10u${PKG_RELEASE}"
elif [[ "$RUNNING_DISTRO_VERSION" = "11"* ]]; then
# Debian Bullseye
PKG_RELEASE="${PKG_RELEASE_PREFIX}~deb11u${PKG_RELEASE}"
elif [[ "$RUNNING_DISTRO_VERSION" = "12"* ]]; then
# Debian Bookworm
PKG_RELEASE="${PKG_RELEASE_PREFIX}~deb12u${PKG_RELEASE}"
else
echo "the currently running $RUNNING_DISTRO version ( $RUNNING_DISTRO_VERSION ) is not supported yet by this build script."
exit 1
fi
check() {
REQUIRED=0
# check kernel version in vermagic
local KMOD_VERMAGIC=$(/sbin/modinfo -k $TARGET_KERNEL batman-adv --field vermagic | awk '{ print $1 }')
if [[ $KMOD_VERMAGIC != $TARGET_KERNEL ]]; then
echo "[-] Kernel version changed (${KMOD_VERMAGIC} to ${TARGET_KERNEL})."
REQUIRED=1
fi
# check kmod version
local KMOD_CURRENT=$(/sbin/modinfo -k $TARGET_KERNEL batman-adv --field version)
/usr/bin/dpkg --compare-versions "$KMOD_CURRENT" "eq" "$KMOD_VERSION"
local CODE=$?
if [ $CODE -ne 0 ]; then
echo "[-] batman-adv version changed (${KMOD_CURRENT} to ${KMOD_VERSION})."
REQUIRED=1
fi
exit $REQUIRED
}
prepare() {
rm -rf $BUILD_ROOT
git clone "$REMOTE" "$BUILD_ROOT"
cd $BUILD_ROOT
git checkout "$TAG"
# apply patches if they exist
if [ -d "/usr/src/${PACKAGE}_patches" ] && [ "$(ls -A /usr/src/${PACKAGE}_patches/)" ]; then
git am /usr/src/${PACKAGE}_patches/*
fi
}
build() {
cd $BUILD_ROOT
export KERNELPATH=/lib/modules/$TARGET_KERNEL/build
# strip debug info
export INSTALL_MOD_STRIP=1
# build (including deprecated DEBUGFS & SYSFS interfaces)
make -j$(nproc)
}
install() {
cd $BUILD_ROOT
echo ${PKGDESC} > description-pak
checkinstall -y --nodoc \
--pkgname "${PACKAGE}" \
--pkgversion "${KMOD_VERSION}" \
--pkgrelease "${PKG_RELEASE}" \
--pkgsource "${REMOTE}" \
--pkgaltsource "${PKGALTSRC}" \
--pkglicense "${PKGLICENSE}" \
--pkggroup "${PKGGROUP}" \
--maintainer "${MAINTAINER}" \
--requires "${REQUIRES}" \
--fstrans=no
depmod -a
}
if [ "$1" = "check" ]; then
check
else
prepare
build
if [ "$?" != "0" ]; then
echo "build may have failed."
exit 1
fi
install
fi