forked from aabc/ipt-netflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-dkms.sh
executable file
·108 lines (90 loc) · 2.69 KB
/
install-dkms.sh
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
#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-only
#
# This script cleanly re-install module into DKMS tree.
PATH=$PATH:/bin:/usr/bin:/usr/sbin:/sbin:/usr/local/sbin
if [ "$1" = --uninstall ]; then
echo "Uninstalling from DKMS..."
elif [ "$1" = --install ]; then
echo "Installing into DKMS..."
else
exit 1
fi
if ! which dkms >/dev/null 2>&1; then
echo "! You don't have DKMS accessible in system."
exit 1
fi
if [ ! -e dkms.conf ]; then
echo "! You don't have DKMS configured for this module."
exit 1
fi
MVERSION=`./version.sh`
contains() { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
D=() # to be list of installed versions
OLDIFS="$IFS"
IFS=$'\n' A=(`dkms status | grep ^ipt-netflow`)
IFS="$OLDIFS"
for i in "${A[@]}"; do
z=($i)
v=${z[1]}
v=${v%,}
v=${v%:}
if ! contains "$v" "${D[@]}"; then
D+=($v)
fi
done
if [ ${#D[@]} -eq 1 ]; then
# single version is already installed.
if [ $D = "$MVERSION" ]; then
echo "! You have same version of module already installed into DKMS."
else
echo "! You have different version of module installed into DKMS."
fi
if [ ! -d /usr/src/ipt-netflow-$D ]; then
echo "! Can not find DKMS dir for it, that's plain weird."
elif [ -e /usr/src/ipt-netflow-$D/.automatic ]; then
echo "! That version was automatically installed by this script,"
echo "! thus, is safe to remove. No worries."
else
echo "! That version was manually installed by you."
fi
nodepmod=
if grep -qs no-depmod `which dkms`; then
nodepmod=--no-depmod
fi
echo "! Removing from dkms..."
dkms $nodepmod remove ipt-netflow/$D --all
if [ -d "/usr/src/ipt-netflow-$D" ]; then
echo "! Removing source tree from /usr/src/ipt-netflow-$D"
rm -rf "/usr/src/ipt-netflow-$D"
fi
elif [ ${#D[@]} -gt 1 ]; then
# multiple versions are installed.
echo "! You have multiple versions of module already installed in DKMS."
echo "! Please remove them manually to avoid conflict."
echo "! 'dkms status' output:"
dkms status
echo "! Suggested commands to remove them:"
for i in ${D[@]}; do
echo "! root# dkms remove ipt-netflow/$i --all"
done
exit 1
fi
if [ "$1" = --uninstall ]; then
exit 0
fi
if [ "$PWD" = "/usr/src/ipt-netflow-$MVERSION" ]; then
echo "! You are already in DKMS dir."
dkms add -m ipt-netflow -v $MVERSION
exit $?
fi
echo "! Installing $MVERSION into DKMS..."
rm -rf /usr/src/ipt-netflow-$MVERSION
mkdir -p /usr/src/ipt-netflow-$MVERSION
cp -p *.[ch] Make* READ* conf* gen* irq* *.sh *.conf /usr/src/ipt-netflow-$MVERSION/
if [ -d .git ]; then
cp -pr .git /usr/src/ipt-netflow-$MVERSION/
fi
touch /usr/src/ipt-netflow-$MVERSION/.automatic
dkms add -m ipt-netflow -v $MVERSION
exit $?