0

I have a rooted Nexus 5, but this question would apply, I think, to any rooted device running Android 5.x and higher. Note also this is a question about a script to run on a osx/linux to manipulate the phone, not a script to run on the phone itself.

Rooted devices can't be upgraded using the OTA method, because that checks to see whether there is a stock recovery and won't install if there isn't one. So very time Android is upgraded, it's necessary for the owners of rooted devices to find and download the new factory image, flash it (which will destroy the custom recovery) and then reflash a custom recovery and finally reflash the superuser tool of choice.

Now that Google has committed to monthly security upgrades I'd like to automate this process. This needs a shell script or similar on OSX.

The middle part is easily done by tweaking a copy of the flash-all.sh script that comes with all factory images: something like

fastboot flash bootloader bootloader-hammerhead-hhz12h.img
fastboot reboot-bootloader
sleep 5
fastboot flash radio radio-hammerhead-m8974a-2.0.50.2.26.img
fastboot reboot-bootloader
sleep 5
fastboot update image-hammerhead-lmy48m.zip
# -w flag removed from line above so that itjust upgrades and does not wipe all the apps. data and so on
# now flash the recovery
fastboot reboot-bootloader
sleep 5
fastboot flash recovery twrp-2.8.6.0-hammerhead.img

(obviously I can and should replace the particular file names with variables to suit)

I'd like to improve this script by adding a line or two at the beginning to download the most recent factory image from the Google site -- and that is what I don't know how to do. There must be some variant of curl or wget which will do this. But is there a way to choose the most recent available file from a particular site, download and then unzip and untar it automatically?

  • Out of curiosity: why are you rebooting the device at all after flashing a partition? – Firelord Sep 18 '15 at 11:37
  • That's what the original script does, so when I added the lines to flash the recovery I thought it was the safe thing to do. To be consistent I should add one more line to reboot into the new recovery so that I can flash superSU from there. – Andrew Brown Sep 18 '15 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.