Skip to content

Commit

Permalink
Push sources and ramdisk
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnRTitor committed Mar 22, 2024
1 parent 09f1729 commit d8de4d4
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 0 deletions.
91 changes: 91 additions & 0 deletions OFOX_flashable/META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/sbin/sh
# TWRP A/B Installer Backend
# by osm0sis, Dees_Troy and topjohnwu

OUTFD=/proc/self/fd/$2;
ZIPFILE="$3";

ui_print() {
if $BOOTMODE; then
echo "$1";
else
echo -e "ui_print $1\nui_print" >> $OUTFD;
fi;
}
abort() { ui_print " "; ui_print "$1"; exit 1; }

# detect Magisk app/booted flashing
BOOTMODE=false;
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true;
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true;

ui_print "########################################";
ui_print "# OFOX flashable installer for redwood #";
ui_print "########################################";
ui_print " ";

# /dev/tmp is safe for both booted and recovery installs
tmp=/dev/tmp/twrp-install;
# target partition without the slot suffix
if [ -e /dev/block/bootdevice/by-name/recovery_b ]; then
target=/dev/block/bootdevice/by-name/recovery;
else
target=/dev/block/bootdevice/by-name/boot;
fi;
name=$(basename $target);

ui_print "Unpacking the installer...";
rm -rf $tmp;
mkdir -p $tmp;
unzip -o "$ZIPFILE" -d $tmp || abort "Failed to extract zip!";

cd $tmp;
recoverycpio=`(ls ramdisk-twrp.cpio || ls ramdisk-recovery.cpio) 2>/dev/null`;
recoveryimg=`(ls twrp*.img || ls TWRP*.img || ls recovery.img) 2>/dev/null`;
[ "$recoverycpio" ] || [ "$recoveryimg" ] || abort "No OFOX ramdisk/image found in zip!";

tool=$tmp/magiskboot;
chmod 755 $tool;

ui_print " ";
for slot in _a _b; do
if [ "$recoverycpio" ]; then
ui_print "Running image patcher on $name$slot...";
dd bs=1048576 if=$target$slot of=boot.img || abort "Failed to dump image!";
$tool unpack -h boot.img || abort "Failed to unpack image!";

# kernel string want_initramfs -> skip_initramfs (Magisk)
$tool hexpatch kernel 77616E745F696E697472616D6673 736B69705F696E697472616D6673;
# kernel string trip_initramfs -> skip_initramfs (SuperSU)
$tool hexpatch kernel 747269705F696E697472616D6673 736B69705F696E697472616D6673;

# boot.img header cmdline remove skip_override (flar2 patch)
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;

cp -f $recoverycpio ramdisk.cpio;
$tool repack boot.img || abort "Failed to repack image!";
$tool cleanup;
else
ui_print "Flashing image to $name$slot...";
cp -f $recoveryimg new-boot.img;
fi;

blockdev --setrw $target$slot;
cat new-boot.img /dev/zero > $target$slot 2>/dev/null || true;
rm -f new-boot.img;
done;

if [ "$recoverycpio" ]; then
ui_print " ";
ui_print "Image patching complete!";
fi;

cd /;
rm -rf /dev/tmp;

ui_print " ";
ui_print "Done installing OFOX!";
if [ "$name" != "recovery" ]; then
ui_print " ";
ui_print "*** NOTE: MAGISK ERASED! REFLASH ***";
fi;
1 change: 1 addition & 0 deletions OFOX_flashable/META-INF/com/google/android/updater-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#MAGISK
Binary file added OFOX_flashable/magiskboot
Binary file not shown.
Binary file added OFOX_flashable/ramdisk-recovery.cpio
Binary file not shown.
91 changes: 91 additions & 0 deletions TWRP_flashable/META-INF/com/google/android/update-binary
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/sbin/sh
# TWRP A/B Installer Backend
# by osm0sis, Dees_Troy and topjohnwu

OUTFD=/proc/self/fd/$2;
ZIPFILE="$3";

ui_print() {
if $BOOTMODE; then
echo "$1";
else
echo -e "ui_print $1\nui_print" >> $OUTFD;
fi;
}
abort() { ui_print " "; ui_print "$1"; exit 1; }

# detect Magisk app/booted flashing
BOOTMODE=false;
ps | grep zygote | grep -v grep >/dev/null && BOOTMODE=true;
$BOOTMODE || ps -A 2>/dev/null | grep zygote | grep -v grep >/dev/null && BOOTMODE=true;

ui_print "########################################";
ui_print "# TWRP flashable installer for redwood #";
ui_print "########################################";
ui_print " ";

# /dev/tmp is safe for both booted and recovery installs
tmp=/dev/tmp/twrp-install;
# target partition without the slot suffix
if [ -e /dev/block/bootdevice/by-name/recovery_b ]; then
target=/dev/block/bootdevice/by-name/recovery;
else
target=/dev/block/bootdevice/by-name/boot;
fi;
name=$(basename $target);

ui_print "Unpacking the installer...";
rm -rf $tmp;
mkdir -p $tmp;
unzip -o "$ZIPFILE" -d $tmp || abort "Failed to extract zip!";

cd $tmp;
recoverycpio=`(ls ramdisk-twrp.cpio || ls ramdisk-recovery.cpio) 2>/dev/null`;
recoveryimg=`(ls twrp*.img || ls TWRP*.img || ls recovery.img) 2>/dev/null`;
[ "$recoverycpio" ] || [ "$recoveryimg" ] || abort "No TWRP ramdisk/image found in zip!";

tool=$tmp/magiskboot;
chmod 755 $tool;

ui_print " ";
for slot in _a _b; do
if [ "$recoverycpio" ]; then
ui_print "Running image patcher on $name$slot...";
dd bs=1048576 if=$target$slot of=boot.img || abort "Failed to dump image!";
$tool unpack -h boot.img || abort "Failed to unpack image!";

# kernel string want_initramfs -> skip_initramfs (Magisk)
$tool hexpatch kernel 77616E745F696E697472616D6673 736B69705F696E697472616D6673;
# kernel string trip_initramfs -> skip_initramfs (SuperSU)
$tool hexpatch kernel 747269705F696E697472616D6673 736B69705F696E697472616D6673;

# boot.img header cmdline remove skip_override (flar2 patch)
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;

cp -f $recoverycpio ramdisk.cpio;
$tool repack boot.img || abort "Failed to repack image!";
$tool cleanup;
else
ui_print "Flashing image to $name$slot...";
cp -f $recoveryimg new-boot.img;
fi;

blockdev --setrw $target$slot;
cat new-boot.img /dev/zero > $target$slot 2>/dev/null || true;
rm -f new-boot.img;
done;

if [ "$recoverycpio" ]; then
ui_print " ";
ui_print "Image patching complete!";
fi;

cd /;
rm -rf /dev/tmp;

ui_print " ";
ui_print "Done installing TWRP!";
if [ "$name" != "recovery" ]; then
ui_print " ";
ui_print "*** NOTE: MAGSIK ERASED! REFLASH ***";
fi;
1 change: 1 addition & 0 deletions TWRP_flashable/META-INF/com/google/android/updater-script
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#MAGISK
Binary file added TWRP_flashable/magiskboot
Binary file not shown.
Binary file added TWRP_flashable/ramdisk-recovery.cpio
Binary file not shown.

0 comments on commit d8de4d4

Please sign in to comment.