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-126.96.36.199.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-188.8.131.52-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?