forked from rasa/vmware-tools-patches
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch-module.sh
executable file
·92 lines (69 loc) · 2.17 KB
/
patch-module.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
#!/usr/bin/env bash
# apply patches for a single module
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if ! hash patch >/dev/null 2>&1; then
if hash apt-get >/dev/null 2>&1; then
sudo apt-get install -y patch
else
echo $0: Command not found: patch >&2
exit 1
fi
fi
if [[ -z "$1" ]]; then
echo Usage: $0 patchdir >&2
exit 2
fi
patchdir="$1"
if [[ ! -d "${patchdir}" ]]; then
echo $0: Error: Directory not found: ${patchdir} >&2
exit 3
fi
patches="$(find ${patchdir} -type f -size +1c -regextype posix-extended -iregex '.*\.(patch|diff)' | sort)"
scripts="$(find ${patchdir} -type f -name '*.sh' | sort)"
module="$(basename ${patchdir})"
if [[ ! -d lib/modules/source ]]; then
echo $0: Error: Directory not found: lib/modules/source >&2
exit 5
fi
if [[ ! -f "lib/modules/source/${module}.tar" ]]; then
echo $0: Error: File not found: lib/modules/source/${module}.tar >&2
exit 6
fi
pushd lib/modules/source >/dev/null
if [[ ! -f "${module}.tar.orig" ]]; then
cp -p "${module}.tar" "${module}.tar.orig"
fi
rm -rf "${module}-only"
tar --no-same-owner --no-same-permissions -xf "${module}.tar"
if [[ ! -d "${module}-only" ]]; then
echo $0: Error: Directory not found: ${module}-only in lib/modules/source/${module}.tar >&2
exit 7
fi
chmod -R a+w "${module}-only"
pushd "${module}-only" >/dev/null
if [[ -n "${patches}" ]]; then
for patch in ${patches}; do
base="$(basename ${patch})"
dir="$(basename $(dirname ${patch}))"
patch --batch --ignore-whitespace --strip=1 --dry-run < "${patch}" >$base.patch.err 2>&1
if [ $? -eq 0 ]; then
rm $base.patch.err
echo "*** Applying ${dir}/${base} ..."
patch --batch --ignore-whitespace --strip=1 --backup < "${patch}"
else
echo "*** Skipping ${dir}/${base}: patch not appropriate for this kernel"
fi
done
fi
if [[ -n "${scripts}" ]]; then
for script in ${scripts}; do
base="$(basename ${script})"
dir="$(basename $(dirname ${script}))"
chmod +x "${script}"
echo "*** Running ${dir}/${base}"
"${script}"
done
fi
popd >/dev/null
tar -cf "${module}.tar" "${module}-only"
popd >/dev/null