- symlinks under /system/lib/modules were getting broken, so follow them instead to replace the target file, avoiding issues with multiple versions of the same module and running out of free space (e.g. OnePlus devices link /system/lib/modules/wlan.ko to /system/lib/modules/qca_cld3/qca_cld3_wlan.ko) - set contexts on copied modules (following symlinks) to system_file to avoid SELinux issues where unlabeled module files might not be allowed to load
109 lines
3.1 KiB
Bash
Executable File
109 lines
3.1 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; }
|
|
set_perm_recursive() {
|
|
dirs=$(echo $* | $bb awk '{ print substr($0, index($0,$5)) }');
|
|
for i in $dirs; do
|
|
$bb chown -R $1:$2 $i;
|
|
find "$i" -type d -exec chmod $3 {} +;
|
|
find "$i" -type f -exec chmod $4 {} +;
|
|
done;
|
|
}
|
|
file_getprop() { grep "^$2" "$1" | cut -d= -f2; }
|
|
getprop() { test -e /sbin/getprop && /sbin/getprop $1 || file_getprop /default.prop $1; }
|
|
cleanup() { rm -rf /tmp/anykernel; }
|
|
abort() {
|
|
if [ ! -f /tmp/anykernel/anykernel.sh -o "$(file_getprop /tmp/anykernel/anykernel.sh do.cleanuponabort 2>/dev/null)" == 1 ]; then
|
|
ui_print "$*"; cleanup; umount /system; umount /data; exit 1;
|
|
else
|
|
ui_print "$*"; umount /system; umount /data; exit 1;
|
|
fi;
|
|
}
|
|
|
|
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;
|
|
chmod -R 755 /tmp/anykernel/tools /tmp/anykernel/bin;
|
|
bb=/tmp/anykernel/tools/busybox;
|
|
|
|
ui_print "$(file_getprop /tmp/anykernel/anykernel.sh kernel.string)";
|
|
ui_print " ";
|
|
ui_print "AnyKernel2 by osm0sis @ xda-developers";
|
|
ui_print " ";
|
|
umount /system 2>/dev/null;
|
|
mount -o ro -t auto /system;
|
|
mount /data 2>/dev/null;
|
|
test -f /system/system/build.prop && root=/system;
|
|
|
|
if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.devicecheck)" == 1 ]; then
|
|
ui_print "Checking device...";
|
|
for i in 1 2 3 4 5; do
|
|
testname="$(file_getprop /tmp/anykernel/anykernel.sh device.name$i)";
|
|
if [ "$(getprop ro.product.device)" == "$testname" -o "$(getprop ro.build.product)" == "$testname" ]; then
|
|
ui_print "$testname";
|
|
match=1;
|
|
fi;
|
|
done;
|
|
ui_print " ";
|
|
if [ "$match" != 1 ]; then
|
|
abort "Unsupported device. Aborting...";
|
|
fi;
|
|
fi;
|
|
|
|
ui_print "Installing kernel...";
|
|
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...";
|
|
mount -o rw,remount -t auto /system;
|
|
cp -rLf /tmp/anykernel/modules/* $root/system/lib/modules/;
|
|
set_perm_recursive 0 0 0755 0644 $root/system/lib/modules;
|
|
chcon -R 'u:object_r:system_file:s0' $root/system/lib/modules;
|
|
mount -o ro,remount -t auto /system;
|
|
fi;
|
|
|
|
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;
|
|
|
|
if [ "$(file_getprop /tmp/anykernel/anykernel.sh do.cleanup)" == 1 ]; then
|
|
cleanup;
|
|
fi;
|
|
|
|
umount /system;
|
|
umount /data;
|
|
ui_print " ";
|
|
ui_print "Done!";
|