-
Notifications
You must be signed in to change notification settings - Fork 9
/
kernelpatch_ubuntu
executable file
·204 lines (173 loc) · 5.37 KB
/
kernelpatch_ubuntu
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#!/bin/bash
# Define where to build and from what dir to build
BUILD_DIR="/lib/modules/`uname -r`/build"
TEMPDIR="tmp"
die(){
echo $1
exit 1
}
confirmyes(){
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [Y/n]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
[nN][oO]|[nN])
false
;;
*)
true
;;
esac
}
confirmno(){
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
success(){
depmod -a
echo -en "
####################################################################
\E[1;33;44mYour kernel is properly patched. You should reboot your machine now.\E[0m
####################################################################
"
cd ../.. && rm -rf $TEMPDIR
}
fail(){
echo -en "
##########################################################
\E[1;33;44mError(s) encountered. Your kernel is NOT properly patched.\E[0m
##########################################################
"
cd ../.. && rm -rf $TEMPDIR
exit 1
}
# Get OS and release info
if [ -f /usr/bin/lsb_release ]; then
OS=$( lsb_release -si )
RELEASE=$( lsb_release -sc )
fi
if [ "$OS" = "Ubuntu" ]; then
# Make sure that we are running as root
if ! echo "$(whoami)" | grep "root" > /dev/null 2>&1; then
echo -en "
\E[1;33;44m
You should run as root.
Do \"sudo su\" and run me again.
Aborting...
\E[0m
"
make clean > /dev/null 2>&1
exit 0
fi
# Get kernel version numbers
SHORT_KERNEL="$( echo `uname -r` | grep -o '[[:digit:]]\+\.[[:digit:]]\+' )"
FIRST_DIGIT="$( echo `uname -r` | grep -o '[[:digit:]]\+' | head -n1 )"
SECOND_DIGIT="$( echo `uname -r` | grep -o '[[:digit:]]\+' | head -n2 | awk 'NR==2' )"
PATCHLEVEL="$( echo `uname -r` | grep -o '[[:digit:]]\+' | head -n3 | awk 'NR==3' )"
UBUNTU_KERNEL="$SHORT_KERNEL.0"
# Abort if running kernel is < 3.x
if [ "$FIRST_DIGIT" -lt 3 ]; then
echo -en "
\E[1;33;44m
The kernel you are running is not supported anymore.
Minimum supported version is 3.x
Aborting...
\E[0m
"
exit 1
fi
if test "x$GCC" = "x"; then
GCC=gcc
fi
# When using FFdecsawrapper, the kernel has to be patched.
# Let's do it.
echo -en "
FFdecsawrapper needs a patched dvb-core.ko kernel module.
If you are running a \E[1;33;44m!UNMODIFIED!\E[0m Debian/Ubuntu kernel
I can do that for you if your sources.list is ok and the source
for your kernel is available from the repo's.
This will (re)install the source for your running kernel
along with any missing build deps.
Having done that, your running Debian/Ubuntu kernel
will be patched for use with ffdecsawrapper.
\E[1;33;44mIf you recompiled a stock kernel, you should\E[0m
\E[1;33;44mhave patched it. So answer 'No' in that case\E[0m
"
confirmyes "Do you want me to patch your running Debian/Ubuntu kernel?[Y/n]"
# Install dependencies for patching the kernel
if [ "$?" -eq 0 ]; then
apt-get build-dep linux --no-install-recommends -y || die "Error installing \"build-dep linux\""
rm -rf $TEMPDIR && mkdir $TEMPDIR && cd $TEMPDIR && apt-get source linux -y || die "Error(s) while fetching Debian Linux source"
cd linux-*
CWD=$(pwd)
if [ "$FIRST_DIGIT" -eq 3 ]; then
if [ "$SECOND_DIGIT" -lt 7 ]; then
patch -p0 < ../../linux-3.0-dvb-mutex.patch
if ! [ "$?" -eq 0 ]; then
fail
fi
CC="$GCC" make -C $BUILD_DIR M=$CWD/drivers/media/dvb/dvb-core modules
mkdir -p /lib/modules/`uname -r`/updates/ffdecsawrapper > /dev/null 2>&1
/usr/bin/install $CWD/drivers/media/dvb/dvb-core/dvb-core.ko /lib/modules/`uname -r`/updates/ffdecsawrapper
if [ "$?" -eq 0 ]; then
success
else
fail
fi
elif [ "$SECOND_DIGIT" -lt 13 ]; then
patch -p0 < ../../linux-3.7-dvb-mutex.patch
if ! [ "$?" -eq 0 ]; then
fail
fi
CC="$GCC" make -C $BUILD_DIR M=$CWD/drivers/media/dvb-core modules
mkdir -p /lib/modules/`uname -r`/updates/ffdecsawrapper > /dev/null 2>&1
/usr/bin/install $CWD/drivers/media/dvb-core/dvb-core.ko /lib/modules/`uname -r`/updates/ffdecsawrapper
if [ "$?" -eq 0 ]; then
success
else
fail
fi
else
patch -p0 < ../../linux-3.13-dvb-mutex.patch
if ! [ "$?" -eq 0 ]; then
fail
fi
CC="$GCC" make -C $BUILD_DIR M=$CWD/drivers/media/dvb-core modules
mkdir -p /lib/modules/`uname -r`/updates/ffdecsawrapper > /dev/null 2>&1
/usr/bin/install $CWD/drivers/media/dvb-core/dvb-core.ko /lib/modules/`uname -r`/updates/ffdecsawrapper
if [ "$?" -eq 0 ]; then
success
else
fail
fi
fi
else
patch -p0 < ../../linux-3.13-dvb-mutex.patch
if ! [ "$?" -eq 0 ]; then
fail
fi
CC="$GCC" make -C $BUILD_DIR M=$CWD/drivers/media/dvb-core modules
mkdir -p /lib/modules/`uname -r`/updates/ffdecsawrapper > /dev/null 2>&1
/usr/bin/install $CWD/drivers/media/dvb-core/dvb-core.ko /lib/modules/`uname -r`/updates/ffdecsawrapper
if [ "$?" -eq 0 ]; then
success
else
fail
fi
fi
else
echo "
Not patching any kernel.
"
fi
fi