blob: 94f1510bd74b7361ed9bf70774a16fbfa3b7feae (
plain)
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
#!/sbin/sh
# AnyKernel3 Backend (DO NOT CHANGE)
# osm0sis @ xda-developers
OUTFD=/proc/self/fd/$2;
ZIPFILE="$3";
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false;
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true;
$BOOTMODE && DIR=/sdcard || DIR=$(dirname "$ZIPFILE");
test "$ANDROID_ROOT" || ANDROID_ROOT=/system;
test "$home" || home=/tmp/anykernel;
ui_print() {
until [ ! "$1" ]; do
echo -e "ui_print $1\nui_print" > $OUTFD;
shift;
done;
}
ui_printfile() {
while IFS='' read -r line || $bb [[ -n "$line" ]]; do
ui_print "$line";
done < $1;
}
show_progress() { echo "progress $1 $2" > $OUTFD; }
file_getprop() { $bb grep "^$2=" "$1" | $bb cut -d= -f2-; }
int2ver() {
if [ "$1" -eq "$1" ] 2>/dev/null; then
echo "$1.0.0";
elif [ ! "$(echo "$1" | $bb cut -d. -f3)" ]; then
echo "$1.0";
else
echo "$1";
fi;
}
cleanup() {
cd $(dirname $home);
rm -rf $home;
}
debugging() {
case $(basename "$ZIPFILE" .zip) in
*-debugging)
ui_print " " "Creating debugging archive in $DIR...";
test -f /tmp/recovery.log && log=/tmp/recovery.log;
$bb tar -czf "$DIR/anykernel3-$(date +%Y-%m-%d_%H%M%S)-debug.tgz" $home $log;
;;
esac;
}
setup_mountpoint() {
test -L $1 && $bb mv -f $1 ${1}_link;
if [ ! -d $1 ]; then
rm -f $1;
mkdir $1;
fi;
}
is_mounted() { $bb mount | $bb grep -q " $1 "; }
umount_all() {
($bb umount /system;
$bb umount -l /system;
if [ -e /system_root ]; then
$bb umount /system_root;
$bb umount -l /system_root;
fi;
umount /vendor;
umount -l /vendor;
if [ "$umount_data" ]; then
$bb umount /data;
$bb umount -l /data;
fi) 2>/dev/null;
}
restore_env() {
test "$savedpath" && export LD_LIBRARY_PATH="$savedpath";
test "$savedpre" && export LD_PRELOAD="$savedpre";
umount_all;
($bb mv -f /system_link /system;
$bb mv -f /system_root_link /system_root;
$bb umount -l /dev/random) 2>/dev/null;
}
abort() {
ui_print "$@";
debugging;
restore_env;
if [ ! -f anykernel.sh -o "$(file_getprop anykernel.sh do.cleanuponabort 2>/dev/null)" == 1 ]; then
cleanup;
fi;
exit 1;
}
show_progress 1.34 4;
ui_print " ";
cleanup;
mkdir -p $home/bin;
cd $home;
unzip -o "$ZIPFILE";
if [ $? != 0 -o ! "$(ls tools)" ]; then
abort "Unzip failed. Aborting...";
fi;
for arch32 in x86 arm; do
if [ -d $home/tools/$arch32 ]; then
bb=$home/tools/$arch32/busybox;
chmod 755 $bb;
$bb >/dev/null 2>&1;
if [ $? == 0 ]; then
$bb mv -f $home/tools/$arch32/* $home/tools;
break;
fi;
fi;
done;
bb=$home/tools/busybox;
chmod 755 $bb;
$bb chmod -R 755 tools bin;
$bb --install -s bin;
if [ $? != 0 -o -z "$(ls bin)" ]; then
abort "Busybox setup failed. Aborting...";
fi;
if [ -f banner ]; then
ui_printfile banner;
ui_print " " " ";
fi;
ui_print "$(file_getprop anykernel.sh kernel.string)";
if [ -f version ]; then
ui_print " ";
ui_printfile version;
ui_print " ";
fi;
ui_print " " "AnyKernel3 by osm0sis @ xda-developers" " " " ";
$BOOTMODE || $bb mount -o bind /dev/urandom /dev/random;
umount_all;
setup_mountpoint $ANDROID_ROOT;
if ! is_mounted $ANDROID_ROOT; then
$bb mount -o ro -t auto $ANDROID_ROOT;
fi;
case $ANDROID_ROOT in
/system_root) setup_mountpoint /system;;
/system)
if [ -f /system/system/build.prop ]; then
setup_mountpoint /system_root;
$bb mount --move /system /system_root;
if [ $? != 0 ]; then
$bb umount /system;
$bb umount -l /system 2>/dev/null;
$bb mount -o ro -t auto /dev/block/bootdevice/by-name/system /system_root;
fi;
fi;
;;
esac;
if is_mounted /system_root; then
$bb mount -o bind /system_root/system /system;
fi;
$bb mount -o ro -t auto /vendor 2>/dev/null;
if ! is_mounted /data; then
$bb mount /data;
umount_data=1;
fi;
savedpath="$LD_LIBRARY_PATH";
savedpre="$LD_PRELOAD";
unset LD_LIBRARY_PATH;
unset LD_PRELOAD;
if [ ! "$(getprop 2>/dev/null)" ]; then
getprop() {
local propdir propfile propval;
for propdir in / /system_root /system /vendor /odm /product; do
for propfile in default.prop build.prop; do
test "$propval" || propval="$(file_getprop $propdir/$propfile $1 2>/dev/null)";
done;
done;
test "$propval" && echo "$propval" || echo "";
}
elif [ ! "$(getprop ro.product.device 2>/dev/null)" -a ! "$(getprop ro.build.product 2>/dev/null)" -a ! "$(getprop ro.vendor.product.device 2>/dev/null)" -a ! "$(getprop ro.vendor.build.product 2>/dev/null)" ]; then
getprop() {
($(which getprop) | $bb grep "$1" | $bb cut -d[ -f3 | $bb cut -d] -f1) 2>/dev/null;
}
fi;
if [ "$(file_getprop anykernel.sh do.devicecheck)" == 1 ]; then
ui_print "Checking device...";
device=$(getprop ro.product.device 2>/dev/null);
product=$(getprop ro.build.product 2>/dev/null);
vendordevice=$(getprop ro.vendor.product.device 2>/dev/null);
vendorproduct=$(getprop ro.vendor.build.product 2>/dev/null);
for testname in $(file_getprop anykernel.sh 'device.name.*'); do
for devicename in $device $product $vendordevice $vendorproduct; do
if [ "$devicename" == "$testname" ]; then
ui_print "$testname" " ";
match=1;
break 2;
fi;
done;
done;
if [ ! "$match" ]; then
abort " " "Unsupported device. Aborting...";
fi;
fi;
supported_ver=$(file_getprop anykernel.sh supported.versions | $bb tr -d '[:space:]');
if [ "$supported_ver" ]; then
ui_print "Checking Android version...";
android_ver=$(file_getprop /system/build.prop ro.build.version.release);
parsed_ver=$(int2ver $android_ver);
if echo $supported_ver | $bb grep -q '-'; then
lo_ver=$(int2ver "$(echo $supported_ver | $bb cut -d- -f1)");
hi_ver=$(int2ver "$(echo $supported_ver | $bb cut -d- -f2)");
if echo -e "$hi_ver\n$lo_ver\n$parsed_ver" | $bb sort -g | $bb grep -n "$parsed_ver" | $bb grep -q '^2:'; then
supported=1;
fi;
else
for ver in $(echo $supported_ver | $bb sed 's;,; ;g'); do
if [ "$(int2ver $ver)" == "$parsed_ver" ]; then
supported=1;
break;
fi;
done;
fi;
if [ "$supported" ]; then
ui_print "$android_ver" " ";
else
abort " " "Unsupported Android version. Aborting...";
fi;
fi;
supported_lvl=$(file_getprop anykernel.sh supported.patchlevels | $bb grep -oE '[0-9]{4}-[0-9]{2}|-');
if [ "$supported_lvl" ]; then
ui_print "Checking Android security patch level...";
android_lvl=$(file_getprop /system/build.prop ro.build.version.security_patch);
parsed_lvl=$(echo $android_lvl | $bb grep -oE '[0-9]{4}-[0-9]{2}');
if echo $supported_lvl | $bb grep -q '^\-'; then
lo_lvl=0000-00;
hi_lvl=$(echo $supported_lvl | $bb awk '{ print $2 }');
elif echo $supported_lvl | $bb grep -q ' - '; then
lo_lvl=$(echo $supported_lvl | $bb awk '{ print $1 }');
hi_lvl=$(echo $supported_lvl | $bb awk '{ print $3 }');
elif echo $supported_lvl | $bb grep -q '\-$'; then
lo_lvl=$(echo $supported_lvl | $bb awk '{ print $1 }');
hi_lvl=9999-99;
fi;
if echo -e "$hi_lvl\n$lo_lvl\n$parsed_lvl" | $bb sort -g | $bb grep -n "$parsed_lvl" | $bb grep -q '^2:'; then
ui_print "$android_lvl" " ";
else
abort " " "Unsupported Android security patch level. Aborting...";
fi;
fi;
ui_print "Installing...";
core=$($bb grep -oE 'ak.*core.sh' anykernel.sh);
test -f tools/$core || $bb ln -s $home/tools/ak*-core.sh $home/tools/$core;
PATH="$home/bin:$PATH" home=$home $bb ash anykernel.sh $2;
if [ $? != 0 ]; then
abort;
fi;
if [ "$(file_getprop anykernel.sh do.modules)" == 1 ]; then
ui_print " " "Pushing modules...";
$bb mount -o rw,remount -t auto /system;
$bb mount -o rw,remount -t auto /vendor 2>/dev/null;
cd $home/modules;
for module in $(find . -name '*.ko'); do
modtarget=$(echo $module | $bb cut -c2-);
if [ ! -e $modtarget ]; then
case $module in
*/vendor/*) modcon=vendor;;
*) modcon=system;;
esac;
fi;
if is_mounted $modtarget; then
$bb mount -o rw,remount -t auto $modtarget;
fi;
mkdir -p $(dirname $modtarget);
$bb cp -rLf $module $modtarget;
$bb chown 0:0 $modtarget;
$bb chmod 644 $modtarget;
if [ "$modcon" ]; then
chcon "u:object_r:${modcon}_file:s0" $modtarget;
fi;
if is_mounted $modtarget; then
$bb mount -o ro,remount -t auto $modtarget;
fi;
done;
cd $home;
$bb mount -o ro,remount -t auto /system;
$bb mount -o ro,remount -t auto /vendor 2>/dev/null;
fi;
debugging;
restore_env;
if [ "$(file_getprop anykernel.sh do.cleanup)" == 1 ]; then
cleanup;
fi;
ui_print " " " " "Done!";
|