Files
anykernel3-rhode/META-INF/com/google/android/update-binary
T
osm0sis 77fe6bffeb Backend: more robust getprop checks and replacements
- getprop failures are not only a system-as-root device issue, as it now also happens on OnePlus 5T in recovery when ROM is Pie Open Beta
- this appears to come down to a libc mismatch between recovery and ROM resulting in direct property checks failing but getprop without arguments printing all properties working
- revert most of https://github.com/osm0sis/AnyKernel2/commit/b1524da099efa716616a8eb3357876bca6a73540 since this should remain resolved with the new implementation
- keep the old check and file_getprop fallback for devices without getprop entirely
- add new getprop fallback that parses the full getprop output
2018-12-14 16:29:53 -04:00

185 lines
4.9 KiB
Bash
Executable File

#!/sbin/sh
# AnyKernel2 Backend
# osm0sis @ xda-developers
OUTFD=/proc/self/fd/$2;
ZIPFILE="$3";
DIR=`dirname "$ZIPFILE"`;
ui_print() {
until [ ! "$1" ]; do
echo -e "ui_print $1\nui_print" > $OUTFD;
shift;
done;
}
show_progress() { echo "progress $1 $2" > $OUTFD; }
file_getprop() { $bb grep "^$2=" "$1" | $bb cut -d= -f2; }
cleanup() { rm -rf /tmp/anykernel; }
debugging() {
case $(basename "$ZIPFILE" .zip) in
*-debugging)
ui_print " ";
ui_print "Creating debugging archive in zip directory...";
$bb tar -czvf "$DIR/anykernel2-$(date +%Y-%m-%d_%H%M%S)-debug.tgz" /tmp/*;
;;
esac;
}
unmount_all() {
(umount /system;
if [ -d /system_root -a ! -f /system/build.prop ]; then
umount /system_root;
fi;
umount /system;
umount /vendor;
umount /data) 2>/dev/null;
}
abort() {
ui_print "$*";
debugging;
if [ ! -f /tmp/anykernel/anykernel.sh -o "$(file_getprop /tmp/anykernel/anykernel.sh do.cleanuponabort 2>/dev/null)" == 1 ]; then
cleanup;
fi;
unmount_all;
exit 1;
}
show_progress 1.34 4;
ui_print " ";
cleanup;
mkdir -p /tmp/anykernel/bin;
cd /tmp/anykernel;
unzip -o "$ZIPFILE";
if [ $? != 0 -o -z "$(ls /tmp/anykernel/tools)" ]; then
abort "Unzip failed. Aborting...";
fi;
bb=/tmp/anykernel/tools/busybox;
chmod 755 $bb;
$bb chmod -R 755 /tmp/anykernel/tools /tmp/anykernel/bin;
if [ -f /tmp/anykernel/banner ]; then
while IFS='' read -r line || $bb [[ -n "$line" ]]; do
ui_print "$line";
done < /tmp/anykernel/banner;
ui_print " ";
ui_print " ";
fi;
ui_print "$(file_getprop /tmp/anykernel/anykernel.sh kernel.string)";
if [ -f /tmp/anykernel/version ]; then
ui_print " ";
while IFS='' read -r line || $bb [[ -n "$line" ]]; do
ui_print "$line";
done < /tmp/anykernel/version;
ui_print " ";
fi;
ui_print " ";
ui_print "AnyKernel2 by osm0sis @ xda-developers";
ui_print " ";
ui_print " ";
unmount_all;
$bb mount -o ro -t auto /system;
$bb mount -o ro -t auto /vendor 2>/dev/null;
$bb mount /data 2>/dev/null;
if [ -f /system/system/build.prop ]; then
umount /system;
umount /system 2>/dev/null;
mkdir /system_root 2>/dev/null;
$bb mount -o ro -t auto /dev/block/bootdevice/by-name/system /system_root;
$bb mount -o bind /system_root/system /system;
unset root;
fi;
savedpath="$LD_LIBRARY_PATH";
savedpre="$LD_PRELOAD";
unset LD_LIBRARY_PATH;
unset LD_PRELOAD;
if [ ! "$(getprop 2>/dev/null)" ]; then
getprop() {
local propval="$(file_getprop /default.prop $1 2>/dev/null)";
test "$propval" || local propval="$(file_getprop /system/build.prop $1 2>/dev/null)";
test "$propval" && echo "$propval" || echo "";
}
elif [ ! "$(getprop ro.product.device 2>/dev/null)" -a ! "$(getprop ro.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 /tmp/anykernel/anykernel.sh do.devicecheck)" == 1 ]; then
ui_print "Checking device...";
device="$(getprop ro.product.device)";
product="$(getprop ro.build.product)";
for testname in $(file_getprop /tmp/anykernel/anykernel.sh 'device.name.*'); do
test "$testname" || break;
if [ "$device" == "$testname" -o "$product" == "$testname" ]; then
ui_print "$testname";
match=1;
break;
fi;
done;
ui_print " ";
if [ "$match" != 1 ]; then
abort "Unsupported device. Aborting...";
fi;
fi;
ui_print "Installing...";
for i in $($bb --list); do
$bb ln -s $bb /tmp/anykernel/bin/$i;
done;
if [ $? != 0 -o -z "$(ls /tmp/anykernel/bin)" ]; then
abort "Recovery busybox setup failed. Aborting...";
fi;
PATH="/tmp/anykernel/bin:$PATH" $bb ash /tmp/anykernel/anykernel.sh $2;
if [ $? != "0" ]; then
abort;
fi;
if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.modules)" == 1 ]; then
ui_print " ";
ui_print "Pushing modules...";
$bb mount -o rw,remount -t auto /system;
$bb mount -o rw,remount -t auto /vendor 2>/dev/null;
cd /tmp/anykernel/modules;
for module in $(find . -name '*.ko'); do
if [ ! -e /$module ]; then
case $module in
*/vendor/*) mod=vendor;;
*) mod=system;;
esac;
fi;
if [ "$($bb mount | $bb grep " $(echo $module | $bb cut -c2-) ")" ]; then
$bb mount -o rw,remount -t auto /$module;
fi;
mkdir -p $(dirname /$module);
$bb cp -rLf $module /$module;
$bb chown 0:0 /$module;
$bb chmod 644 /$module;
if [ "$mod" ]; then
chcon "u:object_r:${mod}_file:s0" /$module;
fi;
if [ "$($bb mount | $bb grep " $(echo $module | $bb cut -c2-) ")" ]; then
$bb mount -o ro,remount -t auto /$module;
fi;
done;
cd /tmp/anykernel;
$bb mount -o ro,remount -t auto /system;
$bb mount -o ro,remount -t auto /vendor 2>/dev/null;
fi;
debugging;
if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.cleanup)" == 1 ]; then
cleanup;
fi;
test "$savedpath" && export LD_LIBRARY_PATH="$savedpath";
test "$savedpre" && export LD_PRELOAD="$savedpre";
unmount_all;
ui_print " ";
ui_print " ";
ui_print "Done!";