-
Notifications
You must be signed in to change notification settings - Fork 34
/
kernel-patch
executable file
·63 lines (51 loc) · 2.02 KB
/
kernel-patch
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
#!/bin/bash
dir_linux=/usr/src/linux
dir_distfiles=/usr/src/distfiles
usage() {
echo >&2 "Usage: $0 [ver_to]"
echo >&2
echo >&2 'If version is not specified, latest patchset for same'
echo >&2 ' major version is scraped from kernel.org and downloaded.'
exit 1
}
[[ "$#" -gt 1 || "$1" = -h || "$1" = --help ]] && usage
v1=$1
[[ -r /usr/src/distfiles ]] || { echo >&2 "ERROR: no access to $dir_distfiles"; exit 1; }
cd "$dir_linux" && [[ -e Makefile ]]\
|| { echo >&2 "ERROR: Failed to find Makefile in $dir_linux"; exit 1; }
v0=$( awk '$1=="VERSION" {v1=$3}
$1=="PATCHLEVEL" {v2=$3}
$1=="SUBLEVEL" {v3=$3; v3_set=1}
v1 && v2 && v3_set {print v1 "." v2 "." v3; exit}' Makefile )
[[ -n "$v0" ]] || { echo >&2 "ERROR: Failed to get current sources version"; exit 1; }
[[ -n "$v1" ]] || {
releases=( )
for v1 in $(
curl -SsL 'https://www.kernel.org' |
grep -oP '(?<=<strong>)[0-9.]+(?=</strong>)' ) fail
do [[ ${v1%.*} != ${v0%.*} ]] || break
done
[[ "$v1" != fail ]] || {
echo >&2 "ERROR: Failed to scrape matching release from kernel.org"; exit 1; }
}
[[ "$v0" != "$v1" ]] || exit 0
patch0="$dir_distfiles"/patch-$v0.zst
[[ -e "$patch0" ]] || patch0="${patch0%.zst}".xz
patch1="$dir_distfiles"/patch-$v1.zst
[[ -e "$patch1" ]] || patch1="${patch1%.zst}".xz
[[ -e "$patch1" ]] \
|| curl -SsL -o "$patch1" \
"https://cdn.kernel.org/pub/linux/kernel/v${v1%%.*}.x/patch-$v1.xz" \
|| { echo >&2 "ERROR: Failed to download patch: $v1"; exit 1; }
[[ "${v0##*.}" == 0 ]] || {
bsdcat "$patch0" | patch --batch --follow-symlinks -p1 -R --dry-run
[[ ${PIPESTATUS[0]} -ne 0 || ${PIPESTATUS[1]} -ne 0 ]] && exit 1
bsdcat "$patch0" | patch --batch --follow-symlinks -p1 -R
[[ ${PIPESTATUS[0]} -ne 0 || ${PIPESTATUS[1]} -ne 0 ]] && exit 1
}
bsdcat "$patch1" | patch --batch --follow-symlinks -p1 -N --dry-run
[[ ${PIPESTATUS[0]} -ne 0 || ${PIPESTATUS[1]} -ne 0 ]] && exit 1
bsdcat "$patch1" | patch --batch --follow-symlinks -p1 -N
[[ ${PIPESTATUS[0]} -ne 0 || ${PIPESTATUS[1]} -ne 0 ]] && exit 1
[[ -e .config ]] && make oldconfig
exit 0