Skip to content

Instantly share code, notes, and snippets.

@2shrestha22
Last active June 3, 2024 10:17
Show Gist options
  • Save 2shrestha22/b2f15066c1627085e0913ac52d243d62 to your computer and use it in GitHub Desktop.
Save 2shrestha22/b2f15066c1627085e0913ac52d243d62 to your computer and use it in GitHub Desktop.
Helper script to flash Magisk for non A/B device.
#!/bin/bash
# To run this:
# bash <(curl -sL https://gist.githubusercontent.com/2shrestha22/b2f15066c1627085e0913ac52d243d62/raw/2c477da35d44b77a510783a1d1494cc90feb9217/magisk_flash.sh)
BOOT_IMAGE_FILE_NAME="boot.img"
BOOT_IMAGE_FILE_PATH="./$BOOT_IMAGE_FILE_NAME"
echo -e "Helper srcipt to flash Magisk patched boot.img for non A/B device...\n"
if adb shell getprop ro.build.ab_update | grep -q true; then
echo "A/B device detected but this script is only for non A/B device. Exiting..."
exit 1;
fi
read -t 1 -n 1
echo -e "YOU will be RESPONSIBLE for anything this script does including bricking your device...\n"
echo -e "This script will copy $BOOT_IMAGE_FILE_NAME file from $PWD to you device download folder. Then you need to manually path it from Magisk app. Then this script will copy patched boot img file and flash it in the boot partition...\n"
echo -e "Press any key to continue. Or Ctrl+C to exit..."
while [ true ] ; do
read -t 3 -n 1
if [ $? = 0 ] ; then
break ;
else
continue ;
fi
done
if [ ! -f $BOOT_IMAGE_FILE_NAME ]; then
echo ""
echo -e "$BOOT_IMAGE_FILE_NAME not found in $PWD.\n"
exit 1;
fi
echo "Copying $BOOT_IMAGE_FILE_NAME to phone (/storage/emulated/0/Download)..."
echo "----"
adb push $BOOT_IMAGE_FILE_PATH /storage/emulated/0/Download
echo "----"
echo ""
echo -e "Removing any already patched boot img files from device...\n"
adb shell rm -rf /storage/emulated/0/Download/magisk_patched*.img
read -t 1 -n 1
echo -e "Press any key after done patching boot from Magisk app...\n"
while [ true ] ; do
read -t 3 -n 1
if [ $? = 0 ] ; then
break ;
else
continue ;
fi
done
echo "Copying patched $BOOT_IMAGE_FILE_NAME to $PWD..."
echo "----"
adb shell mv /storage/emulated/0/Download/magisk_patched*.img /storage/emulated/0/Download/magisk_patched.img
adb pull /storage/emulated/0/Download/magisk_patched.img magisk_patched.img
echo "----"
echo ""
echo "Removing boot images from phone... "
echo "----"
adb shell rm /storage/emulated/0/Download/boot.img
adb shell rm /storage/emulated/0/Download/magisk_patched.img
read -t 1 -n 1
echo -e "If installing Magisk in your device does not include 'fastboot flash boot /path/to/magisk_patched_[random_strings].img' step then STOP right here...\nPress any key to continue or Ctrl+C to exit...\n"
while [ true ] ; do
read -t 3 -n 1
if [ $? = 0 ] ; then
break ;
else
continue ;
fi
done
echo "Rebooting to bootloader... "
echo "----"
adb reboot bootloader
read -t 1 -n 1
echo "Press any key when in bootloader... "
while [ true ] ; do
read -t 3 -n 1
if [ $? = 0 ] ; then
break ;
else
continue ;
fi
done
echo "----"
echo "Flashing boot partition... "
echo "----"
fastboot flash boot magisk_patched.img
echo "----"
echo ""
fastboot reboot
echo ""
echo "Done rooting!"
echo "Cleaning up local files ..."
rm $BOOT_IMAGE_FILE_PATH
rm magisk_patched.img
echo "Complete!"
@2shrestha22
Copy link
Author

To run this script:

bash <(curl -sL https://gist.githubusercontent.com/2shrestha22/b2f15066c1627085e0913ac52d243d62/raw/2c477da35d44b77a510783a1d1494cc90feb9217/magisk_flash.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment