-
Notifications
You must be signed in to change notification settings - Fork 1
/
apply-patches.sh
executable file
·154 lines (135 loc) · 4.33 KB
/
apply-patches.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
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
#!/bin/bash
set -e
source="$(readlink -f -- $1)"
core="$source/patches/trebledroid"
personal="$source/patches/personal"
pre="$source/patches/pre"
fod="$source/patches/fod"
if [ -e $pre ]; then
printf "\n ##### APPLYING PRE-REQUISITE PATCHES #####\n";
sleep 1.0;
for path_pre in $(cd $pre; echo *); do
tree="$(tr _ / <<<$path_pre | sed -e 's;platform/;;g')"
printf "\n| $path_pre #####\n";
[ "$tree" == build ] && tree=build/make
[ "$tree" == vendor/hardware/overlay ] && tree=vendor/hardware_overlay
[ "$tree" == treble/app ] && tree=treble_app
pushd $tree
for patch in $pre/$path_pre/*.patch; do
# Check if patch is already applied
if patch -f -p1 --dry-run -R < $patch > /dev/null; then
printf "##### ALREDY APPLIED: $patch \n";
continue
fi
if git apply --check $patch; then
git am $patch
elif patch -f -p1 --dry-run < $patch > /dev/null; then
#This will fail
git am $patch || true
patch -f -p1 < $patch
git add -u
git am --continue
else
printf "##### FAILED APPLYING: $patch \n"
fi
done
popd
done
fi
if [ -e $core ]; then
printf "\n ##### APPLYING TREBLEDROID PATCHES #####\n";
sleep 1.0;
for path in $(cd $core; echo *); do
tree="$(tr _ / <<<$path | sed -e 's;platform/;;g')"
printf "\n| $path #####\n";
[ "$tree" == build ] && tree=build/make
[ "$tree" == vendor/hardware/overlay ] && tree=vendor/hardware_overlay
[ "$tree" == treble/app ] && tree=treble_app
pushd $tree
for patch in $core/$path/*.patch; do
# Check if patch is already applied
if patch -f -p1 --dry-run -R < $patch > /dev/null; then
printf "##### ALREDY APPLIED: $patch \n";
continue
fi
if git apply --check $patch; then
git am $patch
elif patch -f -p1 --dry-run < $patch > /dev/null; then
#This will fail
git am $patch || true
patch -f -p1 < $patch
git add -u
git am --continue
else
printf "##### FAILED APPLYING: $patch \n"
fi
done
popd
done
fi
if [ -e $personal ]; then
printf "\n##### APPLYING PERSONAL PATCHES #####\n";
sleep 1.0;
for path_personal in $(cd $personal; echo *); do
tree="$(tr _ / <<<$path_personal | sed -e 's;platform/;;g')"
printf "\n| $path_personal #####\n";
[ "$tree" == build ] && tree=build/make
[ "$tree" == vendor/hardware/overlay ] && tree=vendor/hardware_overlay
[ "$tree" == treble/app ] && tree=treble_app
pushd $tree
for patch in $personal/$path_personal/*.patch; do
# Check if patch is already applied
if patch -f -p1 --dry-run -R < $patch > /dev/null; then
printf "##### ALREDY APPLIED: $patch \n";
continue
fi
if git apply --check $patch; then
git am $patch
elif patch -f -p1 --dry-run < $patch > /dev/null; then
#This will fail
git am $patch || true
patch -f -p1 < $patch
git add -u
git am --continue
else
printf "##### FAILED APPLYING: $patch \n"
fi
done
popd
done
else
printf "\n##### THERE'S NO PERSONAL PATCHES#####\n";
fi
if [ -e $fod ]; then
printf "\n##### APPLYING FOD PATCHES #####\n";
sleep 1.0;
for path_fod in $(cd $fod; echo *); do
tree="$(tr _ / <<<$path_fod | sed -e 's;platform/;;g')"
printf "\n| $path_fod #####\n";
[ "$tree" == build ] && tree=build/make
[ "$tree" == vendor/hardware/overlay ] && tree=vendor/hardware_overlay
[ "$tree" == treble/app ] && tree=treble_app
pushd $tree
for patch in $fod/$path_fod/*.patch; do
# Check if patch is already applied
if patch -f -p1 --dry-run -R < $patch > /dev/null; then
printf "##### ALREDY APPLIED: $patch \n";
continue
fi
if git apply --check $patch; then
git am $patch
elif patch -f -p1 --dry-run < $patch > /dev/null; then
#This will fail
git am $patch || true
patch -f -p1 < $patch
git add -u
git am --continue
else
printf "##### FAILED APPLYING: $patch \n"
fi
done
popd
done
else
printf "\n##### THERE'S NO FOD PATCHES#####\n";
fi