This is just a personal automation script and doesn't feature much error handling, informative error messages or even code comments, excuse me for that. It's dead simple and self explanatory.
./extract.sh <miui_beryllium_rom_zip>
Most operations are verbose and you will get an idea what's happening at every step. It doesn't cleans the intermediate files/directories it makes on purpose.
This script is provided 'AS IS' without any guarantee whatsoever.