update-binary 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/sbin/sh
  2. # LazyFlasher installer backend (for helper functions only)
  3. # Heavily modified by Dees_Troy and osm0sis
  4. tmp=/dev/tmp/twrp-install
  5. # detect when flashing in Magisk Manager
  6. ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true || BOOTMODE=false;
  7. $BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true;
  8. if [ "$3" ]; then
  9. zip=$3
  10. console=/proc/$$/fd/$2
  11. fi
  12. print() {
  13. if $BOOTMODE; then
  14. echo "$1"
  15. else
  16. if [ "$1" ]; then
  17. echo "ui_print $1" > "$console"
  18. else
  19. echo "ui_print " > "$console"
  20. fi
  21. fi
  22. }
  23. extract() {
  24. rm -rf "$2"
  25. mkdir -p "$2"
  26. unzip -o "$1" -d "$2" || abort "Failed to extract zip to $2!"
  27. }
  28. print "########################################"
  29. print "# TWRP installer for Nokia #"
  30. print "# by theimpulson #"
  31. print "########################################"
  32. print
  33. # unpack the installer
  34. [ "$zip" ] && {
  35. print "Unpacking the installer..."
  36. extract "$zip" "$tmp"
  37. print
  38. }
  39. cd "$tmp"
  40. toolname="/magiskboot"
  41. tool="$tmp$toolname"
  42. targetfile="/boot.img"
  43. target="$tmp$targetfile"
  44. recoverycpio=`(ls ramdisk-twrp.cpio || ls ramdisk-recovery.cpio) 2>/dev/null`
  45. chmod 755 "$tool"
  46. for slot in a b; do
  47. print "Running boot image patcher on slot $slot..."
  48. dd if=/dev/block/bootdevice/by-name/boot_$slot "of=$target"
  49. "$tool" unpack -h boot.img
  50. # kernel string want_initramfs -> skip_initramfs (Magisk)
  51. "$tool" hexpatch kernel 77616E745F696E697472616D6673 736B69705F696E697472616D6673
  52. # kernel string trip_initramfs -> skip_initramfs (SuperSU)
  53. "$tool" hexpatch kernel 747269705F696E697472616D6673 736B69705F696E697472616D6673
  54. # boot.img cmdline remove skip_override (flar2 patch)
  55. sed -i "s|$(grep '^cmdline=' header | cut -d= -f2-)|$(grep '^cmdline=' header | cut -d= -f2- | sed -e 's/skip_override//' -e 's/ */ /g' -e 's/[ \t]*$//')|" header
  56. cp -f $recoverycpio ramdisk.cpio
  57. "$tool" repack boot.img
  58. dd if=new-boot.img of=/dev/block/bootdevice/by-name/boot_$slot
  59. "$tool" cleanup
  60. rm -f new-boot.img
  61. done
  62. print
  63. print "Boot image patching complete!"
  64. cd /
  65. rm -rf /dev/tmp
  66. print
  67. print "Done installing TWRP!"
  68. print
  69. print "*** NOTE: You are now unrooted! ***"