2015-01-07 15:11:36 -04:00
|
|
|
#!/sbin/sh
|
2019-05-31 23:49:18 -03:00
|
|
|
# AnyKernel3 Backend (DO NOT CHANGE)
|
2015-01-07 15:11:36 -04:00
|
|
|
# osm0sis @ xda-developers
|
2010-12-21 09:46:05 -08:00
|
|
|
|
2015-01-07 15:11:36 -04:00
|
|
|
OUTFD=/proc/self/fd/$2;
|
2017-05-28 18:44:46 -03:00
|
|
|
ZIPFILE="$3";
|
2019-06-07 17:03:38 -03:00
|
|
|
|
|
|
|
|
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");
|
2019-05-31 23:49:18 -03:00
|
|
|
|
2019-08-17 22:48:51 -03:00
|
|
|
test "$ANDROID_ROOT" || ANDROID_ROOT=/system;
|
2019-05-31 23:49:18 -03:00
|
|
|
test "$home" || home=/tmp/anykernel;
|
2010-12-21 09:46:05 -08:00
|
|
|
|
2015-01-07 15:11:36 -04:00
|
|
|
ui_print() {
|
|
|
|
|
until [ ! "$1" ]; do
|
|
|
|
|
echo -e "ui_print $1\nui_print" > $OUTFD;
|
|
|
|
|
shift;
|
|
|
|
|
done;
|
|
|
|
|
}
|
2019-08-12 23:40:53 -03:00
|
|
|
ui_printfile() {
|
|
|
|
|
while IFS='' read -r line || $bb [[ -n "$line" ]]; do
|
|
|
|
|
ui_print "$line";
|
|
|
|
|
done < $1;
|
|
|
|
|
}
|
2015-01-07 15:11:36 -04:00
|
|
|
show_progress() { echo "progress $1 $2" > $OUTFD; }
|
2018-12-16 13:51:57 -04:00
|
|
|
file_getprop() { $bb grep "^$2=" "$1" | $bb cut -d= -f2-; }
|
2019-01-02 17:08:22 -04:00
|
|
|
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() {
|
2019-06-25 16:04:21 +08:00
|
|
|
cd $(dirname $home);
|
2019-05-31 23:49:18 -03:00
|
|
|
rm -rf $home;
|
2018-12-15 00:36:26 -04:00
|
|
|
}
|
2017-09-22 00:18:31 -03:00
|
|
|
debugging() {
|
|
|
|
|
case $(basename "$ZIPFILE" .zip) in
|
|
|
|
|
*-debugging)
|
2019-06-07 17:03:38 -03:00
|
|
|
ui_print " " "Creating debugging archive in $DIR...";
|
2019-06-10 00:01:13 -03:00
|
|
|
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;
|
2017-09-22 00:18:31 -03:00
|
|
|
;;
|
|
|
|
|
esac;
|
|
|
|
|
}
|
2019-08-12 23:40:53 -03:00
|
|
|
setup_mountpoint() {
|
2019-08-17 22:48:51 -03:00
|
|
|
test -L $1 && $bb mv -f $1 ${1}_link;
|
|
|
|
|
if [ ! -d $1 ]; then
|
2019-08-12 23:40:53 -03:00
|
|
|
rm -f $1;
|
|
|
|
|
mkdir $1;
|
|
|
|
|
fi;
|
|
|
|
|
}
|
2019-07-12 21:07:16 -03:00
|
|
|
is_mounted() { $bb mount | $bb grep -q " $1 "; }
|
2019-08-12 23:40:53 -03:00
|
|
|
umount_all() {
|
2019-05-31 23:49:18 -03:00
|
|
|
($bb umount /system;
|
2019-08-17 22:48:51 -03:00
|
|
|
$bb umount -l /system;
|
|
|
|
|
if [ -e /system_root ]; then
|
2019-05-31 23:49:18 -03:00
|
|
|
$bb umount /system_root;
|
2019-08-17 22:48:51 -03:00
|
|
|
$bb umount -l /system_root;
|
2018-06-27 18:27:34 -03:00
|
|
|
fi;
|
2019-06-23 20:28:24 +08:00
|
|
|
umount /vendor;
|
2019-08-17 22:48:51 -03:00
|
|
|
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;
|
2019-08-27 13:37:49 -03:00
|
|
|
$bb mv -f /system_root_link /system_root;
|
|
|
|
|
$bb umount -l /dev/random) 2>/dev/null;
|
2018-06-27 18:27:34 -03:00
|
|
|
}
|
2017-05-26 22:24:45 -03:00
|
|
|
abort() {
|
2019-08-04 01:16:54 -03:00
|
|
|
ui_print "$@";
|
2017-09-22 00:18:31 -03:00
|
|
|
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
|
2017-09-22 00:18:31 -03:00
|
|
|
cleanup;
|
2017-05-26 22:24:45 -03:00
|
|
|
fi;
|
2019-08-17 22:48:51 -03:00
|
|
|
restore_env;
|
2017-09-22 00:18:31 -03:00
|
|
|
exit 1;
|
2017-05-26 22:24:45 -03:00
|
|
|
}
|
2010-12-21 09:46:05 -08:00
|
|
|
|
2015-01-07 15:11:36 -04:00
|
|
|
show_progress 1.34 4;
|
|
|
|
|
ui_print " ";
|
2017-02-17 22:18:39 +01:00
|
|
|
cleanup;
|
2019-05-31 23:49:18 -03:00
|
|
|
mkdir -p $home/bin;
|
|
|
|
|
cd $home;
|
2017-05-28 18:44:46 -03:00
|
|
|
unzip -o "$ZIPFILE";
|
2019-05-31 23:49:18 -03:00
|
|
|
if [ $? != 0 -o ! "$(ls tools)" ]; then
|
2015-12-04 10:06:31 -04:00
|
|
|
abort "Unzip failed. Aborting...";
|
|
|
|
|
fi;
|
2019-07-01 17:42:34 -03:00
|
|
|
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;
|
2019-05-31 23:49:18 -03:00
|
|
|
bb=$home/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;
|
2019-05-31 23:49:18 -03:00
|
|
|
$bb --install -s bin;
|
|
|
|
|
if [ $? != 0 -o -z "$(ls bin)" ]; then
|
|
|
|
|
abort "Busybox setup failed. Aborting...";
|
|
|
|
|
fi;
|
2010-12-21 09:46:05 -08:00
|
|
|
|
2018-12-15 00:36:26 -04:00
|
|
|
if [ -f banner ]; then
|
2019-08-12 23:40:53 -03:00
|
|
|
ui_printfile banner;
|
2019-05-31 23:49:18 -03:00
|
|
|
ui_print " " " ";
|
2018-02-26 11:18:35 -04:00
|
|
|
fi;
|
|
|
|
|
|
2018-12-15 00:36:26 -04:00
|
|
|
ui_print "$(file_getprop anykernel.sh kernel.string)";
|
|
|
|
|
if [ -f version ]; then
|
2018-02-26 12:22:58 -04:00
|
|
|
ui_print " ";
|
2019-08-12 23:40:53 -03:00
|
|
|
ui_printfile version;
|
2018-02-26 12:22:58 -04:00
|
|
|
ui_print " ";
|
|
|
|
|
fi;
|
2019-05-31 23:49:18 -03:00
|
|
|
ui_print " " "AnyKernel3 by osm0sis @ xda-developers" " " " ";
|
2018-02-26 13:03:50 -04:00
|
|
|
|
2019-08-27 13:37:49 -03:00
|
|
|
$BOOTMODE || $bb mount -o bind /dev/urandom /dev/random;
|
2019-08-12 23:40:53 -03:00
|
|
|
umount_all;
|
2019-08-17 22:48:51 -03:00
|
|
|
setup_mountpoint $ANDROID_ROOT;
|
|
|
|
|
if ! is_mounted $ANDROID_ROOT; then
|
|
|
|
|
$bb mount -o ro -t auto $ANDROID_ROOT;
|
2018-12-16 23:17:16 -04:00
|
|
|
fi;
|
2019-08-17 22:48:51 -03:00
|
|
|
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
|
2018-12-11 02:15:53 -04:00
|
|
|
$bb mount -o bind /system_root/system /system;
|
2018-07-19 21:22:30 -03:00
|
|
|
fi;
|
2019-08-17 22:48:51 -03:00
|
|
|
$bb mount -o ro -t auto /vendor 2>/dev/null;
|
|
|
|
|
if ! is_mounted /data; then
|
|
|
|
|
$bb mount /data;
|
|
|
|
|
umount_data=1;
|
|
|
|
|
fi;
|
|
|
|
|
|
2018-07-19 21:22:30 -03:00
|
|
|
savedpath="$LD_LIBRARY_PATH";
|
|
|
|
|
savedpre="$LD_PRELOAD";
|
|
|
|
|
unset LD_LIBRARY_PATH;
|
|
|
|
|
unset LD_PRELOAD;
|
|
|
|
|
|
2018-12-14 16:29:53 -04:00
|
|
|
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
|
2018-12-14 16:29:53 -04:00
|
|
|
ui_print "Checking device...";
|
2019-07-20 18:11:33 -03:00
|
|
|
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
|
2018-12-14 16:29:53 -04:00
|
|
|
if [ "$device" == "$testname" -o "$product" == "$testname" ]; then
|
2019-07-20 18:11:33 -03:00
|
|
|
ui_print "$testname" " ";
|
2018-12-14 16:29:53 -04:00
|
|
|
match=1;
|
|
|
|
|
break;
|
|
|
|
|
fi;
|
|
|
|
|
done;
|
2018-12-16 18:31:53 -04:00
|
|
|
if [ ! "$match" ]; then
|
2019-07-20 18:11:33 -03:00
|
|
|
abort " " "Unsupported device. Aborting...";
|
2018-12-14 16:29:53 -04:00
|
|
|
fi;
|
|
|
|
|
fi;
|
|
|
|
|
|
2019-07-20 18:11:33 -03:00
|
|
|
supported_ver=$(file_getprop anykernel.sh supported.versions | $bb tr -d '[:space:]');
|
2018-12-16 18:31:53 -04:00
|
|
|
if [ "$supported_ver" ]; then
|
|
|
|
|
ui_print "Checking Android version...";
|
2019-07-20 18:11:33 -03:00
|
|
|
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
|
2018-12-16 18:31:53 -04:00
|
|
|
supported=1;
|
|
|
|
|
fi;
|
|
|
|
|
else
|
|
|
|
|
for ver in $(echo $supported_ver | $bb sed 's;,; ;g'); do
|
2019-07-20 18:11:33 -03:00
|
|
|
if [ "$(int2ver $ver)" == "$parsed_ver" ]; then
|
2018-12-16 18:31:53 -04:00
|
|
|
supported=1;
|
|
|
|
|
break;
|
|
|
|
|
fi;
|
|
|
|
|
done;
|
|
|
|
|
fi;
|
|
|
|
|
if [ "$supported" ]; then
|
2019-05-31 23:49:18 -03:00
|
|
|
ui_print "$android_ver" " ";
|
2018-12-16 18:31:53 -04:00
|
|
|
else
|
2019-07-20 18:11:33 -03:00
|
|
|
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;
|
2019-07-20 18:43:02 -03:00
|
|
|
hi_lvl=$(echo $supported_lvl | $bb awk '{ print $2 }');
|
2019-07-20 18:11:33 -03:00
|
|
|
elif echo $supported_lvl | $bb grep -q ' - '; then
|
2019-07-20 18:43:02 -03:00
|
|
|
lo_lvl=$(echo $supported_lvl | $bb awk '{ print $1 }');
|
|
|
|
|
hi_lvl=$(echo $supported_lvl | $bb awk '{ print $3 }');
|
2019-07-20 18:11:33 -03:00
|
|
|
elif echo $supported_lvl | $bb grep -q '\-$'; then
|
2019-07-20 18:43:02 -03:00
|
|
|
lo_lvl=$(echo $supported_lvl | $bb awk '{ print $1 }');
|
2019-07-20 18:11:33 -03:00
|
|
|
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...";
|
2018-12-16 18:31:53 -04:00
|
|
|
fi;
|
|
|
|
|
fi;
|
|
|
|
|
|
2018-05-29 23:57:29 -03:00
|
|
|
ui_print "Installing...";
|
2019-05-31 23:49:18 -03:00
|
|
|
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;
|
2018-12-15 00:36:26 -04:00
|
|
|
if [ $? != 0 ]; then
|
2015-01-07 15:11:36 -04:00
|
|
|
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
|
2019-05-31 23:49:18 -03:00
|
|
|
ui_print " " "Pushing modules...";
|
2018-12-11 02:15:53 -04:00
|
|
|
$bb mount -o rw,remount -t auto /system;
|
|
|
|
|
$bb mount -o rw,remount -t auto /vendor 2>/dev/null;
|
2019-05-31 23:49:18 -03:00
|
|
|
cd $home/modules;
|
2018-01-01 20:32:24 -07:00
|
|
|
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;
|
2019-07-12 21:07:16 -03:00
|
|
|
if is_mounted $modtarget; then
|
2018-12-16 23:17:16 -04:00
|
|
|
$bb mount -o rw,remount -t auto $modtarget;
|
2018-12-11 13:34:37 -04:00
|
|
|
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;
|
2019-07-12 21:07:16 -03:00
|
|
|
if is_mounted $modtarget; then
|
2018-12-16 23:17:16 -04:00
|
|
|
$bb mount -o ro,remount -t auto $modtarget;
|
2018-12-11 13:34:37 -04:00
|
|
|
fi;
|
2018-01-01 20:32:24 -07:00
|
|
|
done;
|
2019-05-31 23:49:18 -03:00
|
|
|
cd $home;
|
2018-12-11 02:15:53 -04:00
|
|
|
$bb mount -o ro,remount -t auto /system;
|
|
|
|
|
$bb mount -o ro,remount -t auto /vendor 2>/dev/null;
|
2015-01-07 15:11:36 -04:00
|
|
|
fi;
|
2010-12-21 09:46:05 -08:00
|
|
|
|
2017-09-22 00:18:31 -03:00
|
|
|
debugging;
|
2017-05-28 18:44:46 -03:00
|
|
|
|
2018-12-15 00:36:26 -04:00
|
|
|
if [ "$(file_getprop anykernel.sh do.cleanup)" == 1 ]; then
|
2017-02-17 22:17:27 +01:00
|
|
|
cleanup;
|
2015-01-07 15:11:36 -04:00
|
|
|
fi;
|
2010-12-21 09:46:05 -08:00
|
|
|
|
2019-08-17 22:48:51 -03:00
|
|
|
restore_env;
|
2018-06-27 18:27:34 -03:00
|
|
|
|
2019-05-31 23:49:18 -03:00
|
|
|
ui_print " " " " "Done!";
|