7dfe811ac6effa20fecdee81ea6dd96c729d3557
[GitHub/moto-9609/twrp_device_motorola_troika.git] / installer / META-INF / com / google / android / update-binary
1 #!/sbin/sh
2 # LazyFlasher installer backend (for helper functions only)
3
4 tmp=/tmp/twrp-install
5
6 if [ "$3" ]; then
7 zip=$3
8 console=/proc/$$/fd/$2
9 # write the location of the console buffer to /tmp/console for other scripts to use
10 echo "$console" > /tmp/console
11 else
12 console=$(cat /tmp/console)
13 [ "$console" ] || console=/proc/$$/fd/1
14 fi
15
16 print() {
17 if [ "$1" ]; then
18 echo "ui_print $1" > "$console"
19 else
20 echo "ui_print " > "$console"
21 fi
22 echo
23 }
24
25 abort() {
26 [ "$1" ] && {
27 print "Error: $1"
28 print "Aborting..."
29 }
30 cleanup
31 print "Failed to patch boot image!"
32 exit 1
33 }
34
35 cleanup() {
36 [ "$zip" ] && rm /tmp/console
37 }
38
39 extract() {
40 rm -rf "$2"
41 mkdir -p "$2"
42 unzip -o "$1" -d "$2" || abort "Failed to extract zip to $2!"
43 }
44
45 print "#########################################"
46 print "# TWRP installer for OnePlus 6T #"
47 print "# by mauronofrio #"
48 print "#########################################"
49
50 # Unpack the installer
51 [ "$zip" ] && {
52 print "Unpacking the installer..."
53 extract "$zip" "$tmp"
54 }
55 cd "$tmp"
56 toolname="/magiskboot"
57 tool="$tmp$toolname"
58 targetfile="/boot.img"
59 target="$tmp$targetfile"
60
61 chmod 755 "$tool"
62
63 print "Running boot image patcher on slot A..."
64 dd if=/dev/block/bootdevice/by-name/boot_a "of=$target"
65 "$tool" --unpack boot.img
66 cp -f ramdisk-recovery.cpio ramdisk.cpio
67 "$tool" --repack boot.img
68 dd if=new-boot.img of=/dev/block/bootdevice/by-name/boot_a
69 rm boot.img
70 rm dtb
71 rm kernel
72 rm new-boot.img
73 rm ramdisk.cpio
74 print "Running boot image patcher on slot B..."
75 dd if=/dev/block/bootdevice/by-name/boot_b "of=$target"
76 "$tool" --unpack boot.img
77 cp -f ramdisk-recovery.cpio ramdisk.cpio
78 "$tool" --repack boot.img
79 dd if=new-boot.img of=/dev/block/bootdevice/by-name/boot_b
80
81 print "Boot image patching complete"
82
83 #cleanup
84 print "Done installing TWRP!"