Files
anykernel3-rhode/META-INF/com/google/android/update-binary
T

225 lines
5.8 KiB
Bash
Raw Normal View History

#!/sbin/sh
2018-12-16 18:31:53 -04:00
# AnyKernel2 Backend (DO NOT CHANGE)
# osm0sis @ xda-developers
2010-12-21 09:46:05 -08:00
OUTFD=/proc/self/fd/$2;
ZIPFILE="$3";
DIR=`dirname "$ZIPFILE"`;
2010-12-21 09:46:05 -08:00
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-; }
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;
}
2018-12-15 00:36:26 -04:00
cleanup() {
cd /tmp;
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;
}
2018-12-16 23:17:16 -04:00
is_mounted() { $bb mount | $bb grep " $1 "; }
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;
2018-12-15 00:36:26 -04:00
if [ ! -f anykernel.sh -o "$(file_getprop anykernel.sh do.cleanuponabort 2>/dev/null)" == 1 ]; then
cleanup;
fi;
unmount_all;
exit 1;
}
2010-12-21 09:46:05 -08:00
show_progress 1.34 4;
ui_print " ";
cleanup;
mkdir -p /tmp/anykernel/bin;
cd /tmp/anykernel;
unzip -o "$ZIPFILE";
2018-12-15 00:36:26 -04:00
if [ $? != 0 -o -z "$(ls tools)" ]; then
abort "Unzip failed. Aborting...";
fi;
bb=/tmp/anykernel/tools/busybox;
2017-08-20 00:36:17 -03:00
chmod 755 $bb;
2018-12-15 00:36:26 -04:00
$bb chmod -R 755 tools bin;
2010-12-21 09:46:05 -08:00
2018-12-15 00:36:26 -04:00
if [ -f banner ]; then
2018-02-26 11:18:35 -04:00
while IFS='' read -r line || $bb [[ -n "$line" ]]; do
ui_print "$line";
2018-12-15 00:36:26 -04:00
done < banner;
2018-02-26 11:18:35 -04:00
ui_print " ";
ui_print " ";
fi;
2018-12-15 00:36:26 -04:00
ui_print "$(file_getprop anykernel.sh kernel.string)";
if [ -f version ]; then
ui_print " ";
while IFS='' read -r line || $bb [[ -n "$line" ]]; do
ui_print "$line";
2018-12-15 00:36:26 -04:00
done < version;
ui_print " ";
fi;
ui_print " ";
ui_print "AnyKernel2 by osm0sis @ xda-developers";
ui_print " ";
ui_print " ";
unmount_all;
2018-12-16 23:17:16 -04:00
if [ ! "$(is_mounted /system)" ]; then
$bb mount -o ro -t auto /system;
fi;
($bb mount -o ro -t auto /vendor;
$bb mount /data) 2>/dev/null;
if [ -f /system/system/build.prop ]; then
umount /system;
2018-12-16 23:17:16 -04:00
(umount /system;
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;
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;
2018-12-15 00:36:26 -04:00
if [ "$(file_getprop anykernel.sh do.devicecheck)" == 1 ]; then
ui_print "Checking device...";
device="$(getprop ro.product.device)";
product="$(getprop ro.build.product)";
2018-12-15 00:36:26 -04:00
for testname in $(file_getprop anykernel.sh 'device.name.*'); do
if [ "$device" == "$testname" -o "$product" == "$testname" ]; then
ui_print "$testname";
match=1;
break;
fi;
done;
ui_print " ";
2018-12-16 18:31:53 -04:00
if [ ! "$match" ]; then
abort "Unsupported device. Aborting...";
fi;
fi;
2018-12-16 18:31:53 -04:00
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)";
if [ "$(echo $supported_ver | $bb grep -)" ]; then
lo_ver=$(echo $supported_ver | $bb cut -d- -f1);
hi_ver=$(echo $supported_ver | $bb cut -d- -f2);
if [ "$(echo -e "$(int2ver $hi_ver)\n$(int2ver $lo_ver)\n$(int2ver $android_ver)" | $bb sort -g | $bb grep -n "$(int2ver $android_ver)" | $bb grep '^2:')" ]; then
2018-12-16 18:31:53 -04:00
supported=1;
fi;
else
for ver in $(echo $supported_ver | $bb sed 's;,; ;g'); do
if [ "$(int2ver $ver)" == "$(int2ver $android_ver)" ]; then
2018-12-16 18:31:53 -04:00
supported=1;
break;
fi;
done;
fi;
if [ "$supported" ]; then
ui_print "$android_ver";
ui_print " ";
else
ui_print " ";
abort "Unsupported Android version. Aborting...";
fi;
fi;
2018-05-29 23:57:29 -03:00
ui_print "Installing...";
for i in $($bb --list); do
2018-12-15 00:36:26 -04:00
$bb ln -s $bb bin/$i;
done;
2018-12-15 00:36:26 -04:00
if [ $? != 0 -o -z "$(ls bin)" ]; then
abort "Recovery busybox setup failed. Aborting...";
fi;
2018-12-15 00:36:26 -04:00
PATH="/tmp/anykernel/bin:$PATH" $bb ash anykernel.sh $2;
if [ $? != 0 ]; then
abort;
fi;
2010-12-21 09:46:05 -08:00
2018-12-15 00:36:26 -04:00
if [ "$(file_getprop 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;
2018-01-01 20:32:24 -07:00
cd /tmp/anykernel/modules;
for module in $(find . -name '*.ko'); do
2018-12-16 23:17:16 -04:00
modtarget=$(echo $module | $bb cut -c2-);
if [ ! -e $modtarget ]; then
2018-01-06 17:58:25 -07:00
case $module in
2018-12-16 23:17:16 -04:00
*/vendor/*) modcon=vendor;;
*) modcon=system;;
2018-01-06 17:58:25 -07:00
esac;
fi;
2018-12-16 23:17:16 -04:00
if [ "$(is_mounted $modtarget)" ]; then
$bb mount -o rw,remount -t auto $modtarget;
fi;
2018-12-16 23:17:16 -04:00
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;
2018-01-06 17:58:25 -07:00
fi;
2018-12-16 23:17:16 -04:00
if [ "$(is_mounted $modtarget)" ]; then
$bb mount -o ro,remount -t auto $modtarget;
fi;
2018-01-01 20:32:24 -07:00
done;
cd /tmp/anykernel;
$bb mount -o ro,remount -t auto /system;
$bb mount -o ro,remount -t auto /vendor 2>/dev/null;
fi;
2010-12-21 09:46:05 -08:00
debugging;
2018-12-15 00:36:26 -04:00
if [ "$(file_getprop anykernel.sh do.cleanup)" == 1 ]; then
cleanup;
fi;
2010-12-21 09:46:05 -08:00
test "$savedpath" && export LD_LIBRARY_PATH="$savedpath";
test "$savedpre" && export LD_PRELOAD="$savedpre";
unmount_all;
ui_print " ";
ui_print " ";
ui_print "Done!";