[OnePlus 6 Guides, News, & Discussion] TexnoViking:
After setting up Magisk root and MagiskHide Props, I was a bit disappointed to learn that you loose root after a LOS OTA update (which comes out every week). So, I decided to make a bash script to help me automate restoring root. This script still needs to run on your computer rather than on the phone, but it is still a major improvement to the manual process. I am sure smart people can adapt this script to be a BAT script that will work on Windows.

Prerequisites

USB Debugging enabled on your OnePlus 6.

ADB/Fastboot installed on your computer.

It is assumed that you already have root, you just temporarily lost it after an OTA update.

You will need python 3. You will also need to install at least re and requests packages using pip.

Python script for extracting boot.img from the payload.bin provided here https://wiki.lineageos.org/extracti...ing-proprietary-blobs-from-payload-based-otas

It is expected that you put it into `scripts` folder within your current working directory (from where you run the script).

Python script to download the latest LOS zip from the website created by me. Here are the contents of that downloadLOS.py script which is expected to be in your working directory.

import re
import requests

# Get HTML text of the downloads webpage
webpage = requests.get("https://download.lineageos.org/enchilada").text

# Get the firmware urls
pattern = r"(https:.*nightly.*signed\.zip)\""
matches = re.findall(pattern, webpage, flags=0)
matches.sort(reverse=True)
# Get the latest firmware URL
latestOSURL = matches[0]

# Extract firmware name
name = latestOSURL.split('/')[-1]
print("Latest firmware: " + name)
print("Download link: " + latestOSURL)

# Download the latest firmware
print("Downloading...")
with open(name, "wb") as f:
f.write(requests.get(latestOSURL).content)

print("Done!")

Magisk Root Automation Script

Before running the script, install the latest OTA update through the updater app and reboot once that is done.

The script is quite self explanatory. The steps are:

Download the latest LOS zip using downloadLOS.py script.

Extract boot.img and vbmeta.img from the zip using unzip and update-payload-extractor. These are needed for rooting.

Copy boot.img to phone's Download folder.

Here the script pauses, waiting for you to go into Magisk app to patch the boot.img that was just copied. Hit any key once you are done.

The patched boot image is copied to your computer and both boot images are removed from the phone.

The phone now reboots into bootloader. The script pauses. Hit any key once your phone is in bootloader.

Both boot_a and boot_b are flashed with patched boot image. vbmeta partition is also flashed.

The phone reboots.

Firmware files are cleaned from your folder.

flash.sh

#!/bin/bash

echo "Launching python script to download latest firmware ..."
python3 ./downloadLOS.py
echo ""

echo "Extracting boot.img ..."
echo "----"
unzip lineage*.zip 'payload.bin'
python3 ./scripts/update-payload-extractor/extract.py payload.bin --output_dir ./ --partitions boot vbmeta
echo "----"

echo ""

echo "Copying boot.img to phone... "
echo "----"
adb push ./boot.img /storage/emulated/0/Download
echo "----"

echo ""

read -t 1 -n 1
echo "Press any key after done patching boot... "
while [ true ] ; do
read -t 3 -n 1
if [ $? = 0 ] ; then
break ;
else
continue ;
fi
done

echo "Copying patched boot.img to PC... "
echo "----"
adb shell mv /storage/emulated/0/Download/magisk_patched* /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

echo ""

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 both boots... "
echo "----"
fastboot flash boot_a magisk_patched.img
fastboot flash boot_b magisk_patched.img
echo "----"

echo ""

echo "Flashing vbmeta... "
echo "----"
fastboot flash vbmeta --disable-verity --disable-verification vbmeta.img
echo "----"

echo ""

fastboot reboot

echo ""

echo "Done rooting!"

echo "Cleaning up local files ..."
rm *.img
rm *.bin
rm *.zip
echo "Complete!"

Notes

If you have slow internet and do not want to download the update twice. You could remove the whole downloadLOS.py section and use a separate script pullLOS.sh to pull the LOS update from your phone BEFORE YOU REBOOT after installing the update. After you reboot you loose root and cannot access it. For this you will need to enable rooted debugging in developer options.

#!/bin/bash

adb root

echo "Copying update zip from the phone ..."
adb shell mv /data/lineageos_updates/lineage* /data/lineageos_updates/lineage.zip
adb pull /data/lineageos_updates/lineage.zip lineage.zip
adb shell rm /data/lineageos_updates/lineage.zip
echo "----"
echo ""

Attachment

Attachments contains:

scripts folder for your convenience containing LOS extractor scripts. Feel free to remove and re-download from source.

downloadLOS.py python script to download the latest LOS zip from the website.

flash.sh the main script

pullLOS.sh optional script for those who want to avoid re-downloading OTA update.

I hope you guys find it helpful! Let me know if you encounter any problems.